/** * Gets the channel the messages were sent in, or null if no messages are present. * * @return The channel the messages were sent in, or null if no messages are present. */ public IChannel getChannel() { return (backing.length == 0) ? null : backing[0].getChannel(); }
public MessageEvent(IMessage message) { super(message.getChannel()); this.message = message; this.messageID = message.getLongID(); }
@Override public void throwException(IMessage message, Command command, Language lg, Object... arguments) { throwException(message.getChannel(), lg, (MissingPermissionsException) arguments[0]); }
@Override public void request(IMessage message, Matcher m, Language lg) { if (m.group(1).matches("\\s+-cmd")){ Message.sendFile(message.getChannel(), CommandStatistics.purge(), "purge -cmd : " + Instant.now() + ".sql"); } }
@Override public void throwException(IMessage message, Command command, Language lg, Object... arguments) { Message.sendText(message.getChannel(), Translator.getLabel(lg, "exception.bad_use_command") .replace("{author}", Matcher.quoteReplacement(message.getAuthor().toString())) .replaceAll("\\{prefix}", Matcher.quoteReplacement(AbstractCommand.getPrefix(message))) .replaceAll("\\{cmd.name}", command.getName()) .replace("{HelpCmd.name}", HelpCommand.NAME)); } }
@Override public void throwException(IMessage message, Command command, Language lg, Object... arguments) { Message.sendText(message.getChannel(), Translator.getLabel(lg, messageKey)); } }
@EventSubscriber public void onMessageReceived(MessageReceivedEvent event) { IMessage message = event.getMessage(); String[] command = message.getContent().split(" ", 2); IGuild guild = message.getGuild(); if (guild != null) { if ("~play".equals(command[0]) && command.length == 2) { loadAndPlay(message.getChannel(), command[1]); } else if ("~skip".equals(command[0])) { skipTrack(message.getChannel()); } } }
@Override public void throwException(IMessage message, Command command, Language lg, Object... arguments) { String content = Translator.getLabel(lg, messageKey); for(int i = 0; i < parameters.length; i++) if (translatable.length > i && translatable[i]) content = content.replace("{" + i + "}", Translator.getLabel(lg, parameters[i])); else content = content.replace("{" + i + "}", parameters[i]); Message.sendText(message.getChannel(), content); } }
protected String getPrefixMdEscaped(IMessage message){ if (! message.getChannel().isPrivate()) return Guild.getGuild(message.getGuild()).getPrefix() .replaceAll("\\*", "\\\\*") // Italic & Bold .replaceAll("_", "\\_") // Underline .replaceAll("~", "\\~") // Strike .replaceAll("\\`", "\\\\`"); // Code return ""; }
public static void manageException(Exception e, IMessage message, Command command, Language lg){ Reporter.report(e, message.getGuild(), message.getChannel(), message.getAuthor(), message); LOG.error("manageException", e); BasicDiscordException.UNKNOWN_ERROR.throwException(message, command, lg); }
/** * @param message message d'origine * @return true si les permissions sont suffisantes, false le cas échéant */ protected boolean isChannelHasExternalEmojisPermission(IMessage message){ return message.getChannel().isPrivate() || message.getChannel().getModifiedPermissions(ClientConfig.DISCORD().getOurUser()) .contains(Permissions.USE_EXTERNAL_EMOJIS) && ClientConfig.DISCORD().getOurUser().getPermissionsForGuild(message.getGuild()) .contains(Permissions.USE_EXTERNAL_EMOJIS); }
/** * Retourne true si l'utilisateur a les droits nécessaires, false le cas échéant * @param message Message reçu * @return true si l'utilisateur a les droits nécessaires, false le cas échéant */ protected boolean isUserHasEnoughRights(IMessage message){ return ! message.getChannel().isPrivate() && (message.getAuthor().getLongID() == Constants.authorId || message.getAuthor().getPermissionsForGuild(message.getGuild()).contains(Permissions.MANAGE_SERVER) || message.getChannel().getModifiedPermissions(message.getAuthor()).contains(Permissions.MANAGE_SERVER)); }
private List<Requestable> getListTutoFrom(String url, IMessage message){ List<Requestable> result = new ArrayList<>(); Language lg = Translator.getLanguageFrom(message.getChannel()); try { Document doc = JSoupManager.getDocument(url); Elements elems = doc.getElementById("wsite-search-list").getElementsByTag("a"); for (Element element : elems) result.add(new Requestable(element.child(0).text(), element.attr("href"))); } catch(IOException e){ ExceptionManager.manageIOException(e, message, this, lg, notFoundTuto); return new ArrayList<>(); } catch (Exception e) { ExceptionManager.manageException(e, message, this, lg); return new ArrayList<>(); } return result; }
private void playSound(IVoiceChannel voice, IMessage message, File file) { try { voice.join(); AudioPlayer.getAudioPlayerForGuild(message.getGuild()).queue(file).getMetadata() .put(file.getName(), file.toString()); } catch (IOException | UnsupportedAudioFileException e) { Reporter.report(e, message.getGuild(), message.getChannel(), message.getAuthor(), message); LOG.error("playSound", e); } }
@Override public void request(IMessage message, Matcher m, Language lg) { String oldSize = FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(new File(Constants.database))); Connexion connexion = Connexion.getInstance(); Connection connection = connexion.getConnection(); try { PreparedStatement preparedStatement = connection.prepareStatement("VACUUM;"); preparedStatement.executeUpdate(); String newSize = FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(new File(Constants.database))); Message.sendText(message.getChannel(), "OK : " + oldSize + " -> " + newSize); } catch (SQLException e) { Reporter.report(e, message.getGuild(), message.getChannel(), message.getAuthor(), message); BasicDiscordException.UNKNOWN_ERROR.throwException(message, this, lg); LOG.error("request", e); } }
public static String getPrefix(IMessage message){ String prefix = ""; if (! message.getChannel().isPrivate()) prefix = Guild.getGuild(message.getGuild()).getPrefix(); return prefix; }
@Override public void request(IMessage message, Matcher m, Language lg) { if (message.getChannel().isPrivate() || message.getChannel().isNSFW()) { EmbedBuilder builder = new EmbedBuilder(); builder.withTitle(Translator.getLabel(lg, "sendnude.title")) .withColor(PINK_COLOR) .withFooterText(Translator.getLabel(lg, "sendnude.author") .replace("{author}", Nude.MOAM.getAuthor()) .replace("{position}", "1") .replace("{number}", "1")) .withImage(Nude.MOAM.getImage()); Message.sendEmbed(message.getChannel(), builder.build()); } else // Exception NSFW BasicDiscordException.NO_NSFW_CHANNEL.throwException(message, this, lg); }
@Override public void unpin(IMessage message) { PermissionUtils.requirePermissions(this, client.getOurUser(), Permissions.MANAGE_MESSAGES); if (!message.getChannel().equals(this)) throw new DiscordException("Message channel doesn't match current channel!"); if (!message.isPinned()) throw new DiscordException("Message is not pinned!"); ((DiscordClientImpl) client).REQUESTS.DELETE.makeRequest(DiscordEndpoints.CHANNELS + id + "/pins/" + message.getStringID()); }
@Override public void pin(IMessage message) { PermissionUtils.requirePermissions(this, client.getOurUser(), Permissions.MANAGE_MESSAGES); if (!message.getChannel().equals(this)) throw new DiscordException("Message channel doesn't match current channel!"); if (message.isPinned()) throw new DiscordException("Message already pinned!"); ((DiscordClientImpl) client).REQUESTS.PUT.makeRequest(DiscordEndpoints.CHANNELS + id + "/pins/" + message.getStringID()); }
@Override public List<IUser> getUsers() { List<IUser> users = new ArrayList<>(); String emoji = getEmoji().isUnicode() ? getEmoji().getName() : getEmoji().getName() + ":" + getEmoji().getStringID(); String endpoint = String.format(DiscordEndpoints.REACTIONS_USER_LIST, getMessage().getChannel().getStringID(), getMessage().getStringID(), emoji); String after = "0"; while (users.size() < count) { UserObject[] json = ((DiscordClientImpl) getClient()).REQUESTS.GET.makeRequest( endpoint + "?after=" + after + "&limit=100", UserObject[].class); for (UserObject obj : json) { users.add(getMessage().getShard().getUserByID(Long.parseUnsignedLong(obj.id))); } // Temporary measure so a refactor can be applied later. if (json.length == 0) break; after = json[json.length - 1].id; } return users; }