use of me.shadorc.shadbot.data.db.DBGuild in project Shadbot by Shadorc.
the class ChannelSetting method execute.
@Override
public void execute(Context context, String arg) throws MissingArgumentException, IllegalCmdArgumentException {
if (arg == null) {
throw new MissingArgumentException();
}
List<String> splitArgs = StringUtils.split(arg);
if (splitArgs.size() < 2) {
throw new MissingArgumentException();
}
List<IChannel> mentionedChannels = context.getMessage().getChannelMentions();
if (mentionedChannels.isEmpty()) {
throw new MissingArgumentException();
}
Action action = Utils.getValueOrNull(Action.class, splitArgs.get(0));
if (action == null) {
throw new IllegalCmdArgumentException(String.format("`%s` is not a valid action. %s", splitArgs.get(0), FormatUtils.formatOptions(Action.class)));
}
DBGuild dbGuild = Database.getDBGuild(context.getGuild());
List<Long> allowedChannelsList = dbGuild.getAllowedChannels();
if (Action.ADD.equals(action)) {
if (allowedChannelsList.isEmpty() && mentionedChannels.stream().noneMatch(channel -> channel.getLongID() == context.getChannel().getLongID())) {
BotUtils.sendMessage(Emoji.WARNING + " You did not mentioned this channel. " + "I will not reply here until this channel is added to the list of allowed channels.", context.getChannel());
}
allowedChannelsList.addAll(mentionedChannels.stream().map(IChannel::getLongID).filter(channelID -> !allowedChannelsList.contains(channelID)).collect(Collectors.toList()));
BotUtils.sendMessage(String.format(Emoji.CHECK_MARK + " Channel %s added to allowed channels.", FormatUtils.format(mentionedChannels, IChannel::mention, ", ")), context.getChannel());
} else {
allowedChannelsList.removeAll(mentionedChannels.stream().map(IChannel::getLongID).collect(Collectors.toList()));
BotUtils.sendMessage(String.format(Emoji.CHECK_MARK + " Channel %s removed from allowed channels.", FormatUtils.format(mentionedChannels, IChannel::mention, ", ")), context.getChannel());
}
dbGuild.setSetting(this.getSetting(), new JSONArray(allowedChannelsList));
}
use of me.shadorc.shadbot.data.db.DBGuild in project Shadbot by Shadorc.
the class AutoMessageSetting method updateJoinMessage.
private void updateJoinMessage(Context context, Action action, List<String> args) throws MissingArgumentException {
DBGuild dbGuild = Database.getDBGuild(context.getGuild());
if (Action.ENABLE.equals(action)) {
if (args.size() < 3) {
throw new MissingArgumentException();
}
String message = args.get(2);
dbGuild.setSetting(SettingEnum.JOIN_MESSAGE, message);
BotUtils.sendMessage(String.format(Emoji.CHECK_MARK + " Join message set to `%s`", message), context.getChannel());
} else if (Action.DISABLE.equals(action)) {
dbGuild.removeSetting(SettingEnum.JOIN_MESSAGE);
BotUtils.sendMessage(Emoji.CHECK_MARK + " Join message disabled.", context.getChannel());
}
}
Aggregations