use of sx.blah.discord.api.events.EventSubscriber in project KaellyBot by Kaysoro.
the class GuildLeaveListener method onReady.
@EventSubscriber
public void onReady(GuildLeaveEvent event) {
try {
Guild guild = Guild.getGuild(event.getGuild(), false);
if (guild != null) {
guild.removeToDatabase();
LOG.info("La guilde " + event.getGuild().getStringID() + " - " + event.getGuild().getName() + " a supprimé " + Constants.name);
for (RSSFinder finder : RSSFinder.getRSSFinders().values()) {
IChannel chan = event.getGuild().getChannelByID(Long.parseLong(finder.getChan()));
if (chan != null && chan.isDeleted()) {
finder.removeToDatabase();
LOG.info("RSS Chan \"" + chan.getName() + "\"");
}
}
for (TwitterFinder finder : TwitterFinder.getTwitterChannels().values()) {
IChannel chan = event.getGuild().getChannelByID(finder.getChannelId());
if (chan != null && chan.isDeleted()) {
finder.removeToDatabase();
LOG.info("Twitter Chan \"" + chan.getName() + "\"");
}
}
for (AlmanaxCalendar finder : AlmanaxCalendar.getAlmanaxCalendars().values()) {
IChannel chan = event.getGuild().getChannelByID(Long.parseLong(finder.getChan()));
if (chan != null && chan.isDeleted()) {
finder.removeToDatabase();
LOG.info("Almanax Chan \"" + chan.getName() + "\"");
}
}
}
Message.sendText(ClientConfig.DISCORD().getChannelByID(Constants.chanReportID), "[LOSE] **" + event.getGuild().getName() + "**, -" + event.getGuild().getUsers().size() + " utilisateurs");
} catch (Exception e) {
Reporter.report(e, event.getGuild());
LOG.error("onReady", e);
}
}
use of sx.blah.discord.api.events.EventSubscriber 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.api.events.EventSubscriber in project DisCal-Discord-Bot by NovaFox161.
the class CommandListener method onMessageEvent.
/**
* Checks for command validity and calls the command executor if valid.
* @param event The event received to check for a command.
*/
@EventSubscriber
public void onMessageEvent(MessageReceivedEvent event) {
try {
if (event.getMessage() != null && event.getGuild() != null && event.getChannel() != null && !event.getChannel().isPrivate() && event.getMessage().getContent() != null && event.getMessage().getContent().length() > 0) {
// Message is a valid guild message (not DM). Check if in correct channel.
GuildSettings settings = DatabaseManager.getManager().getSettings(event.getGuild().getLongID());
if (event.getMessage().getContent().startsWith(settings.getPrefix())) {
if (PermissionChecker.isCorrectChannel(event)) {
// Prefixed with ! which should mean it is a command, convert and confirm.
String[] argsOr = event.getMessage().getContent().split("\\s+");
if (argsOr.length > 1) {
ArrayList<String> argsOr2 = new ArrayList<>(Arrays.asList(argsOr).subList(1, argsOr.length));
String[] args = argsOr2.toArray(new String[argsOr2.size()]);
String command = argsOr[0].replace(settings.getPrefix(), "");
cmd.issueCommand(command, args, event, settings);
} else if (argsOr.length == 1) {
// Only command... no args.
cmd.issueCommand(argsOr[0].replace(settings.getPrefix(), ""), new String[0], event, settings);
}
}
} else if (!event.getMessage().mentionsEveryone() && !event.getMessage().mentionsHere() && (event.getMessage().toString().startsWith("<@" + Main.getSelfUser().getStringID() + ">") || event.getMessage().toString().startsWith("<@!" + Main.getSelfUser().getStringID() + ">"))) {
if (PermissionChecker.isCorrectChannel(event)) {
String[] argsOr = event.getMessage().getContent().split("\\s+");
if (argsOr.length > 2) {
ArrayList<String> argsOr2 = new ArrayList<>(Arrays.asList(argsOr).subList(2, argsOr.length));
String[] args = argsOr2.toArray(new String[argsOr2.size()]);
String command = argsOr[1];
cmd.issueCommand(command, args, event, settings);
} else if (argsOr.length == 2) {
// No args...
cmd.issueCommand(argsOr[1], new String[0], event, settings);
} else if (argsOr.length == 1) {
// Only disCal mentioned...
cmd.issueCommand("DisCal", new String[0], event, settings);
}
}
}
}
} catch (Exception e) {
Logger.getLogger().exception(event.getAuthor(), "Command error; event message: " + event.getMessage().getContent(), e, this.getClass(), true);
}
}
use of sx.blah.discord.api.events.EventSubscriber in project de-DiscordBot by DACH-Discord.
the class RedditLinker method onMessageReceived.
@EventSubscriber
public void onMessageReceived(final MessageReceivedEvent event) {
final IMessage message = event.getMessage();
final String messageContent = message.getContent();
Pattern pattern = Pattern.compile("^/?r/(\\w+)$");
Matcher matcher = pattern.matcher(messageContent);
if (matcher.matches()) {
Util.sendMessage(message.getChannel(), "https://www.reddit.com/r/" + matcher.group(1));
}
}
use of sx.blah.discord.api.events.EventSubscriber in project DiscordSailv2 by Vaerys-Dawn.
the class AnnotationListener method onUserJoinEvent.
@EventSubscriber
public void onUserJoinEvent(UserJoinEvent event) {
GuildObject content = Globals.getGuildContent(event.getGuild().getLongID());
UserObject user = new UserObject(event.getUser().getLongID(), content);
if (content.config.welcomeMessages && !user.get().isBot()) {
JoinHandler.sendWelcomeMessage(content, event, user);
}
if (content.config.checkNewUsers) {
JoinHandler.checkNewUsers(content, event, user);
}
if (content.config.moduleJoinMessages && content.config.sendJoinMessages) {
JoinHandler.customJoinMessages(content, event.getUser());
}
JoinHandler.autoReMute(event, content, user);
if (!content.config.moduleLogging)
return;
LoggingHandler.doJoinLeaveLog(event, true);
}
Aggregations