Search in sources :

Example 31 with IChannel

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);
    }
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel)

Example 32 with IChannel

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;
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) IRole(sx.blah.discord.handle.obj.IRole)

Example 33 with IChannel

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();
    }
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IChannel(sx.blah.discord.handle.obj.IChannel) FileWriter(java.io.FileWriter) IUser(sx.blah.discord.handle.obj.IUser) IGuild(sx.blah.discord.handle.obj.IGuild) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 34 with IChannel

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();
}
Also used : WebChannel(com.cloudcraftgaming.discal.api.object.web.WebChannel) IChannel(sx.blah.discord.handle.obj.IChannel) IRole(sx.blah.discord.handle.obj.IRole) WebRole(com.cloudcraftgaming.discal.api.object.web.WebRole) WebGuild(com.cloudcraftgaming.discal.api.object.web.WebGuild) IGuild(sx.blah.discord.handle.obj.IGuild) HashMap(java.util.HashMap) Map(java.util.Map) JSONException(org.json.JSONException)

Example 35 with IChannel

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);
            }
        }
    }
}
Also used : Scanner(java.util.Scanner) IChannel(sx.blah.discord.handle.obj.IChannel)

Aggregations

IChannel (sx.blah.discord.handle.obj.IChannel)44 IGuild (sx.blah.discord.handle.obj.IGuild)7 IRole (sx.blah.discord.handle.obj.IRole)7 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)7 SQLException (java.sql.SQLException)6 IUser (sx.blah.discord.handle.obj.IUser)6 ProfileObject (com.github.vaerys.objects.ProfileObject)5 SplitFirstObject (com.github.vaerys.objects.SplitFirstObject)5 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 ArrayList (java.util.ArrayList)4 CommandObject (com.github.vaerys.commands.CommandObject)3 ChannelSetting (com.github.vaerys.enums.ChannelSetting)3 StringHandler (com.github.vaerys.handlers.StringHandler)3 UserObject (com.github.vaerys.masterobjects.UserObject)3 CCommandObject (com.github.vaerys.objects.CCommandObject)3 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)3 IOException (java.io.IOException)3 DBGuild (me.shadorc.shadbot.data.db.DBGuild)3