return sendMessage(String.format(format, args));
default RestAction<Message> getMessageById(long messageId) return getMessageById(Long.toUnsignedString(messageId));
public MessagePaginationAction(MessageChannel channel) { super(channel.getJDA(), Route.Messages.GET_MESSAGE_HISTORY.compile(channel.getId()), 1, 100, 100); if (channel.getType() == ChannelType.TEXT) { TextChannel textChannel = (TextChannel) channel; if (!textChannel.getGuild().getSelfMember().hasPermission(textChannel, Permission.MESSAGE_HISTORY)) throw new InsufficientPermissionException(Permission.MESSAGE_HISTORY); } this.channel = channel; }
@Override public String getJumpUrl() { return String.format("https://discordapp.com/channels/%s/%s/%s", getGuild() == null ? "@me" : getGuild().getId(), getChannel().getId(), getId()); }
HttpResponse<String> theImg = response.get(); BufferedImage image = ImageIO.read(theImg.getRawBody()); File memeFile = new File("tmp/meme_" + channel.getId() + ".jpg"); memeFile.getParentFile().mkdirs(); if (memeFile.exists()) { bot.queue.add(channel.sendFile(memeFile), message -> memeFile.delete()); return "";
/** * The {@link net.dv8tion.jda.core.entities.ChannelType ChannelType} for this message * * @return The ChannelType */ public ChannelType getChannelType() { return channel.getType(); }
if (channel.getType().equals(ChannelType.TEXT) && !PermissionUtil.checkPermission((TextChannel) channel, ((TextChannel) channel).getGuild().getSelfMember(), Permission.MESSAGE_ATTACH_FILES)) { return Templates.permission_missing.formatGuild(channel, "MESSAGE_ATTACH_FILES"); File outputfile = new File("tmp_" + channel.getId() + ".jpg"); ImageIO.write(ImageIO.read(in), "jpg", outputfile); bot.queue.add(channel.sendFile(outputfile, new MessageBuilder().append(post.data.title).build()), message -> outputfile.delete()); return ""; } catch (IOException e) {
context.getMessageChannel().sendTyping().queue(); int timeout = args[0].equals("timeout") || args[0].equals("-t") ? NumberUtil.parseInt(args[1], -1) : -1; String output = out == null ? ":thumbsup::skin-tone-3:" : "```\n" + out.toString() + "\n```"; context.getMessageChannel().sendMessage(String.format("**Input** ```java\n%s```\n**Output**\n%s\nEval took _%sms_", source, output, System.currentTimeMillis() - started )).queue();
public void addReaction(Message message) { if (!(message.getChannel().getType() == ChannelType.TEXT && message.getGuild().getSelfMember() .hasPermission(message.getTextChannel(), Permission.MESSAGE_HISTORY))) { message.getChannel().sendMessage("I can't add buttons due to not having the `Message History` permission!").queue(); return; } this.message = message; if (unicode != null) message.addReaction(unicode).queue(); else { try { message.addReaction(Getters.getEmoteById(emoteId)).queue(); } catch (IllegalArgumentException ignored) {} } }
@Override public String execute(DiscordBot bot, String[] args, MessageChannel channel, User author, Message inputMessage) { if (!DisUtil.hasPermission(channel, channel.getJDA().getSelfUser(), Permission.MESSAGE_ADD_REACTION)) { return Templates.permission_missing.formatGuild(channel, Permission.MESSAGE_ADD_REACTION.toString()); } Game2048 game = new Game2048(); game.addPlayer(author); bot.queue.add(channel.sendMessage(game.toString()), message -> bot.commandReactionHandler.addReactionListener(((TextChannel) channel).getGuild().getIdLong(), message, getReactionListener(author.getIdLong(), game))); return ""; }
if (!user.equals(getJDA().getSelfUser())) if (channel.getType() == ChannelType.TEXT) Route.CompiledRoute route; if (user.equals(getJDA().getSelfUser())) route = Route.Messages.REMOVE_OWN_REACTION.compile(channel.getId(), getMessageId(), code); else route = Route.Messages.REMOVE_REACTION.compile(channel.getId(), getMessageId(), code, user.getId()); return new RestAction<Void>(getJDA(), route)
default MessageAction sendFile(InputStream data, String fileName) return sendFile(data, fileName, null);
@Override public boolean onCommand(CommandMessage context, String[] args) { if (!hasApiKey()) { return false; } if (args.length == 0) { return sendErrorMessage(context, "errors.missingArgument", "city"); } DrainWeatherQueueTask.queueWeather(new DrainWeatherQueueTask.WeatherEntity( context.getAuthor().getIdLong(), context.getMessageChannel().getIdLong(), String.join(" ", args) )); context.getMessageChannel().sendTyping().queue(); return true; }
public final boolean executeReaction(User player, MessageChannel channel, MessageReaction reaction, String messageId) { if (!channel.getType().equals(ChannelType.TEXT) || !reactionMessages.containsKey(messageId)) { return false; } if (!isInAGame(player.getId())) { return false; } if (!getGame(player.getId()).isTurnOf(player)) { return false; } final String input = Misc.emoteToNumber(reaction.getReactionEmote().getName()); Message msg = channel.getMessageById(messageId).complete(); if (msg == null) { return false; } execute(player, (TextChannel) channel, input, msg); return true; }
@Override public String execute(DiscordBot bot, String[] args, MessageChannel channel, User author, Message inputMessage) { if (items.size() < MIN_QUEUE_ITEMS) { bot.queue.add(channel.sendTyping()); getFMLItems(); } if (!items.isEmpty()) { try { String item = StringEscapeUtils.unescapeHtml4(items.take()); if (item.length() >= 2000) { item = item.substring(0, 1999); } return item; } catch (InterruptedException e) { Launcher.logToDiscord(e, "fml-command", "interrupted"); } } return Templates.command.fml_not_today.formatGuild(channel); }
try { if(event.getGuild().getSelfMember().hasPermission(event.getTextChannel(), Permission.MESSAGE_MANAGE)) { event.getChannel().getMessageById(event.getMessageId()).queue(message -> { for (MessageReaction reaction : message.getReactions()) { if (reaction.getReactionEmote().equals(event.getReactionEmote())) { event.getChannel().getMessageById(event.getMessageId()).queue(message -> { MessageReaction reaction = message.getReactions().stream().filter(r -> r.getReactionEmote().getName() if (reaction != null) { if (reaction.getCount() == 5) { message.pin().queue((aVoid) -> event.getChannel().getHistory().retrievePast(1).complete().get(0) .delete().queue());
@Override default void formatTo(Formatter formatter, int flags, int width, int precision) { boolean leftJustified = (flags & FormattableFlags.LEFT_JUSTIFY) == FormattableFlags.LEFT_JUSTIFY; boolean upper = (flags & FormattableFlags.UPPERCASE) == FormattableFlags.UPPERCASE; boolean alt = (flags & FormattableFlags.ALTERNATE) == FormattableFlags.ALTERNATE; String out; out = upper ? getName().toUpperCase(formatter.locale()) : getName(); if (alt) out = "#" + out; MiscUtil.appendTo(formatter, width, precision, leftJustified, out); } }