Search in sources :

Example 1 with IGuild

use of sx.blah.discord.handle.obj.IGuild in project KaellyBot by Kaysoro.

the class AnnounceCommand method request.

@Override
public boolean request(IMessage message) {
    if (super.request(message)) {
        Matcher m = getMatcher(message);
        m.find();
        Language lg = Translator.getLanguageFrom(message.getChannel());
        String text = m.group(2).trim();
        if (m.group(1) != null) {
            for (IGuild guild : ClientConfig.DISCORD().getGuilds()) try {
                if (guild.getDefaultChannel().getModifiedPermissions(ClientConfig.DISCORD().getOurUser()).contains(Permissions.SEND_MESSAGES))
                    Message.sendText(guild.getDefaultChannel(), text);
                else
                    Message.sendText(guild.getOwner().getOrCreatePMChannel(), text);
            } catch (DiscordException e) {
                LOG.warn("onReady", "Impossible de contacter l'administrateur de la guilde [" + guild.getName() + "].");
            } catch (Exception e2) {
                LOG.warn("onReady", e2);
            }
            Message.sendText(message.getChannel(), Translator.getLabel(lg, "announce.request.1") + " " + ClientConfig.DISCORD().getGuilds().size() + " " + Translator.getLabel(lg, "announce.request.2") + (ClientConfig.DISCORD().getGuilds().size() > 1 ? "s" : "") + ".");
        } else
            Message.sendText(message.getChannel(), text);
        return true;
    }
    return false;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) DiscordException(sx.blah.discord.util.DiscordException) IGuild(sx.blah.discord.handle.obj.IGuild) DiscordException(sx.blah.discord.util.DiscordException)

Example 2 with IGuild

use of sx.blah.discord.handle.obj.IGuild in project KaellyBot by Kaysoro.

the class Guild method getGuild.

public static synchronized Guild getGuild(IGuild discordGuild, boolean forceCache) {
    Guild guild = getGuilds().get(discordGuild.getStringID());
    if (guild == null && forceCache) {
        guild = new Guild(discordGuild.getStringID(), discordGuild.getName(), Constants.defaultLanguage);
        guild.addToDatabase();
    }
    return guild;
}
Also used : IGuild(sx.blah.discord.handle.obj.IGuild)

Example 3 with IGuild

use of sx.blah.discord.handle.obj.IGuild in project KaellyBot by Kaysoro.

the class ReadyListener method onReady.

@EventSubscriber
public void onReady(ReadyEvent event) {
    LOG.info(Constants.name + "Bot connecté !");
    LOG.info("Ajout des différents listeners");
    ClientConfig.DISCORD().getDispatcher().registerListener(new GuildCreateListener());
    ClientConfig.DISCORD().getDispatcher().registerListener(new GuildLeaveListener());
    ClientConfig.DISCORD().getDispatcher().registerListener(new GuildUpdateListener());
    ClientConfig.DISCORD().getDispatcher().registerListener(new ChannelDeleteListener());
    ClientConfig.DISCORD().getDispatcher().registerListener(new UserVoiceChannelMoveListener());
    ClientConfig.DISCORD().getDispatcher().registerListener(new UserVoiceChannelLeaveListener());
    LOG.info("Check des guildes");
    for (IGuild guild : ClientConfig.DISCORD().getGuilds()) if (Guild.getGuilds().containsKey(guild.getStringID()) && !guild.getName().equals(Guild.getGuild(guild).getName()))
        Guild.getGuild(guild).setName(guild.getName());
    else
        ClientConfig.DISCORD().getDispatcher().dispatch(new GuildCreateEvent(guild));
    // Check des guildes éventuellement supprimé durant l'absence
    List<String> ids = new ArrayList<>(Guild.getGuilds().keySet());
    for (String guildID : ids) if (ClientConfig.DISCORD().getGuildByID(Long.parseLong(guildID)) == null) {
        LOG.info(Guild.getGuilds().get(guildID).getName() + " a supprimé " + Constants.name + " en son absence.");
        Guild.getGuilds().get(guildID).removeToDatabase();
    }
    // Joue à...
    ClientConfig.DISCORD().changePresence(StatusType.ONLINE, ActivityType.WATCHING, Constants.discordInvite);
    LOG.info("Ecoute des flux RSS du site Dofus...");
    RSSFinder.start();
    LOG.info("Récupération des positions de portails...");
    PortalFinder.start();
    LOG.info("Lancement du calendrier Almanax...");
    AlmanaxCalendar.start();
    LOG.info("Connexion à l'API Twitter...");
    TwitterFinder.start();
    LOG.info("Ecoute des messages...");
    ClientConfig.DISCORD().getDispatcher().registerListener(new MessageListener());
}
Also used : GuildCreateEvent(sx.blah.discord.handle.impl.events.guild.GuildCreateEvent) ArrayList(java.util.ArrayList) IGuild(sx.blah.discord.handle.obj.IGuild) EventSubscriber(sx.blah.discord.api.events.EventSubscriber)

Example 4 with IGuild

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

the class DevCommand method moduleListGuilds.

private void moduleListGuilds(MessageReceivedEvent event) {
    Message.sendMessage("Sending a list of all Guilds! This may take awhile...", event);
    StringBuilder msg = new StringBuilder();
    for (IGuild g : Main.client.getGuilds()) {
        msg.append(MessageUtils.lineBreak).append(g.getName()).append(" | ").append(g.getLongID()).append(" | Members: ").append(g.getTotalMemberCount()).append(" | Bots: ").append(botPercent(g)).append("%");
        if (msg.length() >= 1500) {
            Message.sendMessage(msg.toString(), event);
            msg = new StringBuilder();
        }
    }
    Message.sendMessage(msg.toString(), event);
    Message.sendMessage("All Guilds listed!", event);
}
Also used : IGuild(sx.blah.discord.handle.obj.IGuild)

Example 5 with IGuild

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

the class DevCommand method moduleEval.

@SuppressWarnings("all")
private void moduleEval(MessageReceivedEvent event) {
    IGuild guild = event.getGuild();
    IUser user = event.getAuthor();
    IMessage message = event.getMessage();
    IDiscordClient client = event.getClient();
    IChannel channel = event.getChannel();
    String input = message.getContent().substring(message.getContent().indexOf("eval") + 5).replaceAll("`", "");
    Object o = null;
    factory.put("guild", guild);
    factory.put("channel", channel);
    factory.put("user", user);
    factory.put("message", message);
    factory.put("command", this);
    factory.put("client", client);
    factory.put("builder", new EmbedBuilder());
    factory.put("cUser", client.getOurUser());
    try {
        o = factory.eval(input);
    } catch (Exception ex) {
        EmbedBuilder em = new EmbedBuilder();
        em.withAuthorIcon(guild.getIconURL());
        em.withAuthorName("Error");
        em.withDesc(ex.getMessage());
        em.withFooterText("Eval failed");
        em.withColor(56, 138, 237);
        Message.sendMessage(em.build(), channel);
        return;
    }
    EmbedBuilder em = new EmbedBuilder();
    em.withAuthorIcon(guild.getIconURL());
    em.withAuthorName("Success!");
    em.withColor(56, 138, 237);
    em.withTitle("Evaluation output.");
    em.withDesc(o == null ? "No output, object is null" : o.toString());
    em.appendField("Input", "```java\n" + input + "\n```", false);
    em.withFooterText("Eval successful!");
    Message.sendMessage(em.build(), channel);
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IChannel(sx.blah.discord.handle.obj.IChannel) IMessage(sx.blah.discord.handle.obj.IMessage) IUser(sx.blah.discord.handle.obj.IUser) IGuild(sx.blah.discord.handle.obj.IGuild) IDiscordClient(sx.blah.discord.api.IDiscordClient) DiscordException(sx.blah.discord.util.DiscordException)

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