Search in sources :

Example 41 with IMessage

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

the class TimerHandler method sendReminder.

// Reminder new setup.
public static void sendReminder(ReminderObject object) {
    ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
    long initialDelay = object.getExecuteTime() - now.toEpochSecond();
    // System.out.println(initialDelay + "");
    if (initialDelay < 0) {
        initialDelay = 5;
    }
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {

        @Override
        public void run() {
            IMessage message = RequestHandler.sendMessage(object.getMessage(), Globals.getClient().getChannelByID(object.getChannelID())).get();
            if (message == null) {
                logger.error("REMINDER FAILED FOR USER WITH ID \"" + object.getUserID() + "\" TO SEND. WILL ATTEMPT TO SEND AGAIN IN 5 MINS.");
                object.setSent(false);
            } else {
                Globals.getGlobalData().removeReminder(object);
            }
        }
    }, initialDelay * 1000);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) IMessage(sx.blah.discord.handle.obj.IMessage)

Example 42 with IMessage

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

the class MessageHistory method delete.

/**
 * Deletes the message with the given ID. The deleted message is NOT removed from the collection.
 *
 * @param id The ID of the message to delete.
 * @return The deleted message (or null if no message was found).
 */
public IMessage delete(long id) {
    IMessage message = get(id);
    if (message == null)
        return null;
    message.delete();
    return message;
}
Also used : IMessage(sx.blah.discord.handle.obj.IMessage)

Example 43 with IMessage

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

the class MessageHistory method delete.

/**
 * Deletes the message at the specified index. The deleted message is NOT removed from the collection.
 *
 * @param index The index of the message to delete.
 * @return The deleted message.
 */
public IMessage delete(int index) {
    IMessage message = get(index);
    message.delete();
    return message;
}
Also used : IMessage(sx.blah.discord.handle.obj.IMessage)

Example 44 with IMessage

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

the class MessageListener method onMessageReceivedEvent.

private void onMessageReceivedEvent(MessageReceivedEvent event) {
    VariousStatsManager.log(VariousEnum.MESSAGES_RECEIVED);
    IMessage message = event.getMessage();
    try {
        if (message.getAuthor().isBot()) {
            return;
        }
        if (message.getChannel().isPrivate()) {
            this.privateMessageReceived(message);
            return;
        }
        ShardManager.getShadbotShard(message.getShard()).messageReceived();
        if (!BotUtils.isChannelAllowed(message.getGuild(), message.getChannel())) {
            return;
        }
        if (MessageManager.intercept(message)) {
            return;
        }
        String prefix = Database.getDBGuild(message.getGuild()).getPrefix();
        if (message.getContent().startsWith(prefix)) {
            CommandManager.execute(new Context(prefix, message));
        }
    } catch (MissingPermissionsException err) {
        BotUtils.sendMessage(TextUtils.missingPerm(err.getMissingPermissions()), message.getChannel());
        LogUtils.infof("{Guild ID: %d} %s", message.getGuild().getLongID(), err.getMessage());
    } catch (Exception err) {
        BotUtils.sendMessage(Emoji.RED_FLAG + " Sorry, an unknown error occurred. My developer has been warned.", message.getChannel());
        LogUtils.error(message.getContent(), err, String.format("{Guild ID: %d} An unknown error occurred while receiving a message.", message.getGuild().getLongID()));
    }
}
Also used : Context(me.shadorc.shadbot.core.command.Context) IMessage(sx.blah.discord.handle.obj.IMessage) MissingPermissionsException(sx.blah.discord.util.MissingPermissionsException) MissingPermissionsException(sx.blah.discord.util.MissingPermissionsException) MissingArgumentException(me.shadorc.shadbot.exception.MissingArgumentException) IllegalCmdArgumentException(me.shadorc.shadbot.exception.IllegalCmdArgumentException)

Example 45 with IMessage

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

the class DiceManager method show.

private void show() {
    EmbedBuilder embed = EmbedUtils.getDefaultEmbed().setLenient(true).withAuthorName("Dice Game").withThumbnail("http://findicons.com/files/icons/2118/nuvola/128/package_games_board.png").withDescription(String.format("**Use `%s%s <num>` to join the game.**%n**Bet:** %s", this.getPrefix(), this.getCmdName(), FormatUtils.formatCoins(bet))).appendField("Player", numsPlayers.values().stream().map(IUser::getName).collect(Collectors.joining("\n")), true).appendField("Number", numsPlayers.keySet().stream().map(Object::toString).collect(Collectors.joining("\n")), true).appendField("Results", results, false).withFooterText(String.format("You have %d seconds to make your bets.", GAME_DURATION));
    RequestFuture<IMessage> msgRequest = message.send(embed.build());
    if (msgRequest != null) {
        msgRequest.get();
    }
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IMessage(sx.blah.discord.handle.obj.IMessage)

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