Search in sources :

Example 11 with IMessage

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

the class EventCreator method init.

public PreEvent init(MessageReceivedEvent e, GuildSettings settings, String summary, boolean handleMessage) {
    if (!hasPreEvent(e.getGuild().getLongID())) {
        PreEvent event = new PreEvent(e.getGuild().getLongID());
        event.setSummary(summary);
        try {
            // TODO: Handle multiple calendars...
            String calId = DatabaseManager.getManager().getMainCalendar(e.getGuild().getLongID()).getCalendarAddress();
            if (!settings.useExternalCalendar()) {
                event.setTimeZone(CalendarAuth.getCalendarService().calendars().get(calId).execute().getTimeZone());
            } else {
                event.setTimeZone(CalendarAuth.getCalendarService(settings).calendars().get(calId).execute().getTimeZone());
            }
        } catch (Exception exc) {
        // Failed to get timezone, ignore safely.
        }
        if (handleMessage) {
            if (PermissionChecker.botHasMessageManagePerms(e)) {
                IMessage message = Message.sendMessage(EventMessageFormatter.getPreEventEmbed(event, settings), MessageManager.getMessage("Creator.Event.Create.Init", settings), e);
                event.setCreatorMessage(message);
                Message.deleteMessage(e);
            } else {
                Message.sendMessage(MessageManager.getMessage("Creator.Notif.MANAGE_MESSAGES", settings), e);
            }
        }
        events.add(event);
        return event;
    }
    return getPreEvent(e.getGuild().getLongID());
}
Also used : PreEvent(com.cloudcraftgaming.discal.api.object.event.PreEvent) IMessage(sx.blah.discord.handle.obj.IMessage) IOException(java.io.IOException)

Example 12 with IMessage

use of sx.blah.discord.handle.obj.IMessage 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));
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) IMessage(sx.blah.discord.handle.obj.IMessage) EventSubscriber(sx.blah.discord.api.events.EventSubscriber)

Example 13 with IMessage

use of sx.blah.discord.handle.obj.IMessage in project BoltBot by DiscordBolt.

the class NowPlayingCommand method nowPlayingCommand.

@BotCommand(command = "nowplaying", aliases = { "np", "current", "playing" }, module = MusicModule.MODULE, description = "View what is currently playing", usage = "NowPlaying", allowedChannels = "music")
public static void nowPlayingCommand(CommandContext cc) throws CommandException {
    AudioTrack at = MusicModule.getVoiceManager().getNowPlaying(cc.getGuild());
    if (at == null)
        throw new CommandStateException("Nothing is currently playing. Play something with !Play");
    IMessage nowPlayingMessage = cc.replyWith(MusicModule.createPlayingEmbed(cc.getGuild(), MusicModule.getVoiceManager().getNowPlaying(cc.getGuild())));
    ChannelUtil.addReaction(nowPlayingMessage, new Emoji[] { EmojiManager.getForAlias(":black_right_pointing_double_triangle_with_vertical_bar:"), EmojiManager.getForAlias(":star:") });
    MusicModule.getVoiceManager().putNowPlayingMessage(nowPlayingMessage, MusicModule.getVoiceManager().getNowPlaying(cc.getGuild()));
}
Also used : IMessage(sx.blah.discord.handle.obj.IMessage) CommandStateException(com.discordbolt.api.command.exceptions.CommandStateException) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) BotCommand(com.discordbolt.api.command.BotCommand)

Example 14 with IMessage

use of sx.blah.discord.handle.obj.IMessage in project Discord4J by Discord4J.

the class ParrotBot method handle.

/**
 * Called when the client receives a message.
 */
@Override
public void handle(MessageReceivedEvent event) {
    // Gets the message from the event object NOTE: This is not the content of the message, but the object itself
    IMessage message = event.getMessage();
    // Gets the channel in which this message was sent.
    IChannel channel = message.getChannel();
    try {
        // Builds (sends) and new message in the channel that the original message was sent with the content of the original message.
        new MessageBuilder(this.client).withChannel(channel).withContent(message.getContent()).build();
    } catch (RateLimitException e) {
        // RateLimitException thrown. The bot is sending messages too quickly!
        System.err.print("Sending messages too quickly!");
        e.printStackTrace();
    } catch (DiscordException e) {
        // DiscordException thrown. Many possibilities. Use getErrorMessage() to see what went wrong.
        // Print the error message sent by Discord
        System.err.print(e.getErrorMessage());
        e.printStackTrace();
    } catch (MissingPermissionsException e) {
        // MissingPermissionsException thrown. The bot doesn't have permission to send the message!
        System.err.print("Missing permissions for channel!");
        e.printStackTrace();
    }
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) MessageBuilder(sx.blah.discord.util.MessageBuilder) RateLimitException(sx.blah.discord.util.RateLimitException) IMessage(sx.blah.discord.handle.obj.IMessage) DiscordException(sx.blah.discord.util.DiscordException) MissingPermissionsException(sx.blah.discord.util.MissingPermissionsException)

Example 15 with IMessage

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

the class AnnotationListener method onReactionAddEvent.

@EventSubscriber
public void onReactionAddEvent(ReactionAddEvent event) {
    if (event.getUser().isBot()) {
        return;
    }
    ReactionEmoji x = Utility.getReaction("x");
    ReactionEmoji pin = Utility.getReaction(Constants.EMOJI_ADD_PIN);
    ReactionEmoji thumbsUp = Utility.getReaction(Constants.EMOJI_APPROVE);
    ReactionEmoji thumbsDown = Utility.getReaction(Constants.EMOJI_DISAPPROVE);
    ReactionEmoji heart = Utility.getReaction(Constants.EMOJI_LIKE_PIN);
    ReactionEmoji remove = Utility.getReaction(Constants.EMOJI_REMOVE_PIN);
    ReactionEmoji emoji = event.getReaction().getEmoji();
    if (emoji == null)
        return;
    IMessage message = event.getMessage();
    if (message == null)
        message = event.getChannel().getMessageByID(event.getMessageID());
    CommandObject object = new CommandObject(message);
    UserObject pinner = new UserObject(event.getUser(), object.guild);
    UserObject owner = new UserObject(event.getAuthor(), object.guild);
    // do only on server channels
    if (!event.getChannel().isPrivate() && emoji.isUnicode()) {
        // if is x and can bypass
        if (emoji.equals(remove))
            ArtHandler.unPin(object);
        if (emoji.equals(x) && GuildHandler.testForPerms(object, Permissions.MANAGE_MESSAGES) && object.client.bot.longID == object.user.longID)
            RequestHandler.deleteMessage(object.message);
        // if is pushpin
        if (emoji.equals(pin))
            ArtHandler.pinMessage(object, pinner, owner);
        // if is thumbsup or thumbs down and is creator.
        if (emoji.equals(thumbsUp) || emoji.equals(thumbsDown))
            QueueHandler.reactionAdded(object, event.getReaction());
        // if is hear and is pinned then give xp
        if (emoji.equals(heart))
            ArtHandler.pinLiked(object, pinner, owner);
    // do only within Direct messages
    } else if (event.getChannel().isPrivate() && emoji.isUnicode()) {
        // if anyone uses x
        if (emoji.equals(x) && object.client.bot.longID == object.user.longID) {
            RequestHandler.deleteMessage(message);
        }
    }
}
Also used : CommandObject(com.github.vaerys.commands.CommandObject) IMessage(sx.blah.discord.handle.obj.IMessage) UserObject(com.github.vaerys.masterobjects.UserObject) ReactionEmoji(sx.blah.discord.handle.impl.obj.ReactionEmoji) EventSubscriber(sx.blah.discord.api.events.EventSubscriber)

Aggregations

IMessage (sx.blah.discord.handle.obj.IMessage)46 IUser (sx.blah.discord.handle.obj.IUser)10 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)9 EventSubscriber (sx.blah.discord.api.events.EventSubscriber)6 IChannel (sx.blah.discord.handle.obj.IChannel)6 ProfileObject (com.github.vaerys.objects.ProfileObject)5 UserObject (com.github.vaerys.masterobjects.UserObject)4 ArrayList (java.util.ArrayList)4 DiscordException (sx.blah.discord.util.DiscordException)4 Announcement (com.cloudcraftgaming.discal.api.object.announcement.Announcement)3 PreEvent (com.cloudcraftgaming.discal.api.object.event.PreEvent)3 CommandObject (com.github.vaerys.commands.CommandObject)3 SplitFirstObject (com.github.vaerys.objects.SplitFirstObject)3 GitHubImage (io.github.spugn.Sargo.Utilities.GitHubImage)3 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 RateLimitException (sx.blah.discord.util.RateLimitException)3 PreCalendar (com.cloudcraftgaming.discal.api.object.calendar.PreCalendar)2 TrackLikes (com.github.vaerys.objects.TrackLikes)2