use of me.shadorc.shadbot.data.db.DBGuild in project Shadbot by Shadorc.
the class ChannelListener method onChannelDeleteEvent.
private void onChannelDeleteEvent(ChannelDeleteEvent event) {
DBGuild dbGuild = Database.getDBGuild(event.getGuild());
List<Long> allowedChannelsID = dbGuild.getAllowedChannels();
if (allowedChannelsID.remove(event.getChannel().getLongID())) {
dbGuild.setSetting(SettingEnum.ALLOWED_CHANNELS, new JSONArray(allowedChannelsID));
}
}
use of me.shadorc.shadbot.data.db.DBGuild in project Shadbot by Shadorc.
the class GuildMemberListener method onUserLeaveEvent.
private void onUserLeaveEvent(UserLeaveEvent event) {
DBGuild dbGuild = Database.getDBGuild(event.getGuild());
Long channelID = dbGuild.getMessageChannelID();
String leaveMsg = dbGuild.getLeaveMessage();
this.sendAutoMsg(event.getGuild(), channelID, leaveMsg);
}
use of me.shadorc.shadbot.data.db.DBGuild in project Shadbot by Shadorc.
the class ServerInfoCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException {
IGuild guild = context.getGuild();
DBGuild dbGuild = Database.getDBGuild(guild);
StringBuilder settingsStr = new StringBuilder();
if (!dbGuild.getPrefix().equals(Config.DEFAULT_PREFIX)) {
settingsStr.append(String.format("**Prefix:** %s", context.getPrefix()));
}
if (dbGuild.getDefaultVol() != Config.DEFAULT_VOLUME) {
settingsStr.append(String.format("%n**Default volume:** %d%%", dbGuild.getDefaultVol()));
}
if (!dbGuild.getAllowedChannels().isEmpty()) {
List<IChannel> channels = dbGuild.getAllowedChannels().stream().map(guild::getChannelByID).filter(Objects::nonNull).collect(Collectors.toList());
settingsStr.append(String.format("%n**Allowed channels:**%n\t%s", FormatUtils.format(channels, IChannel::getName, "\n\t")));
}
if (!dbGuild.getBlacklistedCmd().isEmpty()) {
settingsStr.append(String.format("%n**Blacklisted commands:**%n\t%s", FormatUtils.format(dbGuild.getBlacklistedCmd(), Object::toString, "\n\t")));
}
if (!dbGuild.getAutoRoles().isEmpty()) {
List<IRole> roles = dbGuild.getAutoRoles().stream().map(guild::getRoleByID).filter(Objects::nonNull).collect(Collectors.toList());
settingsStr.append(String.format("%n**Auto-roles:**%n\t%s", FormatUtils.format(roles, IRole::mention, "\n\t")));
}
String creationDate = String.format("%s%n(%s)", TimeUtils.toLocalDate(guild.getCreationDate()).format(dateFormatter), FormatUtils.formatLongDuration(guild.getCreationDate()));
EmbedBuilder embed = EmbedUtils.getDefaultEmbed().setLenient(true).withAuthorName(String.format("Info about \"%s\"", guild.getName())).withThumbnail(guild.getIconURL()).appendField("Owner", guild.getOwner().getName(), true).appendField("Server ID", Long.toString(guild.getLongID()), true).appendField("Creation date", creationDate, true).appendField("Region", guild.getRegion().getName(), true).appendField("Channels", String.format("**Voice:** %d", guild.getVoiceChannels().size()) + String.format("%n**Text:** %d", guild.getChannels().size()), true).appendField("Members", Integer.toString(guild.getTotalMemberCount()), true).appendField("Settings", settingsStr.toString(), true);
BotUtils.sendMessage(embed.build(), context.getChannel());
}
use of me.shadorc.shadbot.data.db.DBGuild in project Shadbot by Shadorc.
the class AutoMessageSetting method channel.
private void channel(Context context, Action action) throws MissingArgumentException {
List<IChannel> channelsMentioned = context.getMessage().getChannelMentions();
if (channelsMentioned.size() != 1) {
throw new MissingArgumentException();
}
DBGuild dbGuild = Database.getDBGuild(context.getGuild());
IChannel channel = channelsMentioned.get(0);
if (Action.ENABLE.equals(action)) {
dbGuild.setSetting(SettingEnum.MESSAGE_CHANNEL_ID, channel.getLongID());
BotUtils.sendMessage(String.format(Emoji.CHECK_MARK + " %s is now the default channel for join/leave messages.", channel.mention()), context.getChannel());
} else if (Action.DISABLE.equals(action)) {
dbGuild.removeSetting(SettingEnum.MESSAGE_CHANNEL_ID);
BotUtils.sendMessage(String.format(Emoji.CHECK_MARK + " Auto-messages disabled. I will no longer send automatic messages " + "until a new channel is defined.", channel.mention()), context.getChannel());
}
}
use of me.shadorc.shadbot.data.db.DBGuild in project Shadbot by Shadorc.
the class AutoMessageSetting method updateLeaveMessage.
private void updateLeaveMessage(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.LEAVE_MESSAGE, message);
BotUtils.sendMessage(String.format(Emoji.CHECK_MARK + " Leave message set to `%s`", message), context.getChannel());
} else if (Action.DISABLE.equals(action)) {
dbGuild.removeSetting(SettingEnum.LEAVE_MESSAGE);
BotUtils.sendMessage(Emoji.CHECK_MARK + " Leave message disabled.", context.getChannel());
}
}
Aggregations