Search in sources :

Example 11 with IGuild

use of sx.blah.discord.handle.obj.IGuild in project DisCal-Discord-Bot by NovaFox161.

the class Logger method exception.

public void exception(@Nullable IUser author, @Nullable String message, Exception e, Class clazz, boolean post) {
    String timeStamp = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(Calendar.getInstance().getTime());
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    e.printStackTrace(pw);
    // stack trace as a string
    String error = sw.toString();
    pw.close();
    try {
        sw.close();
    } catch (IOException e1) {
    // Can ignore silently...
    }
    if (Main.getSelfUser() != null) {
        IUser bot = Main.getSelfUser();
        if (post) {
            String shortError = error;
            if (error.length() > 1250) {
                shortError = error.substring(0, 1250);
            }
            EmbedBuilder em = new EmbedBuilder();
            if (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());
            // Send to discord!
            em.appendField("Time", timeStamp, true);
            if (e.getMessage() != null) {
                if (e.getMessage().length() > 1024) {
                    em.appendField("Exception", e.getMessage().substring(0, 1024), true);
                } else {
                    em.appendField("Exception", e.getMessage(), true);
                }
            }
            if (message != null) {
                em.appendField("Message", message, true);
            }
            // Get DisCal guild and channel..
            IGuild guild = Main.client.getGuildByID(266063520112574464L);
            IChannel channel = guild.getChannelByID(302249332244217856L);
            Message.sendMessage(em.build(), "```" + shortError + "```", channel);
        }
    }
    // ALWAYS LOG TO FILE!
    try {
        FileWriter exceptions = new FileWriter(exceptionsFile, true);
        exceptions.write("ERROR --- " + timeStamp + " ---" + MessageUtils.lineBreak);
        if (author != null) {
            exceptions.write("user: " + author.getName() + "#" + author.getDiscriminator() + MessageUtils.lineBreak);
        }
        if (message != null) {
            exceptions.write("message: " + message + MessageUtils.lineBreak);
        }
        exceptions.write(error + MessageUtils.lineBreak);
        exceptions.close();
    } catch (IOException io) {
        io.printStackTrace();
    }
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IChannel(sx.blah.discord.handle.obj.IChannel) StringWriter(java.io.StringWriter) FileWriter(java.io.FileWriter) IUser(sx.blah.discord.handle.obj.IUser) IOException(java.io.IOException) IGuild(sx.blah.discord.handle.obj.IGuild) SimpleDateFormat(java.text.SimpleDateFormat) PrintWriter(java.io.PrintWriter)

Example 12 with IGuild

use of sx.blah.discord.handle.obj.IGuild in project DiscordSailv2 by Vaerys-Dawn.

the class GuildCreateListener method onGuildCreateEvent.

@EventSubscriber
public void onGuildCreateEvent(GuildCreateEvent event) {
    IGuild guild = event.getGuild();
    long guildID = guild.getLongID();
    logger.debug("Starting Loading process for Guild with ID: " + guildID);
    if (new File(Utility.getDirectory(guildID)).exists()) {
        PatchHandler.guildPatches(guild);
    }
    FileHandler.createDirectory(Utility.getDirectory(guildID));
    FileHandler.createDirectory(Utility.getDirectory(guildID, true));
    FileHandler.createDirectory(Utility.getGuildImageDir(guildID));
    FileHandler.initFile(Utility.getFilePath(guildID, Constants.FILE_INFO));
    GuildObject guildObject = new GuildObject(guild);
    Globals.initGuild(guildObject);
    logger.info("Finished Loading Guild With ID: " + guildID);
}
Also used : GuildObject(com.github.vaerys.masterobjects.GuildObject) IGuild(sx.blah.discord.handle.obj.IGuild) File(java.io.File) EventSubscriber(sx.blah.discord.api.events.EventSubscriber)

Example 13 with IGuild

use of sx.blah.discord.handle.obj.IGuild in project DiscordSailv2 by Vaerys-Dawn.

the class GuildConfig method validateRoles.

public void validateRoles() {
    IGuild guild = Globals.client.getGuildByID(guildID);
    if (guild == null) {
        return;
    }
    ListIterator iterator = cosmeticRoleIDs.listIterator();
    while (iterator.hasNext()) {
        IRole role = guild.getRoleByID((Long) iterator.next());
        if (role == null) {
            iterator.remove();
        }
    }
    iterator = modifierRoleIDs.listIterator();
    while (iterator.hasNext()) {
        IRole role = guild.getRoleByID((Long) iterator.next());
        if (role == null) {
            iterator.remove();
        }
    }
    IRole inviteAllowedRole = guild.getRoleByID(inviteAllowedID);
    if (inviteAllowedRole == null) {
        inviteAllowedID = -1;
    }
    IRole mutedRole = guild.getRoleByID(mutedRoleID);
    if (mutedRole == null) {
        mutedRoleID = -1;
    }
    IRole roleToMention = guild.getRoleByID(roleToMentionID);
    if (roleToMention == null) {
        roleToMentionID = -1;
    }
    iterator = rewardRoles.listIterator();
    while (iterator.hasNext()) {
        RewardRoleObject reward = (RewardRoleObject) iterator.next();
        IRole role = guild.getRoleByID(reward.getRoleID());
        if (role == null) {
            iterator.remove();
        }
    }
}
Also used : RewardRoleObject(com.github.vaerys.objects.RewardRoleObject) IRole(sx.blah.discord.handle.obj.IRole) IGuild(sx.blah.discord.handle.obj.IGuild) ListIterator(java.util.ListIterator)

Example 14 with IGuild

use of sx.blah.discord.handle.obj.IGuild in project DiscordSailv2 by Vaerys-Dawn.

the class GetGuildList method execute.

@Override
public String execute(String args, CommandObject command) {
    ArrayList<String> guilds = new ArrayList<>();
    for (IGuild g : command.client.get().getGuilds()) {
        guilds.add(g.getName() + ": " + g.getLongID());
    }
    XEmbedBuilder builder = new XEmbedBuilder(command);
    Utility.listFormatterEmbed("List Of Guilds", builder, guilds, false);
    command.user.sendEmbededDm("", builder);
    return null;
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) ArrayList(java.util.ArrayList) IGuild(sx.blah.discord.handle.obj.IGuild)

Example 15 with IGuild

use of sx.blah.discord.handle.obj.IGuild in project Shadbot by Shadorc.

the class ShutdownCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
    if (!context.hasArg()) {
        MessageManager.addListener(context.getChannel(), this);
        BotUtils.sendMessage(String.format(Emoji.QUESTION + " Do you really want to shutdown %s ? Yes/No", context.getClient().getOurUser().mention()), context.getChannel());
        return;
    }
    List<String> splitArgs = StringUtils.split(context.getArg(), 2);
    if (splitArgs.size() != 2) {
        throw new MissingArgumentException();
    }
    Integer delay = CastUtils.asPositiveInt(splitArgs.get(0));
    if (delay == null) {
        throw new IllegalCmdArgumentException(String.format("`%s` is not a valid time.", splitArgs.get(0)));
    }
    String message = splitArgs.get(1);
    for (IGuild guild : context.getClient().getGuilds()) {
        GuildMusic guildMusic = GuildMusicManager.GUILD_MUSIC_MAP.get(guild.getLongID());
        if (guildMusic != null && guildMusic.getChannel() != null) {
            BotUtils.sendMessage(Emoji.INFO + " " + message, guildMusic.getChannel());
        }
    }
    Shadbot.getScheduler().schedule(() -> System.exit(0), delay, TimeUnit.SECONDS);
    LogUtils.warnf("Shadbot will restart in %d seconds. (Message: %s)", delay, message);
}
Also used : IllegalCmdArgumentException(me.shadorc.shadbot.exception.IllegalCmdArgumentException) MissingArgumentException(me.shadorc.shadbot.exception.MissingArgumentException) GuildMusic(me.shadorc.shadbot.music.GuildMusic) IGuild(sx.blah.discord.handle.obj.IGuild)

Aggregations

IGuild (sx.blah.discord.handle.obj.IGuild)31 IUser (sx.blah.discord.handle.obj.IUser)13 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)9 IChannel (sx.blah.discord.handle.obj.IChannel)7 ArrayList (java.util.ArrayList)5 IRole (sx.blah.discord.handle.obj.IRole)5 EventSubscriber (sx.blah.discord.api.events.EventSubscriber)4 IMessage (sx.blah.discord.handle.obj.IMessage)4 DiscordException (sx.blah.discord.util.DiscordException)4 WebGuild (com.cloudcraftgaming.discal.api.object.web.WebGuild)3 HashMap (java.util.HashMap)3 List (java.util.List)3 MissingPermissionsException (sx.blah.discord.util.MissingPermissionsException)3 EventColor (com.cloudcraftgaming.discal.api.enums.event.EventColor)2 EventData (com.cloudcraftgaming.discal.api.object.event.EventData)2 Calendar (com.google.api.services.calendar.Calendar)2 Language (enums.Language)2 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 SimpleDateFormat (java.text.SimpleDateFormat)2