/** * Gets the author of the message. * * <p>This is equivalent to <code>getMessage().getAuthor()</code> * * @return The author of the message. */ public IUser getAuthor() { return message == null ? null : message.getAuthor(); }
@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)); } }
/** * 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)); }
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); }
public static boolean hasManageServerRole(MessageReceivedEvent event) { return event.getMessage().getAuthor().getPermissionsForGuild(event.getMessage().getGuild()).contains(Permissions.MANAGE_SERVER); }
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); } }
public static void manageIOException(Exception e, IMessage message, Command command, Language lg, DiscordException notFound){ // First we try parsing the exception message to see if it contains the response code Matcher exMsgStatusCodeMatcher = Pattern.compile("^Server returned HTTP response code: (\\d+)") .matcher(e.getMessage()); if(exMsgStatusCodeMatcher.find()) { int statusCode = Integer.parseInt(exMsgStatusCodeMatcher.group(1)); if (statusCode >= 500 && statusCode < 600) { LOG.warn("manageIOException", e); gameWebsite503.throwException(message, command, lg); } else { Reporter.report(e, message.getGuild(), message.getChannel(), message.getAuthor(), message); LOG.error("manageIOException", e); BasicDiscordException.UNKNOWN_ERROR.throwException(message, command, lg); } } else if (e instanceof UnknownHostException || e instanceof SocketTimeoutException) { gameWebsite503.throwException(message, command, lg); } else if (e instanceof FileNotFoundException || e instanceof HttpStatusException || e instanceof NoRouteToHostException){ notFound.throwException(message, command, lg); } else { Reporter.report(e, message.getGuild(), message.getChannel(), message.getAuthor(), message); LOG.error("manageIOException", e); BasicDiscordException.UNKNOWN_ERROR.throwException(message, command, lg); } }
@Override public void request(IMessage message, Matcher m, Language lg) { if (m.group(1) == null && m.group(5) == null) { // No dimension precised for(Portal pos : Guild.getGuild(message.getGuild()).getPortals()) Message.sendEmbed(message.getChannel(), pos.getEmbedObject(lg)); } else { List<Portal> portals = new ArrayList<>(); if (m.group(1) != null) portals = getPortal(m.group(1), Guild.getGuild(message.getGuild())); if (portals.size() == 1) { if (m.group(2) != null) portals.get(0).setCoordonate(Position.parse("[" + m.group(3) + "," + m.group(4) + "]"), message.getAuthor().getDisplayName(message.getGuild())); if (m.group(5) != null) portals.get(0).setUtilisation(Integer.parseInt(m.group(5).replaceAll("\\s", "")), message.getAuthor().getDisplayName(message.getGuild())); Message.sendEmbed(message.getChannel(), portals.get(0).getEmbedObject(lg)); } else if(portals.size() > 1) tooMuchPortals.throwException(message, this, lg); else notFoundPortal.throwException(message, this, lg); } }
@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); } }
@EventSubscriber public void onReady(MessageReceivedEvent event) { Language lg = Translator.getLanguageFrom(event.getChannel()); String prefixe = AbstractCommand.getPrefix(event.getMessage()); // If the authorId is a bot, message get ignored if (! event.getMessage().getAuthor().isBot()) { List<Command> commandsAvailable = new ArrayList<>(); for (Command command : CommandManager.getCommands()) if (event.getMessage().getContent().startsWith(prefixe + command.getName())) commandsAvailable.add(command); if (!commandsAvailable.isEmpty()){ commandsAvailable.sort((cmd1, cmd2) -> cmd2.getName().length() - cmd1.getName().length()); Command command = commandsAvailable.get(0); try { command.request(event.getMessage()); } catch (Exception e) { BasicDiscordException.UNKNOWN_ERROR.throwException(event.getMessage(), command, lg); Reporter.report(e, event.getGuild(), event.getChannel(), event.getAuthor(), event.getMessage()); LOG.error("onReady", e); } } } } }
return; if (!hasPermission(event.getMessage().getAuthor(), commandAnnotation.requiredPermissions())) { if (Sdcf4jMessage.MISSING_PERMISSIONS.getMessage() != null) { try {
if ((!isPublic() || isAdmin()) && message.getAuthor().getLongID() != Constants.authorId) return; else if (!message.getChannel().isPrivate() && message.getAuthor().getLongID() != Constants.authorId && isForbidden(Guild.getGuild(message.getGuild()))) { BasicDiscordException.COMMAND_FORBIDDEN.throwException(message, this, lg); Reporter.report(e, message.getGuild(), message.getChannel(), message.getAuthor(), message); LOG.error("request", e);
parameters[i] = event.getMessage().getChannel(); } else if (type == IUser.class) { parameters[i] = event.getMessage().getAuthor(); } else if (type == IGuild.class) { parameters[i] = event.getMessage().getChannel().getGuild();
Discord4J.LOGGER.debug(LogMarkers.MESSAGES, "Message from: {} ({}) in channel ID {}: {}", message.getAuthor().getName(), json.author.id, json.channel_id, json.content); if (message.getAuthor().equals(client.getOurUser())) { client.dispatcher.dispatch(new MessageSendEvent(message)); message.getChannel().setTypingStatus(false); //Messages being sent should stop the bot from typing
GuildSettings settings = DatabaseManager.getManager().getSettings(event.getGuild().getLongID()); if (!settings.getControlRole().equalsIgnoreCase("everyone")) { IUser sender = event.getMessage().getAuthor(); String roleId = settings.getControlRole(); IRole role = null; Logger.getLogger().exception(event.getMessage().getAuthor(), "Failed to check for sufficient control role.", e, PermissionChecker.class); return true;
/** * Checks if the user sent the command in a DisCal channel (if set). * * @param event The event received to check for the correct channel. * @return <code>true</code> if in correct channel, otherwise <code>false</code>. */ public static boolean isCorrectChannel(MessageReceivedEvent event) { try { GuildSettings settings = DatabaseManager.getManager().getSettings(event.getGuild().getLongID()); if (settings.getDiscalChannel().equalsIgnoreCase("all")) return true; IChannel channel = null; for (IChannel c : event.getMessage().getGuild().getChannels()) { if (c.getStringID().equals(settings.getDiscalChannel())) { channel = c; break; } } if (channel != null) return event.getMessage().getChannel().getStringID().equals(channel.getStringID()); //If we got here, the channel no longer exists, reset data and return true. settings.setDiscalChannel("all"); DatabaseManager.getManager().updateSettings(settings); return true; } catch (Exception e) { //Catch any errors so that the bot always responds... Logger.getLogger().exception(event.getMessage().getAuthor(), "Failed to check for discal channel.", e, PermissionChecker.class); return true; } }