Search in sources :

Example 1 with DBGuild

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));
    }
}
Also used : DBGuild(me.shadorc.shadbot.data.db.DBGuild) JSONArray(org.json.JSONArray)

Example 2 with DBGuild

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);
}
Also used : DBGuild(me.shadorc.shadbot.data.db.DBGuild)

Example 3 with DBGuild

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());
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) DBGuild(me.shadorc.shadbot.data.db.DBGuild) IChannel(sx.blah.discord.handle.obj.IChannel) IRole(sx.blah.discord.handle.obj.IRole) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject) IGuild(sx.blah.discord.handle.obj.IGuild)

Example 4 with DBGuild

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());
    }
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) DBGuild(me.shadorc.shadbot.data.db.DBGuild) MissingArgumentException(me.shadorc.shadbot.exception.MissingArgumentException)

Example 5 with DBGuild

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());
    }
}
Also used : DBGuild(me.shadorc.shadbot.data.db.DBGuild) MissingArgumentException(me.shadorc.shadbot.exception.MissingArgumentException)

Aggregations

DBGuild (me.shadorc.shadbot.data.db.DBGuild)12 MissingArgumentException (me.shadorc.shadbot.exception.MissingArgumentException)7 IllegalCmdArgumentException (me.shadorc.shadbot.exception.IllegalCmdArgumentException)4 JSONArray (org.json.JSONArray)4 IChannel (sx.blah.discord.handle.obj.IChannel)3 IRole (sx.blah.discord.handle.obj.IRole)3 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)3 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 AbstractSetting (me.shadorc.shadbot.command.admin.setting.core.AbstractSetting)2 Setting (me.shadorc.shadbot.command.admin.setting.core.Setting)2 SettingEnum (me.shadorc.shadbot.command.admin.setting.core.SettingEnum)2 Context (me.shadorc.shadbot.core.command.Context)2 Database (me.shadorc.shadbot.data.db.Database)2 BotUtils (me.shadorc.shadbot.utils.BotUtils)2 FormatUtils (me.shadorc.shadbot.utils.FormatUtils)2 StringUtils (me.shadorc.shadbot.utils.StringUtils)2 Utils (me.shadorc.shadbot.utils.Utils)2 EmbedUtils (me.shadorc.shadbot.utils.embed.EmbedUtils)2 Emoji (me.shadorc.shadbot.utils.object.Emoji)2