use of sx.blah.discord.handle.obj.IChannel in project DisCal-Discord-Bot by NovaFox161.
the class DisCalCommand method moduleDisCalChannel.
/**
* Sets the channel for the guild that DisCal can respond in.
* @param args The command args
* @param event The event received.
*/
private void moduleDisCalChannel(String[] args, MessageReceivedEvent event, GuildSettings settings) {
if (args.length == 2) {
String channelName = args[1];
if (channelName.equalsIgnoreCase("all")) {
// Reset channel info.
settings.setDiscalChannel("all");
DatabaseManager.getManager().updateSettings(settings);
Message.sendMessage(MessageManager.getMessage("DisCal.Channel.All", settings), event);
} else {
if (ChannelUtils.channelExists(channelName, event)) {
IChannel channel = ChannelUtils.getChannelFromNameOrId(channelName, event);
if (channel != null) {
settings.setDiscalChannel(channel.getStringID());
DatabaseManager.getManager().updateSettings(settings);
Message.sendMessage(MessageManager.getMessage("DisCal.Channel.Set", "%channel%", channel.getName(), settings), event);
} else {
Message.sendMessage(MessageManager.getMessage("Discal.Channel.NotFound", settings), event);
}
} else {
Message.sendMessage(MessageManager.getMessage("Discal.Channel.NotFound", settings), event);
}
}
} else {
Message.sendMessage(MessageManager.getMessage("DisCal.Channel.Specify", settings), event);
}
}
use of sx.blah.discord.handle.obj.IChannel in project DisCal-Discord-Bot by NovaFox161.
the class WebGuild method fromGuild.
// Functions
public WebGuild fromGuild(IGuild g) {
id = g.getStringID();
name = g.getName();
iconUrl = g.getIconURL();
botNick = Main.client.getOurUser().getNicknameForGuild(g);
settings = DatabaseManager.getManager().getSettings(g.getLongID());
// Handle lists and stuffs
for (IRole r : g.getRoles()) {
roles.add(new WebRole().fromRole(r, settings));
}
WebChannel all = new WebChannel();
all.setId(0);
all.setName("All Channels");
all.setDiscalChannel(settings.getDiscalChannel().equalsIgnoreCase("all"));
channels.add(all);
for (IChannel c : g.getChannels()) {
channels.add(new WebChannel().fromChannel(c, settings));
}
announcements.addAll(DatabaseManager.getManager().getAnnouncements(g.getLongID()));
calendar = new WebCalendar().fromCalendar(DatabaseManager.getManager().getMainCalendar(Long.valueOf(id)), settings);
return this;
}
use of sx.blah.discord.handle.obj.IChannel in project DisCal-Discord-Bot by NovaFox161.
the class Logger method debug.
public void debug(@Nullable IUser author, String message, @Nullable String info, Class clazz, boolean post) {
String timeStamp = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss").format(Calendar.getInstance().getTime());
if (Main.client != null) {
if (post) {
IUser bot = Main.getSelfUser();
EmbedBuilder em = new EmbedBuilder();
assert bot != null;
em.withAuthorIcon(bot.getAvatarURL());
if (author != null) {
em.withAuthorName(author.getName());
em.withThumbnail(author.getAvatarURL());
}
em.withColor(239, 15, 0);
em.withFooterText(clazz.getName());
em.appendField("Time", timeStamp, true);
if (info != null) {
em.appendField("Additional Info", info, true);
}
// Get DisCal guild and channel..
IGuild guild = Main.client.getGuildByID(266063520112574464L);
IChannel channel = guild.getChannelByID(302249332244217856L);
Message.sendMessage(em.build(), "```" + message + "```", channel);
}
}
// ALWAYS LOG TO FILE!
try {
FileWriter file = new FileWriter(debugFile, true);
file.write("DEBUG --- " + timeStamp + " ---" + MessageUtils.lineBreak);
if (author != null) {
file.write("user: " + author.getName() + "#" + author.getDiscriminator() + MessageUtils.lineBreak);
}
if (message != null) {
file.write("message: " + message + MessageUtils.lineBreak);
}
if (info != null) {
file.write("info: " + info + MessageUtils.lineBreak);
}
file.close();
} catch (IOException io) {
io.printStackTrace();
}
}
use of sx.blah.discord.handle.obj.IChannel 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();
}
use of sx.blah.discord.handle.obj.IChannel in project DiscordSailv2 by Vaerys-Dawn.
the class Main method consoleInput.
public static void consoleInput() {
Scanner scanner = new Scanner(System.in);
logger.info("Console input initiated.");
while (scanner.hasNextLine()) {
String message = scanner.nextLine();
if (message.equalsIgnoreCase("!Shutdown")) {
System.exit(Constants.EXITCODE_STOP);
return;
}
if (Globals.consoleMessageCID != -1) {
IChannel channel = Globals.getClient().getChannelByID(Globals.consoleMessageCID);
message = message.replace("#Dawn#", Globals.getClient().getUserByID(153159020528533505L).getName());
message = message.replace("teh", "the");
message = message.replace("Teh", "The");
// System.out.println(message);
if (!message.equals("")) {
RequestHandler.sendMessage(message, channel);
}
}
}
}
Aggregations