use of com.cloudcraftgaming.discal.api.object.web.WebRole in project DisCal-Discord-Bot by NovaFox161.
the class DashboardHandler method handleSettingsUpdate.
public static String handleSettingsUpdate(Request request, Response response) {
try {
if (request.queryParams().contains("bot-nick")) {
// Update bot nickname...
Map m = DiscordAccountHandler.getHandler().getAccount(request.session().id());
WebGuild g = (WebGuild) m.get("selected");
if (g.isManageServer()) {
g.setBotNick(request.queryParams("bot-nick"));
IGuild guild = Main.client.getGuildByID(Long.valueOf(g.getId()));
guild.setUserNickname(Main.client.getOurUser(), g.getBotNick());
}
} else if (request.queryParams().contains("prefix")) {
// Update prefix...
Map m = DiscordAccountHandler.getHandler().getAccount(request.session().id());
WebGuild g = (WebGuild) m.get("selected");
if (g.isManageServer()) {
g.setSettings(DatabaseManager.getManager().getSettings(Long.valueOf(g.getId())));
g.getSettings().setPrefix(request.queryParams("prefix"));
DatabaseManager.getManager().updateSettings(g.getSettings());
}
} else if (request.queryParams().contains("lang")) {
// Update lang...
Map m = DiscordAccountHandler.getHandler().getAccount(request.session().id());
WebGuild g = (WebGuild) m.get("selected");
if (g.isManageServer()) {
g.setSettings(DatabaseManager.getManager().getSettings(Long.valueOf(g.getId())));
g.getSettings().setLang(request.queryParams("lang"));
DatabaseManager.getManager().updateSettings(g.getSettings());
}
} else if (request.queryParams().contains("con-role")) {
// Update control role...
Map m = DiscordAccountHandler.getHandler().getAccount(request.session().id());
WebGuild g = (WebGuild) m.get("selected");
if (g.isManageServer()) {
g.setSettings(DatabaseManager.getManager().getSettings(Long.valueOf(g.getId())));
IGuild guild = Main.client.getGuildByID(Long.valueOf(g.getId()));
IRole role = guild.getRoleByID(Long.valueOf(request.queryParams("con-role")));
if (role.isEveryoneRole()) {
g.getSettings().setControlRole("everyone");
} else {
g.getSettings().setControlRole(role.getStringID());
}
DatabaseManager.getManager().updateSettings(g.getSettings());
// Update role list to display properly...
g.getRoles().clear();
for (IRole r : guild.getRoles()) {
g.getRoles().add(new WebRole().fromRole(r, g.getSettings()));
}
}
} else if (request.queryParams().contains("discal-channel")) {
// Update control role...
Map m = DiscordAccountHandler.getHandler().getAccount(request.session().id());
WebGuild g = (WebGuild) m.get("selected");
if (g.isDiscalRole()) {
g.setSettings(DatabaseManager.getManager().getSettings(Long.valueOf(g.getId())));
IGuild guild = Main.client.getGuildByID(Long.valueOf(g.getId()));
if (request.queryParams("discal-channel").equalsIgnoreCase("0")) {
// All channels
g.getSettings().setDiscalChannel("all");
} else {
g.getSettings().setDiscalChannel(request.queryParams("discal-channel"));
}
DatabaseManager.getManager().updateSettings(g.getSettings());
// Update channel list to display properly...
g.getChannels().clear();
WebChannel all = new WebChannel();
all.setId(0);
all.setName("All Channels");
all.setDiscalChannel(g.getSettings().getDiscalChannel().equalsIgnoreCase("all"));
g.getChannels().add(all);
for (IChannel c : guild.getChannels()) {
g.getChannels().add(new WebChannel().fromChannel(c, g.getSettings()));
}
}
} else if (request.queryParams().contains("branding")) {
// Update bot nickname...
Map m = DiscordAccountHandler.getHandler().getAccount(request.session().id());
WebGuild g = (WebGuild) m.get("selected");
if (g.isManageServer()) {
g.setSettings(DatabaseManager.getManager().getSettings(Long.valueOf(g.getId())));
if (g.getSettings().isPatronGuild()) {
if (request.queryParams().contains("value")) {
g.getSettings().setBranded(true);
} else {
g.getSettings().setBranded(false);
}
DatabaseManager.getManager().updateSettings(g.getSettings());
}
}
} else if (request.queryParams().contains("simple-ann")) {
// Update simple announcements...
Map m = DiscordAccountHandler.getHandler().getAccount(request.session().id());
WebGuild g = (WebGuild) m.get("selected");
// Guess this one never checked for perms so...
g.setSettings(DatabaseManager.getManager().getSettings(Long.valueOf(g.getId())));
if (request.queryParams().contains("value")) {
g.getSettings().setSimpleAnnouncements(true);
} else {
g.getSettings().setSimpleAnnouncements(false);
}
DatabaseManager.getManager().updateSettings(g.getSettings());
response.redirect("/dashboard/guild/announcements", 301);
return response.body();
}
// Finally redirect back to the dashboard
response.redirect("/dashboard/guild", 301);
} catch (Exception e) {
Logger.getLogger().exception(null, "[WEB] Settings update failed!", e, DashboardHandler.class, true);
halt(500, "Internal Server Exception");
}
return response.body();
}
Aggregations