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;
}
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;
}
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());
}
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);
}
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);
}
Aggregations