Search in sources :

Example 11 with EventSubscriber

use of sx.blah.discord.api.events.EventSubscriber in project BoltBot by DiscordBolt.

the class VoiceManager method reactionEvent.

/* Listeners */
@EventSubscriber
public void reactionEvent(ReactionAddEvent e) {
    if (e.getUser().equals(MusicModule.getClient().getOurUser()))
        return;
    DJ dj = getDJ(e.getGuild());
    IMessage message = e.getMessage();
    AudioTrack track = null;
    if (message.equals(dj.getNowPlayingMessage()))
        track = dj.getPlaying();
    else if (dj.getTrackMessages().containsKey(message))
        track = dj.getTrackMessages().get(message);
    if (track == null)
        return;
    switch(e.getReaction().getUnicodeEmoji().getAliases().get(0)) {
        case "black_right_pointing_double_triangle_with_vertical_bar":
            if (track.getIdentifier().equals(dj.getPlaying().getIdentifier())) {
                try {
                    skip(e.getGuild(), e.getUser(), false, 1);
                    ChannelUtil.sendMessage(e.getChannel(), e.getUser().getDisplayName(e.getGuild()) + " has voted to skip this track.");
                } catch (CommandException ex) {
                    ChannelUtil.sendMessage(e.getChannel(), ex.getMessage());
                }
            } else {
                ChannelUtil.sendMessage(e.getChannel(), e.getUser().getName() + ", You can only skip currently playing songs");
                return;
            }
            break;
        case "star":
            try {
                getDJ(e.getGuild()).starSong(track, e.getUser());
                ChannelUtil.sendMessage(e.getChannel(), e.getUser().getDisplayName(e.getGuild()) + ", successfully added the song to your selected playlist.");
            } catch (CommandException ex) {
                ChannelUtil.sendMessage(e.getChannel(), ex.getMessage());
            }
            break;
    }
}
Also used : IMessage(sx.blah.discord.handle.obj.IMessage) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) EventSubscriber(sx.blah.discord.api.events.EventSubscriber)

Example 12 with EventSubscriber

use of sx.blah.discord.api.events.EventSubscriber in project KaellyBot by Kaysoro.

the class GuildCreateListener method onReady.

@EventSubscriber
public void onReady(GuildCreateEvent event) {
    try {
        if (!Guild.getGuilds().containsKey(event.getGuild().getStringID())) {
            Guild guild = new Guild(event.getGuild().getStringID(), event.getGuild().getName(), Translator.detectLanguage(event.getGuild().getDefaultChannel()));
            guild.addToDatabase();
            Language lg = guild.getLanguage();
            LOG.info("La guilde " + guild.getId() + " - " + guild.getName() + " a ajouté " + Constants.name);
            String customMessage = Translator.getLabel(lg, "welcome.message");
            customMessage = customMessage.replaceAll("\\{name\\}", Constants.name).replaceAll("\\{game\\}", Constants.game).replaceAll("\\{prefix\\}", Constants.prefixCommand).replaceAll("\\{help\\}", HelpCommand.NAME).replaceAll("\\{server\\}", new ServerCommand().getName()).replaceAll("\\{lang\\}", new LanguageCommand().getName()).replaceAll("\\{twitter\\}", new TwitterCommand().getName()).replaceAll("\\{almanax\\}", new AlmanaxCommand().getName()).replaceAll("\\{rss\\}", new RSSCommand().getName()).replaceAll("\\{owner\\}", event.getGuild().getOwner().mention()).replaceAll("\\{guild\\}", event.getGuild().getName());
            if (event.getGuild().getDefaultChannel() != null && event.getGuild().getDefaultChannel().getModifiedPermissions(ClientConfig.DISCORD().getOurUser()).contains(Permissions.SEND_MESSAGES))
                Message.sendText(event.getGuild().getDefaultChannel(), customMessage);
            else
                try {
                    Message.sendText(event.getGuild().getOwner().getOrCreatePMChannel(), customMessage);
                } catch (DiscordException e) {
                    LOG.warn("onReady", "Impossible de contacter l'administrateur de la guilde [" + guild.getName() + "].");
                }
            Message.sendText(ClientConfig.DISCORD().getChannelByID(Constants.chanReportID), "[NEW] **" + guild.getName() + "** (" + guild.getLanguage().getAbrev() + "), +" + event.getGuild().getUsers().size() + " utilisateurs");
        }
    } catch (Exception e) {
        Reporter.report(e, event.getGuild());
        LOG.error("onReady", e);
    }
}
Also used : Language(enums.Language) DiscordException(sx.blah.discord.util.DiscordException) LanguageCommand(commands.config.LanguageCommand) Guild(data.Guild) DiscordException(sx.blah.discord.util.DiscordException) ServerCommand(commands.config.ServerCommand) TwitterCommand(commands.config.TwitterCommand) AlmanaxCommand(commands.classic.AlmanaxCommand) RSSCommand(commands.config.RSSCommand) EventSubscriber(sx.blah.discord.api.events.EventSubscriber)

Example 13 with EventSubscriber

use of sx.blah.discord.api.events.EventSubscriber in project de-DiscordBot by DACH-Discord.

the class DiscordBot method onMessageEdited.

/**
 * Wird bei jeder geänderten Nachricht aufgerufen, bearbeitete Nachrichten die jünger als 20 Sekunden sind
 * werden auch als Befehl interpretiert
 *
 * @param event Das Event der geänderten Nachricht
 */
@EventSubscriber
public void onMessageEdited(final MessageUpdateEvent event) {
    final IMessage message = event.getNewMessage();
    if (message.getEditedTimestamp().isPresent()) {
        final LocalDateTime messageTimestamp = message.getTimestamp();
        final LocalDateTime editTimestamp = message.getEditedTimestamp().get();
        final long seconds = messageTimestamp.until(editTimestamp, ChronoUnit.SECONDS);
        if (seconds < 20) {
            handleMessage(message);
        }
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) IMessage(sx.blah.discord.handle.obj.IMessage) EventSubscriber(sx.blah.discord.api.events.EventSubscriber)

Example 14 with EventSubscriber

use of sx.blah.discord.api.events.EventSubscriber in project de-DiscordBot by DACH-Discord.

the class UserLog method onStartup.

@EventSubscriber
public void onStartup(ReadyEvent event) {
    // UserLog Kanal auslesen
    final String userLogFileContent = Util.readFile(USERLOG_PATH);
    if (userLogFileContent == null) {
        throw new RuntimeException("[ERROR] Could not read userLog File!");
    }
    jsonUserLog = new JSONObject(userLogFileContent);
    this.isEnabled = jsonUserLog.getBoolean("on");
    final long channelID = jsonUserLog.getLong("channel");
    this.userLogChannel = bot.client.getChannelByID(channelID);
    if (this.userLogChannel == null) {
        System.err.println("[ERR] Invalid UserLog Channel!");
    }
}
Also used : JSONObject(org.json.JSONObject) EventSubscriber(sx.blah.discord.api.events.EventSubscriber)

Example 15 with EventSubscriber

use of sx.blah.discord.api.events.EventSubscriber in project solinia3-core by mixxit.

the class DiscordListener method onMessageReceivedEvent.

@EventSubscriber
public void onMessageReceivedEvent(MessageReceivedEvent event) {
    // This method is NOT called because it doesn't have the @EventSubscriber annotation
    System.out.println(event.getAuthor().getName() + "@" + event.getChannel().getName() + ":" + event.getMessage().getContent());
    if (event.getChannel().getStringID().equals(StateManager.getInstance().getChannelManager().getDefaultDiscordChannel())) {
        // Handle command messaging here
        if (event.getMessage().getContent().startsWith("?")) {
            StateManager.getInstance().getChannelManager().handleDiscordCommand(DiscordChannel.DEFAULT, event);
        } else {
            StateManager.getInstance().getChannelManager().sendToGlobalChannel(event.getAuthor().getName() + "@" + event.getChannel().getName(), event.getMessage().getContent());
        }
    }
    IRole role = null;
    for (IRole currentRole : event.getGuild().getRoles()) {
        if (!currentRole.getName().equals("Admin"))
            continue;
        role = currentRole;
    }
    if (event.getAuthor().getRolesForGuild(event.getGuild()).contains(role)) {
        if (event.getMessage().getContent().startsWith("?")) {
            String[] words = event.getMessage().getContent().split(" ");
            String command = "";
            for (int i = 0; i < words.length; i++) {
                if (i == 0) {
                    command += words[i].replace("?", "") + " ";
                } else {
                    command += words[i] + " ";
                }
            }
            if (event.getChannel().getStringID().equals(StateManager.getInstance().getChannelManager().getDefaultDiscordChannel())) {
                Bukkit.getServer().dispatchCommand(StateManager.getInstance().getDiscordDefaultChannelCommandSender(), command.trim());
            } else {
                Bukkit.getServer().dispatchCommand(StateManager.getInstance().getDiscordAdminChannelCommandSender(), command.trim());
            }
        } else {
            StateManager.getInstance().getChannelManager().sendToOps("[OPONLY]" + event.getAuthor().getName() + "@" + event.getChannel().getName(), event.getMessage().getContent());
        }
    }
}
Also used : IRole(sx.blah.discord.handle.obj.IRole) EventSubscriber(sx.blah.discord.api.events.EventSubscriber)

Aggregations

EventSubscriber (sx.blah.discord.api.events.EventSubscriber)18 IMessage (sx.blah.discord.handle.obj.IMessage)6 CommandObject (com.github.vaerys.commands.CommandObject)5 IGuild (sx.blah.discord.handle.obj.IGuild)3 GuildObject (com.github.vaerys.masterobjects.GuildObject)2 UserObject (com.github.vaerys.masterobjects.UserObject)2 ArrayList (java.util.ArrayList)2 GuildSettings (com.cloudcraftgaming.discal.api.object.GuildSettings)1 Restart (com.github.vaerys.commands.creator.Restart)1 LogObject (com.github.vaerys.objects.LogObject)1 Command (com.github.vaerys.templates.Command)1 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)1 AlmanaxCommand (commands.classic.AlmanaxCommand)1 LanguageCommand (commands.config.LanguageCommand)1 RSSCommand (commands.config.RSSCommand)1 ServerCommand (commands.config.ServerCommand)1 TwitterCommand (commands.config.TwitterCommand)1 Guild (data.Guild)1 Language (enums.Language)1 AlmanaxCalendar (finders.AlmanaxCalendar)1