diff --git a/pom.xml b/pom.xml index c4be9bb..56e175e 100644 --- a/pom.xml +++ b/pom.xml @@ -36,16 +36,17 @@ - com.github.jagrosh + com.github.discord-jda JDA - vortex-SNAPSHOT + v6.4.1 - - com.jagrosh - jda-utilities - 3.0.5 - pom - + + pw.chew + jda-chewtils + 2.2.1 + compile + pom + com.github.jagrosh easysql diff --git a/src/main/java/com/jagrosh/vortex/Constants.java b/src/main/java/com/jagrosh/vortex/Constants.java index a5c975e..530b2dd 100644 --- a/src/main/java/com/jagrosh/vortex/Constants.java +++ b/src/main/java/com/jagrosh/vortex/Constants.java @@ -37,11 +37,11 @@ public final static String VORTEX_EMOJI = Emoji.VORTEX; public final static int DEFAULT_CACHE_SIZE = 8000; public final static Permission[] PERMISSIONS = {Permission.ADMINISTRATOR, Permission.BAN_MEMBERS, Permission.KICK_MEMBERS, Permission.MANAGE_ROLES, - Permission.MANAGE_SERVER, Permission.MESSAGE_ADD_REACTION, Permission.MESSAGE_ATTACH_FILES, Permission.MESSAGE_READ, - Permission.MESSAGE_WRITE,Permission.MESSAGE_EMBED_LINKS, Permission.MESSAGE_HISTORY, Permission.MESSAGE_EXT_EMOJI, + Permission.MANAGE_SERVER, Permission.MESSAGE_ADD_REACTION, Permission.MESSAGE_ATTACH_FILES, Permission.VIEW_CHANNEL, + Permission.MESSAGE_SEND,Permission.MESSAGE_EMBED_LINKS, Permission.MESSAGE_HISTORY, Permission.MESSAGE_EXT_EMOJI, Permission.MESSAGE_MANAGE, Permission.VOICE_CONNECT, Permission.VOICE_MOVE_OTHERS, Permission.VOICE_DEAF_OTHERS, Permission.VOICE_MUTE_OTHERS, Permission.NICKNAME_CHANGE, Permission.NICKNAME_MANAGE, Permission.VIEW_AUDIT_LOGS}; - public final static EnumSet INTENTS = EnumSet.of(GatewayIntent.DIRECT_MESSAGES, GatewayIntent.GUILD_BANS, GatewayIntent.GUILD_INVITES, + public final static EnumSet INTENTS = EnumSet.of(GatewayIntent.DIRECT_MESSAGES, GatewayIntent.GUILD_MODERATION, GatewayIntent.GUILD_INVITES, GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_MESSAGE_REACTIONS, GatewayIntent.GUILD_VOICE_STATES); public final static String SERVER_INVITE = "https://discord.gg/pQNtuyT3TZ"; //public final static String BOT_INVITE = "https://discordapp.com/oauth2/authorize?client_id=240254129333731328&scope=bot&permissions="+Permission.getRaw(PERMISSIONS); diff --git a/src/main/java/com/jagrosh/vortex/Emoji.java b/src/main/java/com/jagrosh/vortex/Emoji.java index ef2b1d6..1442025 100644 --- a/src/main/java/com/jagrosh/vortex/Emoji.java +++ b/src/main/java/com/jagrosh/vortex/Emoji.java @@ -22,11 +22,11 @@ public class Emoji { // vortex general icons - public final static String VORTEX = "<:frye:1253366756865740810>"; - public final static String SUCCESS = "<:frye:1253366756865740810>"; + public final static String VORTEX = "<:check:1508781509124034601>"; + public final static String SUCCESS = "<:check:1508781509124034601>"; public final static String WARNING = ":warning:"; - public final static String ERROR = ":x:"; - public final static String LOADING = ""; + public final static String ERROR = "<:x_:1508781485228818582>"; + public final static String LOADING = ""; // bot public final static String BOT = "<:bot:850113743764717627>"; diff --git a/src/main/java/com/jagrosh/vortex/Listener.java b/src/main/java/com/jagrosh/vortex/Listener.java index cc367e1..ecdcf63 100644 --- a/src/main/java/com/jagrosh/vortex/Listener.java +++ b/src/main/java/com/jagrosh/vortex/Listener.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,21 +23,19 @@ import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.events.GenericEvent; -import net.dv8tion.jda.api.events.ReadyEvent; -import net.dv8tion.jda.api.events.channel.text.update.TextChannelUpdateSlowmodeEvent; +import net.dv8tion.jda.api.events.session.ReadyEvent; +import net.dv8tion.jda.api.events.channel.update.ChannelUpdateSlowmodeEvent; import net.dv8tion.jda.api.events.guild.GuildBanEvent; import net.dv8tion.jda.api.events.guild.GuildJoinEvent; import net.dv8tion.jda.api.events.guild.GuildUnbanEvent; import net.dv8tion.jda.api.events.guild.member.*; import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateNicknameEvent; import net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateTimeOutEvent; -import net.dv8tion.jda.api.events.guild.voice.GuildVoiceJoinEvent; -import net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent; -import net.dv8tion.jda.api.events.guild.voice.GuildVoiceMoveEvent; +import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent; import net.dv8tion.jda.api.events.message.MessageBulkDeleteEvent; -import net.dv8tion.jda.api.events.message.guild.GuildMessageDeleteEvent; -import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; -import net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent; +import net.dv8tion.jda.api.events.message.MessageDeleteEvent; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; +import net.dv8tion.jda.api.events.message.MessageUpdateEvent; import net.dv8tion.jda.api.events.user.update.UserUpdateAvatarEvent; import net.dv8tion.jda.api.events.user.update.UserUpdateNameEvent; import net.dv8tion.jda.api.hooks.EventListener; @@ -63,9 +61,11 @@ @Override public void onEvent(GenericEvent event) { - if (event instanceof GuildMessageReceivedEvent) + if (event instanceof MessageReceivedEvent) { - Message m = ((GuildMessageReceivedEvent)event).getMessage(); + MessageReceivedEvent mevent = (MessageReceivedEvent) event; + if (!mevent.isFromGuild()) return; + Message m = mevent.getMessage(); if(!m.getAuthor().isBot()) // ignore bot messages { @@ -76,9 +76,11 @@ vortex.getAutoMod().performAutomod(m); } } - else if (event instanceof GuildMessageUpdateEvent) + else if (event instanceof MessageUpdateEvent) { - Message m = ((GuildMessageUpdateEvent)event).getMessage(); + MessageUpdateEvent uevent = (MessageUpdateEvent) event; + if (!uevent.isFromGuild()) return; + Message m = uevent.getMessage(); if(!m.getAuthor().isBot()) // ignore bot edits { @@ -90,26 +92,27 @@ vortex.getBasicLogger().logMessageEdit(m, old); } } - else if (event instanceof GuildMessageDeleteEvent) + else if (event instanceof MessageDeleteEvent) { - GuildMessageDeleteEvent gevent = (GuildMessageDeleteEvent) event; + MessageDeleteEvent devent = (MessageDeleteEvent) event; + if (!devent.isFromGuild()) return; // Log the deletion - CachedMessage old = vortex.getMessageCache().pullMessage(gevent.getGuild(), gevent.getMessageIdLong()); + CachedMessage old = vortex.getMessageCache().pullMessage(devent.getGuild(), devent.getMessageIdLong()); vortex.getBasicLogger().logMessageDelete(old); } else if (event instanceof MessageBulkDeleteEvent) { - MessageBulkDeleteEvent gevent = (MessageBulkDeleteEvent) event; + MessageBulkDeleteEvent bdevent = (MessageBulkDeleteEvent) event; // Get the messages we had cached - List logged = gevent.getMessageIds().stream() - .map(id -> vortex.getMessageCache().pullMessage(gevent.getGuild(), Long.parseLong(id))) + List logged = bdevent.getMessageIds().stream() + .map(id -> vortex.getMessageCache().pullMessage(bdevent.getGuild(), Long.parseLong(id))) .filter(m -> m!=null) .collect(Collectors.toList()); // Log the deletion - vortex.getBasicLogger().logMessageBulkDelete(logged, gevent.getMessageIds().size(), gevent.getChannel()); + vortex.getBasicLogger().logMessageBulkDelete(logged, bdevent.getMessageIds().size(), bdevent.getChannel().asTextChannel()); } else if (event instanceof GuildMemberJoinEvent) { @@ -187,33 +190,28 @@ if(!uaue.getUser().isBot()) vortex.getBasicLogger().logAvatarChange(uaue); } - else if (event instanceof GuildVoiceJoinEvent) + else if (event instanceof GuildVoiceUpdateEvent) { - GuildVoiceJoinEvent gevent = (GuildVoiceJoinEvent)event; - - // Log the voice join - if(!gevent.getMember().getUser().isBot()) // ignore bots - vortex.getBasicLogger().logVoiceJoin(gevent); + GuildVoiceUpdateEvent vevent = (GuildVoiceUpdateEvent) event; + if (!vevent.getMember().getUser().isBot()) // ignore bots + { + if (vevent.getChannelLeft() == null && vevent.getChannelJoined() != null) + { + vortex.getBasicLogger().onVoiceUpdate(vevent); + } + else if (vevent.getChannelLeft() != null && vevent.getChannelJoined() != null) + { + vortex.getBasicLogger().onVoiceUpdate(vevent); + } + else if (vevent.getChannelLeft() != null && vevent.getChannelJoined() == null) + { + vortex.getBasicLogger().onVoiceUpdate(vevent); + } + } } - else if (event instanceof GuildVoiceMoveEvent) + else if (event instanceof ChannelUpdateSlowmodeEvent) { - GuildVoiceMoveEvent gevent = (GuildVoiceMoveEvent)event; - - // Log the voice move - if(!gevent.getMember().getUser().isBot()) // ignore bots - vortex.getBasicLogger().logVoiceMove(gevent); - } - else if (event instanceof GuildVoiceLeaveEvent) - { - GuildVoiceLeaveEvent gevent = (GuildVoiceLeaveEvent)event; - - // Log the voice leave - if(!gevent.getMember().getUser().isBot()) // ignore bots - vortex.getBasicLogger().logVoiceLeave(gevent); - } - else if (event instanceof TextChannelUpdateSlowmodeEvent) - { - vortex.getDatabase().tempslowmodes.clearSlowmode(((TextChannelUpdateSlowmodeEvent) event).getChannel()); + vortex.getDatabase().tempslowmodes.clearSlowmode(((ChannelUpdateSlowmodeEvent) event).getChannel().asTextChannel()); } else if (event instanceof GuildMemberUpdateTimeOutEvent) { @@ -238,8 +236,8 @@ ShardInfo si = event.getJDA().getShardInfo(); String shardinfo = (si.getShardId()+1)+"/"+si.getShardTotal(); LOG.info("Shard "+shardinfo+" is ready."); - vortex.getLogWebhook().send("\uD83C\uDF00 Shard `"+shardinfo+"` has connected. Guilds: `" // 🌀 + vortex.getLogWebhook().send("\uD83C\uDF00 Shard `"+shardinfo+"` has connected. Guilds: `" +event.getJDA().getGuildCache().size()+"` Users: `"+event.getJDA().getUserCache().size()+"`"); } } -} +} \ No newline at end of file diff --git a/src/main/java/com/jagrosh/vortex/Vortex.java b/src/main/java/com/jagrosh/vortex/Vortex.java index ddb9f5d..26260f4 100644 --- a/src/main/java/com/jagrosh/vortex/Vortex.java +++ b/src/main/java/com/jagrosh/vortex/Vortex.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,8 +17,7 @@ import club.minnced.discord.webhook.WebhookClient; import club.minnced.discord.webhook.WebhookClientBuilder; -import com.jagrosh.vortex.commands.tools.LookupCmd; -import com.jagrosh.vortex.commands.general.AirstrikeCmd; +// import com.jagrosh.vortex.commands.tools.LookupCmd; import com.jagrosh.vortex.commands.automod.*; import com.jagrosh.vortex.commands.general.*; import com.jagrosh.vortex.commands.moderation.*; @@ -49,11 +48,12 @@ import java.util.Arrays; import java.util.concurrent.TimeUnit; import net.dv8tion.jda.api.entities.Activity; -import net.dv8tion.jda.api.entities.ChannelType; import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.entities.channel.ChannelType; +import net.dv8tion.jda.api.entities.channel.concrete.*; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.exceptions.PermissionException; -import net.dv8tion.jda.api.requests.restaction.MessageAction; import net.dv8tion.jda.api.utils.MemberCachePolicy; import net.dv8tion.jda.api.utils.cache.CacheFlag; @@ -116,15 +116,6 @@ new ServerinfoCmd(), new UserinfoCmd(), - // andrea commands - new AirstrikeCmd(), - new FuckCmd(), - new AssassinateCmd(), - new BombCmd(), - new MolestCmd(), - new TouchCmd(), - new FillCmd(), - // Moderation new KickCmd(this), new BanCmd(this), @@ -132,8 +123,8 @@ new SilentbanCmd(this), new UnbanCmd(this), new CleanCmd(this), - new VoicemoveCmd(this), - new VoicekickCmd(this), + // new VoicemoveCmd(this), + // new VoicekickCmd(this), new MuteCmd(this), new UnmuteCmd(this), new RaidCmd(this), @@ -174,11 +165,11 @@ // Tools new AnnounceCmd(), - new AuditCmd(), + // new AuditCmd(), new DehoistCmd(), new ExportCmd(this), new InvitepruneCmd(this), - new LookupCmd(this), + // new LookupCmd(this), // Owner new EvalCmd(this), @@ -192,19 +183,16 @@ if(event.isFromType(ChannelType.TEXT)) try { - event.getMessage().addReaction(Constants.HELP_REACTION).queue(s->{}, f->{}); + event.getMessage().addReaction(net.dv8tion.jda.api.entities.emoji.Emoji.fromFormatted(Constants.HELP_REACTION)).queue(s->{}, f->{}); } catch(PermissionException ignore) {} }, t -> event.replyWarning("Help cannot be sent because you are blocking Direct Messages."))) - .setDiscordBotsKey(config.getString("listing.discord-bots")) - //.setCarbonitexKey(config.getString("listing.carbon")) .build(); - MessageAction.setDefaultMentions(Arrays.asList(Message.MentionType.EMOTE, Message.MentionType.CHANNEL)); shards = new MultiBotManager.MultiBotManagerBuilder() .addBot(config.getString("pro-token"), Constants.INTENTS) .addBot(config.getString("bot-token"), Constants.INTENTS) .setMemberCachePolicy(MemberCachePolicy.ALL) .enableCache(CacheFlag.MEMBER_OVERRIDES, CacheFlag.VOICE_STATE) - .disableCache(CacheFlag.EMOTE, CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS, CacheFlag.ONLINE_STATUS) + .disableCache(CacheFlag.EMOJI, CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS, CacheFlag.ONLINE_STATUS) .addEventListeners(new Listener(this), client, waiter) .setStatus(OnlineStatus.DO_NOT_DISTURB) .setActivity(Activity.playing("Loading Frye...")) @@ -309,7 +297,6 @@ public void leavePointlessGuilds() { - //shards.getGuilds().stream().filter(g -> shards.getShardManagers().stream().flatMap(s -> s.getGuilds().stream()).filter(g -> { if(!g.isLoaded()) @@ -338,13 +325,8 @@ }); } - - /** - * @param args the command line arguments - * @throws java.lang.Exception - */ public static void main(String[] args) throws Exception { new Vortex(); } -} +} \ No newline at end of file diff --git a/src/main/java/com/jagrosh/vortex/automod/AutoMod.java b/src/main/java/com/jagrosh/vortex/automod/AutoMod.java index 17faaa7..b56dc20 100644 --- a/src/main/java/com/jagrosh/vortex/automod/AutoMod.java +++ b/src/main/java/com/jagrosh/vortex/automod/AutoMod.java @@ -34,6 +34,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.channel.concrete.*; import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.entities.Guild.VerificationLevel; import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent; @@ -63,7 +64,7 @@ private String[] refLinkList; private final URLResolver urlResolver; - private final InviteResolver inviteResolver = new InviteResolver(); + // private final InviteResolver inviteResolver = new InviteResolver(); private final CopypastaResolver copypastaResolver = new CopypastaResolver(); private final FixedCache spams = new FixedCache<>(3000); private final HashMap latestGuildJoin = new HashMap<>(); @@ -172,7 +173,7 @@ { try { - event.getGuild().kick(event.getMember(), "Anti-Raid Mode").queue(); + event.getGuild().kick(event.getMember()).reason("Anti-Raid Mode").queue(); }catch(Exception ignore){} }); } @@ -257,7 +258,7 @@ public void performAutomod(Message message) { //ignore users with Manage Messages, Kick Members, Ban Members, Manage Server, or anyone the bot can't interact with - if(!shouldPerformAutomod(message.getMember(), message.getTextChannel())) + if(!shouldPerformAutomod(message.getMember(), message.getChannel().asTextChannel())) return; //get the settings @@ -266,7 +267,7 @@ return; // check the channel for channel-specific settings - String topic = message.getTextChannel().getTopic(); + String topic = message.getChannel().asTextChannel().getTopic(); boolean preventSpam = topic==null || !topic.toLowerCase().contains("{spam}"); boolean preventInvites = topic==null || !topic.toLowerCase().contains("{invites}"); @@ -287,7 +288,8 @@ } if(preventInvites) { - runAntiInvite(settings, currentStatus, message, inviteWhitelist); + //FIXME!! + //runAntiInvite(settings, currentStatus, message, inviteWhitelist); } runAntiMention(settings, currentStatus, message); runAntiMentionRoles(settings, currentStatus, message); @@ -304,7 +306,7 @@ } // send a short 'warning' message that self-deletes - if(currentStatus.channelWarning != null && message.getGuild().getSelfMember().hasPermission(message.getTextChannel(), Permission.MESSAGE_WRITE)) + if(currentStatus.channelWarning != null && message.getGuild().getSelfMember().hasPermission(message.getChannel().asTextChannel(), Permission.MESSAGE_SEND)) { message.getChannel().sendMessage(message.getAuthor().getAsMention() + Constants.WARNING + " " + currentStatus.channelWarning) .queue(m -> m.delete().queueAfter(2500, TimeUnit.MILLISECONDS, s->{}, f->{}), f->{}); @@ -341,9 +343,11 @@ { String code = resolved.replaceAll(INVITE_LINK, "$1"); LOG.info("Delayed resolving invite in " + message.getGuild().getId() + ": " + code); - long invite = inviteResolver.resolve(code, message.getJDA()); - if(invite != message.getGuild().getIdLong() && !inviteWhitelist.contains(invite)) - containsInvite = true; + // FIXME!!! + // long invite = inviteResolver.resolve(code, message.getJDA()); + // if(invite != message.getGuild().getIdLong() && !inviteWhitelist.contains(invite)) + // containsInvite = true; + containsInvite = false; } if(settings.refStrikes>0) { @@ -411,7 +415,7 @@ { if(settings.maxMentions < AutomodManager.MENTION_MINIMUM) return; - long mentions = message.getMentionedUsers().stream().filter(u -> !u.isBot() && !u.equals(message.getAuthor())).distinct().count(); + long mentions = message.getMentions().getUsers().stream().filter(u -> !u.isBot() && !u.equals(message.getAuthor())).distinct().count(); if(mentions > settings.maxMentions) { currentStatus.addStrikes((int)(mentions - settings.maxMentions)); @@ -424,7 +428,7 @@ { if(settings.maxRoleMentions < AutomodManager.ROLE_MENTION_MINIMUM) return; - long mentions = message.getMentionedRoles().stream().distinct().count(); + long mentions = message.getMentions().getRoles().stream().distinct().count(); if(mentions > settings.maxRoleMentions) { currentStatus.addStrikes((int)(mentions - settings.maxRoleMentions)); @@ -462,40 +466,41 @@ private void runAntiEveryone(AutomodSettings settings, AutomodStatus currentStatus, Message message) { - if(settings.everyoneStrikes <= 0 || message.getMember().hasPermission(message.getTextChannel(), Permission.MESSAGE_MENTION_EVERYONE)) + if(settings.everyoneStrikes <= 0 || message.getMember().hasPermission(message.getChannel().asTextChannel(), Permission.MESSAGE_MENTION_EVERYONE)) return; String filtered = message.getContentRaw().replace("`@everyone`", "").replace("`@here`", ""); if(filtered.contains("@everyone") || filtered.contains("@here") - || message.getMentionedRoles().stream().anyMatch(role -> role.getName().equalsIgnoreCase("everyone") || role.getName().equalsIgnoreCase("here"))) + || message.getMentions().getRoles().stream().anyMatch(role -> role.getName().equalsIgnoreCase("everyone") || role.getName().equalsIgnoreCase("here"))) { currentStatus.addStrikes(settings.everyoneStrikes); currentStatus.appendReason("Attempted @\u0435veryone/here"); // cyrillic e currentStatus.deleteMessage(); } } - - private void runAntiInvite(AutomodSettings settings, AutomodStatus currentStatus, Message message, List inviteWhitelist) - { - if(settings.inviteStrikes <= 0) - return; - List invites = new ArrayList<>(); - Matcher m = INVITES.matcher(message.getContentRaw()); - while(m.find()) - invites.add(m.group(1)); - LOG.trace("Found "+invites.size()+" invites."); - for(String inviteCode : invites) - { - long gid = inviteResolver.resolve(inviteCode, message.getJDA()); - LOG.info("Resolving invite in " + message.getGuild().getId() + ": " + inviteCode + " -> " + gid); - if(gid != message.getGuild().getIdLong() && !inviteWhitelist.contains(gid)) - { - currentStatus.addStrikes(settings.inviteStrikes); - currentStatus.appendReason("Advertising"); - currentStatus.deleteMessage(); - break; - } - } - } + + // FIXME!!! + // private void runAntiInvite(AutomodSettings settings, AutomodStatus currentStatus, Message message, List inviteWhitelist) + // { + // if(settings.inviteStrikes <= 0) + // return; + // List invites = new ArrayList<>(); + // Matcher m = INVITES.matcher(message.getContentRaw()); + // while(m.find()) + // invites.add(m.group(1)); + // LOG.trace("Found "+invites.size()+" invites."); + // for(String inviteCode : invites) + // { + // long gid = inviteResolver.resolve(inviteCode, message.getJDA()); + // LOG.info("Resolving invite in " + message.getGuild().getId() + ": " + inviteCode + " -> " + gid); + // if(gid != message.getGuild().getIdLong() && !inviteWhitelist.contains(gid)) + // { + // currentStatus.addStrikes(settings.inviteStrikes); + // currentStatus.appendReason("Advertising"); + // currentStatus.deleteMessage(); + // break; + // } + // } + // } private void runAntiReferral(AutomodSettings settings, AutomodStatus currentStatus, Message message) { diff --git a/src/main/java/com/jagrosh/vortex/automod/InviteResolver.java b/src/main/java/com/jagrosh/vortex/automod/InviteResolver.java deleted file mode 100644 index 755cd5a..0000000 --- a/src/main/java/com/jagrosh/vortex/automod/InviteResolver.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright 2018 John Grosh (john.a.grosh@gmail.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.jagrosh.vortex.automod; - -import com.jagrosh.vortex.utils.FixedCache; -import java.io.IOException; -import java.time.OffsetDateTime; -import java.util.Collections; -import net.dv8tion.jda.api.JDA; -import net.dv8tion.jda.api.entities.ChannelType; -import net.dv8tion.jda.api.entities.Guild; -import net.dv8tion.jda.api.entities.Invite; -import net.dv8tion.jda.api.utils.MiscUtil; -import net.dv8tion.jda.internal.entities.InviteImpl; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; -import org.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * - * @author John Grosh (john.a.grosh@gmail.com) - */ -public class InviteResolver -{ - private final static String[] BASE_URLS = {"discordapp.com", "ptb.discordapp.com", "canary.discordapp.com", - /*"discord.com",*/ "ptb.discord.com", "canary.discord.com", "discord.co", "watchanimeattheoffice.com", "discord.new"}; - private final Logger log = LoggerFactory.getLogger(InviteResolver.class); - private final FixedCache cached = new FixedCache<>(5000); - private final OkHttpClient client = new OkHttpClient.Builder().build(); - - public Invite resolveFull(String code, JDA jda) - { - return resolveFull(code, jda.getToken()); - } - - public Invite resolveFull(String code, String token) - { - log.debug("Attempting to resolve " + code); - try - { - return getInvite(code, token); - } - catch(Exception ex) - { - return null; - } - } - - public long resolve(String code, JDA jda) - { - return resolve(code, jda.getToken()); - } - - public long resolve(String code, String token) - { - log.debug("Attempting to resolve " + code); - if(cached.contains(code)) - return cached.get(code); - try - { - long guildId = getInviteGuild(code, token); - //long guildId = Invite.resolve(jda, code).complete(false).getGuild().getIdLong(); - cached.put(code, guildId); - return guildId; - } - catch(Exception ex) - { - cached.put(code, 0L); - return 0L; - } - } - - private long getInviteGuild(String code, String token) throws IOException - { - JSONObject json = getInviteJSON(code, token); - if(json != null) - return MiscUtil.parseSnowflake(json.getJSONObject("guild").getString("id")); - return 0L; - } - - private InviteImpl getInvite(String code, String token) throws IOException - { - JSONObject json = getInviteJSON(code, token); - if(json != null) - { - Invite.Channel channel; - if(json.has("channel")) - { - JSONObject c = json.getJSONObject("channel"); - channel = new InviteImpl.ChannelImpl(c.optLong("id"), c.optString("name"), c.optInt("type") == 0 ? ChannelType.TEXT : ChannelType.UNKNOWN); - } - else - channel = null; - Invite.Guild guild; - if(json.has("guild")) - { - JSONObject g = json.getJSONObject("guild"); - guild = new InviteImpl.GuildImpl(g.optLong("id"), g.optString("icon"), g.optString("name"), g.optString("splash"), Guild.VerificationLevel.UNKNOWN, -1, -1, Collections.emptySet()); - } - else - guild = null; - return new InviteImpl(null, code, false, null, 0, 0, false, OffsetDateTime.now(), 0, channel, guild, null, null, Invite.InviteType.GUILD); - } - return null; - } - - private JSONObject getInviteJSON(String code, String token) throws IOException - { - Response res = client.newCall(new Request.Builder().get() - .addHeader("Authorization", token) - .addHeader("User-Agent", "DiscordBot (FryeInviteResolverBasedOnVortex, 1.0)") - .url("https://" + rand(BASE_URLS) + "/api/invites/" + code) - .build()).execute(); - if(res.isSuccessful()) - { - return new JSONObject(res.body().string()); - } - - // if it failed, log why (usually unknown invite or cloudflare issue) - try - { - String message = new JSONObject(res.body().string()).getString("message"); - log.warn(String.format("Unsuccessful resolving '%s': %s", code, message)); - } - catch(Exception ex) - { - log.warn(String.format("Unsuccessful resolving '%s' | Headers: %s | Body: %s", code, - res.headers().toMultimap().toString(), res.body() == null ? null : res.body().string())); - } - return null; - } - - private T rand(T[] items) - { - return items[(int)(Math.random() * items.length)]; - } -} diff --git a/src/main/java/com/jagrosh/vortex/automod/InviteResolver.java.no b/src/main/java/com/jagrosh/vortex/automod/InviteResolver.java.no new file mode 100644 index 0000000..91d3555 --- /dev/null +++ b/src/main/java/com/jagrosh/vortex/automod/InviteResolver.java.no @@ -0,0 +1,153 @@ +/* + * Copyright 2018 John Grosh (john.a.grosh@gmail.com). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jagrosh.vortex.automod; + +import com.jagrosh.vortex.utils.FixedCache; +import java.io.IOException; +import java.time.OffsetDateTime; +import java.util.Collections; +import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.entities.channel.ChannelType; +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.Invite; +import net.dv8tion.jda.api.utils.MiscUtil; +import net.dv8tion.jda.internal.entities.InviteImpl; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author John Grosh (john.a.grosh@gmail.com) + */ +public class InviteResolver +{ + private final static String[] BASE_URLS = {"discordapp.com", "ptb.discordapp.com", "canary.discordapp.com", + /*"discord.com",*/ "ptb.discord.com", "canary.discord.com", "discord.co", "watchanimeattheoffice.com", "discord.new"}; + private final Logger log = LoggerFactory.getLogger(InviteResolver.class); + private final FixedCache cached = new FixedCache<>(5000); + private final OkHttpClient client = new OkHttpClient.Builder().build(); + + public Invite resolveFull(String code, JDA jda) + { + return resolveFull(code, jda.getToken()); + } + + public Invite resolveFull(String code, String token) + { + log.debug("Attempting to resolve " + code); + try + { + return getInvite(code, token); + } + catch(Exception ex) + { + return null; + } + } + + public long resolve(String code, JDA jda) + { + return resolve(code, jda.getToken()); + } + + public long resolve(String code, String token) + { + log.debug("Attempting to resolve " + code); + if(cached.contains(code)) + return cached.get(code); + try + { + long guildId = getInviteGuild(code, token); + //long guildId = Invite.resolve(jda, code).complete(false).getGuild().getIdLong(); + cached.put(code, guildId); + return guildId; + } + catch(Exception ex) + { + cached.put(code, 0L); + return 0L; + } + } + + private long getInviteGuild(String code, String token) throws IOException + { + JSONObject json = getInviteJSON(code, token); + if(json != null) + return MiscUtil.parseSnowflake(json.getJSONObject("guild").getString("id")); + return 0L; + } + + private InviteImpl getInvite(String code, String token) throws IOException + { + JSONObject json = getInviteJSON(code, token); + if(json != null) + { + Invite.Channel channel; + if(json.has("channel")) + { + JSONObject c = json.getJSONObject("channel"); + channel = new InviteImpl.ChannelImpl(c.optLong("id"), c.optString("name"), c.optInt("type") == 0 ? ChannelType.TEXT : ChannelType.UNKNOWN); + } + else + channel = null; + Invite.Guild guild; + if(json.has("guild")) + { + JSONObject g = json.getJSONObject("guild"); + guild = new InviteImpl.GuildImpl(g.optLong("id"), g.optString("icon"), g.optString("name"), g.optString("splash"), Guild.VerificationLevel.UNKNOWN, -1, -1, Collections.emptySet()); + } + else + guild = null; + return new InviteImpl(null, code, false, null, 0, 0, false, OffsetDateTime.now(), 0, channel, guild, null, null, Invite.InviteType.GUILD); + } + return null; + } + + private JSONObject getInviteJSON(String code, String token) throws IOException + { + Response res = client.newCall(new Request.Builder().get() + .addHeader("Authorization", token) + .addHeader("User-Agent", "DiscordBot (FryeInviteResolverBasedOnVortex, 1.0)") + .url("https://" + rand(BASE_URLS) + "/api/invites/" + code) + .build()).execute(); + if(res.isSuccessful()) + { + return new JSONObject(res.body().string()); + } + + // if it failed, log why (usually unknown invite or cloudflare issue) + try + { + String message = new JSONObject(res.body().string()).getString("message"); + log.warn(String.format("Unsuccessful resolving '%s': %s", code, message)); + } + catch(Exception ex) + { + log.warn(String.format("Unsuccessful resolving '%s' | Headers: %s | Body: %s", code, + res.headers().toMultimap().toString(), res.body() == null ? null : res.body().string())); + } + return null; + } + + private T rand(T[] items) + { + return items[(int)(Math.random() * items.length)]; + } +} diff --git a/src/main/java/com/jagrosh/vortex/automod/StrikeHandler.java b/src/main/java/com/jagrosh/vortex/automod/StrikeHandler.java index 713a338..85651a2 100644 --- a/src/main/java/com/jagrosh/vortex/automod/StrikeHandler.java +++ b/src/main/java/com/jagrosh/vortex/automod/StrikeHandler.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -32,6 +32,7 @@ import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.UserSnowflake; /** * @@ -89,14 +90,14 @@ if(punishments.stream().anyMatch(p -> p.action==Action.BAN) && canBan) { OtherUtil.safeDM(target, dmmsg + punish(Action.BAN, moderator.getGuild()), isMember, - () -> moderator.getGuild().ban(target, 7, notimeaudit).queue()); + () -> moderator.getGuild().ban(UserSnowflake.fromId(target.getIdLong()), 7, TimeUnit.DAYS).reason(notimeaudit).queue()); vortex.getDatabase().tempbans.clearBan(moderator.getGuild(), target.getIdLong()); return; } if(punishments.stream().anyMatch(p -> p.action==Action.SILENTBAN) && canBan) { OtherUtil.safeDM(target, dmmsg + punish(Action.SILENTBAN, moderator.getGuild()), isMember, - () -> moderator.getGuild().ban(target, 0, notimeaudit).queue()); + () -> moderator.getGuild().ban(UserSnowflake.fromId(target.getIdLong()), 0, TimeUnit.DAYS).reason(notimeaudit).queue()); vortex.getDatabase().tempbans.clearBan(moderator.getGuild(), target.getIdLong()); return; } @@ -115,7 +116,7 @@ { int finalBanDuration = banDuration; OtherUtil.safeDM(target, dmmsg + punishTime(Action.TEMPBAN, moderator.getGuild(), banDuration), isMember, - () -> moderator.getGuild().ban(target, 7, LogUtil.auditStrikeReasonFormat(moderator, finalBanDuration, counts[0], counts[1], reason)).queue()); + () -> moderator.getGuild().ban(UserSnowflake.fromId(target.getIdLong()), 7, TimeUnit.DAYS).reason(LogUtil.auditStrikeReasonFormat(moderator, finalBanDuration, counts[0], counts[1], reason)).queue()); vortex.getDatabase().tempbans.setBan(moderator.getGuild(), target.getIdLong(), now.plus(banDuration, ChronoUnit.MINUTES)); if(muteDuration>0) vortex.getDatabase().tempmutes.setMute(moderator.getGuild(), target.getIdLong(), muteTime(now, muteDuration)); @@ -124,8 +125,8 @@ if(punishments.stream().anyMatch(p -> p.action==Action.SOFTBAN) && canBan) { OtherUtil.safeDM(target, dmmsg + punish(Action.SOFTBAN, moderator.getGuild()), isMember, - () -> moderator.getGuild().ban(target, 7, notimeaudit).queue( - s -> moderator.getGuild().unban(target).reason(notimeaudit).queueAfter(4, TimeUnit.SECONDS))); + () -> moderator.getGuild().ban(UserSnowflake.fromId(target.getIdLong()), 7, TimeUnit.DAYS).reason(notimeaudit).queue( + s -> moderator.getGuild().unban(UserSnowflake.fromId(target.getIdLong())).reason(notimeaudit).queueAfter(4, TimeUnit.SECONDS))); if(muteDuration>0) vortex.getDatabase().tempmutes.setMute(moderator.getGuild(), target.getIdLong(), muteTime(now, muteDuration)); return; @@ -136,7 +137,7 @@ if(moderator.getGuild().isMember(target)) { OtherUtil.safeDM(target, dmmsg + punish(Action.KICK, moderator.getGuild()), isMember, - () -> moderator.getGuild().kick(target.getId(), notimeaudit).queue()); + () -> moderator.getGuild().kick(target).reason(notimeaudit).queue()); } else { @@ -190,4 +191,4 @@ { return minutes==Integer.MAX_VALUE ? Instant.MAX : now.plus(minutes, ChronoUnit.MINUTES); } -} +} \ No newline at end of file diff --git a/src/main/java/com/jagrosh/vortex/commands/CommandExceptionListener.java b/src/main/java/com/jagrosh/vortex/commands/CommandExceptionListener.java index df70ce0..5493f46 100644 --- a/src/main/java/com/jagrosh/vortex/commands/CommandExceptionListener.java +++ b/src/main/java/com/jagrosh/vortex/commands/CommandExceptionListener.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,7 +20,7 @@ import com.jagrosh.jdautilities.command.CommandListener; import com.jagrosh.vortex.utils.FormatUtil; import com.jagrosh.vortex.utils.Usage; -import net.dv8tion.jda.api.entities.ChannelType; +import net.dv8tion.jda.api.entities.channel.ChannelType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -71,4 +71,4 @@ { return usage; } -} +} \ No newline at end of file diff --git a/src/main/java/com/jagrosh/vortex/commands/LogCommand.java b/src/main/java/com/jagrosh/vortex/commands/LogCommand.java index 13942da..f467a2f 100644 --- a/src/main/java/com/jagrosh/vortex/commands/LogCommand.java +++ b/src/main/java/com/jagrosh/vortex/commands/LogCommand.java @@ -22,7 +22,7 @@ import com.jagrosh.vortex.utils.FormatUtil; import java.util.List; import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; /** * @@ -30,7 +30,7 @@ */ public abstract class LogCommand extends Command { - public static Permission[] REQUIRED_PERMS = {Permission.MESSAGE_READ, Permission.MESSAGE_WRITE, Permission.MESSAGE_EMBED_LINKS, Permission.MESSAGE_HISTORY}; + public static Permission[] REQUIRED_PERMS = {Permission.VIEW_CHANNEL, Permission.MESSAGE_SEND, Permission.MESSAGE_EMBED_LINKS, Permission.MESSAGE_HISTORY}; public static String REQUIRED_ERROR = "I am missing the necessary permissions (Read Messages, Send Messages, Read Message History, and Embed Links) in %s!"; protected final Vortex vortex; diff --git a/src/main/java/com/jagrosh/vortex/commands/ModCommand.java b/src/main/java/com/jagrosh/vortex/commands/ModCommand.java index b17b69b..700ecaf 100644 --- a/src/main/java/com/jagrosh/vortex/commands/ModCommand.java +++ b/src/main/java/com/jagrosh/vortex/commands/ModCommand.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,7 +19,7 @@ import com.jagrosh.vortex.Constants; import com.jagrosh.vortex.Vortex; import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.ChannelType; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.Role; /** @@ -36,7 +36,7 @@ this.guildOnly = true; this.category = new Category("Moderation", event -> { - if(event.getChannelType() != ChannelType.TEXT) + if(!event.getChannelType().isMessage()) { event.replyError("This command is not available in Direct Messages!"); return false; @@ -48,10 +48,17 @@ boolean missingPerms = false; for(Permission altPerm: altPerms) { - if(altPerm.isText()) + if(altPerm.isChannel()) { - if(!event.getMember().hasPermission(event.getTextChannel(), altPerm)) + if(event.getChannel() instanceof TextChannel) + { + if(!event.getMember().hasPermission((TextChannel) event.getChannel(), altPerm)) + missingPerms = true; + } + else + { missingPerms = true; + } } else { @@ -62,7 +69,7 @@ if(!missingPerms) return true; if(event.getMember().getRoles().isEmpty()) - event.getMessage().addReaction(Constants.ERROR_REACTION).queue(); + event.getMessage().addReaction(net.dv8tion.jda.api.entities.emoji.Emoji.fromFormatted(Constants.ERROR_REACTION)).queue(); else event.replyError("You must have the following permissions to use that: "+listPerms(altPerms)); return false; @@ -78,4 +85,4 @@ sb.append(", ").append(perms[i].getName()); return sb.toString(); } -} +} \ No newline at end of file diff --git a/src/main/java/com/jagrosh/vortex/commands/automod/IgnoreCmd.java b/src/main/java/com/jagrosh/vortex/commands/automod/IgnoreCmd.java index 8f660e6..6961fef 100644 --- a/src/main/java/com/jagrosh/vortex/commands/automod/IgnoreCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/automod/IgnoreCmd.java @@ -12,7 +12,7 @@ import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Role; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import com.jagrosh.vortex.Vortex; import com.jagrosh.vortex.utils.FormatUtil; diff --git a/src/main/java/com/jagrosh/vortex/commands/automod/UnignoreCmd.java b/src/main/java/com/jagrosh/vortex/commands/automod/UnignoreCmd.java index e8352be..3f7887a 100644 --- a/src/main/java/com/jagrosh/vortex/commands/automod/UnignoreCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/automod/UnignoreCmd.java @@ -22,7 +22,7 @@ import java.util.List; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Role; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import com.jagrosh.vortex.utils.FormatUtil; /** diff --git a/src/main/java/com/jagrosh/vortex/commands/general/AboutCmd.java b/src/main/java/com/jagrosh/vortex/commands/general/AboutCmd.java index 5d7c8b5..7a7b199 100644 --- a/src/main/java/com/jagrosh/vortex/commands/general/AboutCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/general/AboutCmd.java @@ -23,9 +23,9 @@ import java.awt.Color; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.JDAInfo; -import net.dv8tion.jda.api.MessageBuilder; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.ChannelType; +import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.sharding.ShardManager; /** @@ -46,9 +46,9 @@ protected void execute(CommandEvent event) { ShardManager sm = event.getJDA().getShardManager(); - event.reply(new MessageBuilder() + event.reply(new MessageCreateBuilder() .setContent(Constants.VORTEX_EMOJI + " **All about Frye** " + Constants.VORTEX_EMOJI) - .setEmbed(new EmbedBuilder() + .setEmbeds(new EmbedBuilder() .setColor(!event.isFromType(ChannelType.TEXT) ? Color.GRAY : event.getSelfMember().getColor()) .setDescription("Hello, I am **Frye**#7106, a bot designed to keep your server safe and make moderating fast and easy!\n" + "I was written in Java by **ssdrive** using [JDA](" + JDAInfo.GITHUB + ") and [JDA-Utilities](" + JDAUtilitiesInfo.GITHUB + ")\n" diff --git a/src/main/java/com/jagrosh/vortex/commands/general/AirstrikeCmd.java b/src/main/java/com/jagrosh/vortex/commands/general/AirstrikeCmd.java deleted file mode 100644 index adaa772..0000000 --- a/src/main/java/com/jagrosh/vortex/commands/general/AirstrikeCmd.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2018 John Grosh (john.a.grosh@gmail.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.jagrosh.vortex.commands.general; - -import com.jagrosh.jdautilities.command.Command; -import com.jagrosh.jdautilities.command.CommandEvent; -import com.jagrosh.jdautilities.commons.JDAUtilitiesInfo; -import com.jagrosh.vortex.Constants; -import com.jagrosh.vortex.utils.FormatUtil; -import java.awt.Color; -import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.JDAInfo; -import net.dv8tion.jda.api.MessageBuilder; -import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.ChannelType; -import net.dv8tion.jda.api.sharding.ShardManager; -import net.dv8tion.jda.api.entities.User; - -/** - * - * @author John Grosh (john.a.grosh@gmail.com) - */ -public class AirstrikeCmd extends Command -{ - public AirstrikeCmd() - { - this.name = "airstrike"; - this.help = "airstrike a user"; - this.guildOnly = false; - this.botPermissions = new Permission[]{Permission.MESSAGE_EMBED_LINKS}; - } - - @Override - protected void execute(CommandEvent event) - { - if (event.getArgs().isEmpty()) { - event.replyError("Please mention a user to airstrike!"); - return; - } - - // Try to resolve a user from args - User target = event.getMessage().getMentionedUsers().stream().findFirst().orElse(null); - if (target == null) { - event.replyError("Could not find a mentioned user!"); - return; - } - - // Build the response - event.reply(new MessageBuilder() - .setContent(Constants.VORTEX_EMOJI + " **Airstrike** " + Constants.VORTEX_EMOJI) - .setEmbed(new EmbedBuilder() - .setColor(!event.isFromType(ChannelType.TEXT) ? Color.GRAY : event.getSelfMember().getColor()) - .setDescription(target.getAsMention() + " has been airstriked.") - .build()) - .build()); - } -} diff --git a/src/main/java/com/jagrosh/vortex/commands/general/AssassinateCmd.java b/src/main/java/com/jagrosh/vortex/commands/general/AssassinateCmd.java deleted file mode 100644 index 72f9b93..0000000 --- a/src/main/java/com/jagrosh/vortex/commands/general/AssassinateCmd.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2018 John Grosh (john.a.grosh@gmail.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.jagrosh.vortex.commands.general; - -import com.jagrosh.jdautilities.command.Command; -import com.jagrosh.jdautilities.command.CommandEvent; -import com.jagrosh.jdautilities.commons.JDAUtilitiesInfo; -import com.jagrosh.vortex.Constants; -import com.jagrosh.vortex.utils.FormatUtil; -import java.awt.Color; -import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.JDAInfo; -import net.dv8tion.jda.api.MessageBuilder; -import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.ChannelType; -import net.dv8tion.jda.api.sharding.ShardManager; -import net.dv8tion.jda.api.entities.User; - -/** - * - * @author John Grosh (john.a.grosh@gmail.com) - */ -public class AssassinateCmd extends Command -{ - public AssassinateCmd() - { - this.name = "assassinate"; - this.help = "Assassinate a user"; - this.guildOnly = false; - this.botPermissions = new Permission[]{Permission.MESSAGE_EMBED_LINKS}; - } - - @Override - protected void execute(CommandEvent event) - { - if (event.getArgs().isEmpty()) { - event.replyError("Please mention a user to assassinate!"); - return; - } - - // Try to resolve a user from args - User target = event.getMessage().getMentionedUsers().stream().findFirst().orElse(null); - if (target == null) { - event.replyError("Could not find a mentioned user!"); - return; - } - - // Build the response - event.reply(new MessageBuilder() - .setContent(Constants.VORTEX_EMOJI + " **Donald Trump Moment** " + Constants.VORTEX_EMOJI) - .setEmbed(new EmbedBuilder() - .setColor(!event.isFromType(ChannelType.TEXT) ? Color.GRAY : event.getSelfMember().getColor()) - .setDescription(target.getAsMention() + " was assassinated. :gun:") - .build()) - .build()); - } -} diff --git a/src/main/java/com/jagrosh/vortex/commands/general/BombCmd.java b/src/main/java/com/jagrosh/vortex/commands/general/BombCmd.java deleted file mode 100644 index c9583d9..0000000 --- a/src/main/java/com/jagrosh/vortex/commands/general/BombCmd.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2018 John Grosh (john.a.grosh@gmail.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.jagrosh.vortex.commands.general; - -import com.jagrosh.jdautilities.command.Command; -import com.jagrosh.jdautilities.command.CommandEvent; -import com.jagrosh.jdautilities.commons.JDAUtilitiesInfo; -import com.jagrosh.vortex.Constants; -import com.jagrosh.vortex.utils.FormatUtil; -import java.awt.Color; -import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.JDAInfo; -import net.dv8tion.jda.api.MessageBuilder; -import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.ChannelType; -import net.dv8tion.jda.api.sharding.ShardManager; -import net.dv8tion.jda.api.entities.User; - -/** - * - * @author John Grosh (john.a.grosh@gmail.com) - */ -public class BombCmd extends Command -{ - public BombCmd() - { - this.name = "bomb"; - this.help = "Bomb a user"; - this.guildOnly = false; - this.botPermissions = new Permission[]{Permission.MESSAGE_EMBED_LINKS}; - } - - @Override - protected void execute(CommandEvent event) - { - if (event.getArgs().isEmpty()) { - event.replyError("Please mention a user to bomb!"); - return; - } - - // Try to resolve a user from args - User target = event.getMessage().getMentionedUsers().stream().findFirst().orElse(null); - if (target == null) { - event.replyError("Could not find a mentioned user!"); - return; - } - - // Build the response - event.reply(new MessageBuilder() - .setContent(Constants.VORTEX_EMOJI + " **Bomb** " + Constants.VORTEX_EMOJI) - .setEmbed(new EmbedBuilder() - .setColor(!event.isFromType(ChannelType.TEXT) ? Color.GRAY : event.getSelfMember().getColor()) - .setDescription(target.getAsMention() + " was bombed. :bomb:") - .build()) - .build()); - } -} diff --git a/src/main/java/com/jagrosh/vortex/commands/general/FillCmd.java b/src/main/java/com/jagrosh/vortex/commands/general/FillCmd.java deleted file mode 100644 index e7ce55b..0000000 --- a/src/main/java/com/jagrosh/vortex/commands/general/FillCmd.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2018 John Grosh (john.a.grosh@gmail.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.jagrosh.vortex.commands.general; - -import com.jagrosh.jdautilities.command.Command; -import com.jagrosh.jdautilities.command.CommandEvent; -import com.jagrosh.jdautilities.commons.JDAUtilitiesInfo; -import com.jagrosh.vortex.Constants; -import com.jagrosh.vortex.utils.FormatUtil; -import java.awt.Color; -import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.JDAInfo; -import net.dv8tion.jda.api.MessageBuilder; -import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.ChannelType; -import net.dv8tion.jda.api.sharding.ShardManager; -import net.dv8tion.jda.api.entities.User; - -/** - * - * @author John Grosh (john.a.grosh@gmail.com) - */ -public class FillCmd extends Command -{ - public FillCmd() - { - this.name = "fill"; - this.help = "fill a user"; - this.guildOnly = false; - this.botPermissions = new Permission[]{Permission.MESSAGE_EMBED_LINKS}; - } - - @Override - protected void execute(CommandEvent event) - { - if (event.getArgs().isEmpty()) { - event.replyError("Please mention a user to fill."); - return; - } - - // Try to resolve a user from args - User target = event.getMessage().getMentionedUsers().stream().findFirst().orElse(null); - if (target == null) { - event.replyError("Could not find a mentioned user!"); - return; - } - - // Build the response - event.reply(new MessageBuilder() - .setContent(target.getAsMention() + " was filled with love!") - // .setEmbed(new EmbedBuilder() - // .setColor(!event.isFromType(ChannelType.TEXT) ? Color.GRAY : event.getSelfMember().getColor()) - // .setDescription(target.getAsMention() + " was filled. :blush:") - // .build()) - .build()); - } -} diff --git a/src/main/java/com/jagrosh/vortex/commands/general/FuckCmd.java b/src/main/java/com/jagrosh/vortex/commands/general/FuckCmd.java deleted file mode 100644 index 048c745..0000000 --- a/src/main/java/com/jagrosh/vortex/commands/general/FuckCmd.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2018 John Grosh (john.a.grosh@gmail.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.jagrosh.vortex.commands.general; - -import com.jagrosh.jdautilities.command.Command; -import com.jagrosh.jdautilities.command.CommandEvent; -import com.jagrosh.jdautilities.commons.JDAUtilitiesInfo; -import com.jagrosh.vortex.Constants; -import com.jagrosh.vortex.utils.FormatUtil; -import java.awt.Color; -import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.JDAInfo; -import net.dv8tion.jda.api.MessageBuilder; -import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.ChannelType; -import net.dv8tion.jda.api.sharding.ShardManager; -import net.dv8tion.jda.api.entities.User; - -/** - * - * @author John Grosh (john.a.grosh@gmail.com) - */ -public class FuckCmd extends Command -{ - public FuckCmd() - { - this.name = "fuck"; - this.help = "fuck a user"; - this.guildOnly = false; - this.botPermissions = new Permission[]{Permission.MESSAGE_EMBED_LINKS}; - } - - @Override - protected void execute(CommandEvent event) - { - if (event.getArgs().isEmpty()) { - event.replyError("Please mention a user to... well... y'know."); - return; - } - - // Try to resolve a user from args - User target = event.getMessage().getMentionedUsers().stream().findFirst().orElse(null); - if (target == null) { - event.replyError("Could not find a mentioned user!"); - return; - } - - // Build the response - event.reply(new MessageBuilder() - .setContent(target.getAsMention() + " was, uhh... :flushed:, yk.") - // .setEmbed(new EmbedBuilder() - // .setColor(!event.isFromType(ChannelType.TEXT) ? Color.GRAY : event.getSelfMember().getColor()) - // .setDescription(target.getAsMention() + " was fucked. :blush:") - // .build()) - .build()); - } -} diff --git a/src/main/java/com/jagrosh/vortex/commands/general/MolestCmd.java b/src/main/java/com/jagrosh/vortex/commands/general/MolestCmd.java deleted file mode 100644 index 752ed5f..0000000 --- a/src/main/java/com/jagrosh/vortex/commands/general/MolestCmd.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2018 John Grosh (john.a.grosh@gmail.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.jagrosh.vortex.commands.general; - -import com.jagrosh.jdautilities.command.Command; -import com.jagrosh.jdautilities.command.CommandEvent; -import com.jagrosh.jdautilities.commons.JDAUtilitiesInfo; -import com.jagrosh.vortex.Constants; -import com.jagrosh.vortex.utils.FormatUtil; -import java.awt.Color; -import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.JDAInfo; -import net.dv8tion.jda.api.MessageBuilder; -import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.ChannelType; -import net.dv8tion.jda.api.sharding.ShardManager; -import net.dv8tion.jda.api.entities.User; - -/** - * - * @author John Grosh (john.a.grosh@gmail.com) - */ -public class MolestCmd extends Command -{ - public MolestCmd() - { - this.name = "molest"; - this.help = "molest a user"; - this.guildOnly = false; - this.botPermissions = new Permission[]{Permission.MESSAGE_EMBED_LINKS}; - } - - @Override - protected void execute(CommandEvent event) - { - if (event.getArgs().isEmpty()) { - event.replyError("Please mention a user to molest!"); - return; - } - - // Try to resolve a user from args - User target = event.getMessage().getMentionedUsers().stream().findFirst().orElse(null); - if (target == null) { - event.replyError("Could not find a mentioned user!"); - return; - } - - // Build the response - event.reply(new MessageBuilder() - .setContent(target.getAsMention() + " has been molested. Yummy! :yum:") - // .setEmbed(new EmbedBuilder() - // .setColor(!event.isFromType(ChannelType.TEXT) ? Color.GRAY : event.getSelfMember().getColor()) - // .setDescription(target.getAsMention() + " has been molested. Yummy! :yummy:") - // .build()) - .build()); - } -} diff --git a/src/main/java/com/jagrosh/vortex/commands/general/RoleinfoCmd.java b/src/main/java/com/jagrosh/vortex/commands/general/RoleinfoCmd.java index 63366a1..13da94b 100644 --- a/src/main/java/com/jagrosh/vortex/commands/general/RoleinfoCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/general/RoleinfoCmd.java @@ -23,7 +23,7 @@ import com.jagrosh.vortex.utils.FormatUtil; import java.util.List; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.MessageBuilder; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Role; @@ -90,9 +90,9 @@ if(list.size()*24<=2048-desr.length()) list.forEach(m -> desr.append("<@").append(m.getUser().getId()).append("> ")); - event.reply(new MessageBuilder() - .append(FormatUtil.filterEveryone(title)) - .setEmbed(new EmbedBuilder() + event.reply(new MessageCreateBuilder() + .addContent(FormatUtil.filterEveryone(title)) + .setEmbeds(new EmbedBuilder() .setDescription(desr.toString().trim()) .setColor(role.getColor()).build()) .build()); diff --git a/src/main/java/com/jagrosh/vortex/commands/general/ServerinfoCmd.java b/src/main/java/com/jagrosh/vortex/commands/general/ServerinfoCmd.java index d015c14..e5e6222 100644 --- a/src/main/java/com/jagrosh/vortex/commands/general/ServerinfoCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/general/ServerinfoCmd.java @@ -1,18 +1,3 @@ -/* - * Copyright 2022 John Grosh (john.a.grosh@gmail.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package com.jagrosh.vortex.commands.general; import com.jagrosh.jdautilities.command.Command; @@ -21,16 +6,12 @@ import net.dv8tion.jda.api.*; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; -/** - * - * @author John Grosh (john.a.grosh@gmail.com) - */ -public class ServerinfoCmd extends Command +public class ServerinfoCmd extends Command { - private final static String LINESTART = "\u25AB"; // â–« - private final static String GUILD_EMOJI = "\uD83D\uDDA5"; // 🖥 - private final static String NO_REGION = "\u2754"; // â�” + private final static String LINESTART = "\u25AB"; + private final static String GUILD_EMOJI = "\uD83D\uDDA5"; public ServerinfoCmd() { @@ -46,35 +27,33 @@ { Guild guild = event.getGuild(); Member owner = guild.getOwner(); - long onlineCount = guild.getMembers().stream().filter(u -> u.getOnlineStatus() != OnlineStatus.OFFLINE).count(); - long botCount = guild.getMembers().stream().filter(m -> m.getUser().isBot()).count(); + + // Note: Presence/Online status requires GUILD_PRESENCES intent + long onlineCount = guild.getMemberCache().stream().filter(u -> u.getOnlineStatus() != OnlineStatus.OFFLINE).count(); + long botCount = guild.getMemberCache().stream().filter(m -> m.getUser().isBot()).count(); + EmbedBuilder builder = new EmbedBuilder(); String title = (GUILD_EMOJI + " Information about **" + guild.getName() + "**:") - .replace("@everyone", "@\u0435veryone") // cyrillic e - .replace("@here", "@h\u0435re") // cyrillic e - .replace("discord.gg/", "dis\u0441ord.gg/"); // cyrillic c; + .replace("@everyone", "@\u0435veryone") + .replace("@here", "@h\u0435re") + .replace("discord.gg/", "dis\u0441ord.gg/"); + String str = LINESTART + "ID: **" + guild.getId() + "**\n" - + LINESTART + "Owner: " + (owner == null ? "Unknown" : "**" + owner.getUser().getName() + "**") + "\n"; - if(!guild.getVoiceChannels().isEmpty()) - { - Region reg = guild.getVoiceChannels().get(0).getRegion(); - str += LINESTART + "Location: " + (reg.getEmoji() == null || reg.getEmoji().isEmpty() ? NO_REGION : reg.getEmoji()) + " **" + reg.getName() + "**\n"; - } - str += LINESTART + "Creation: **" + guild.getTimeCreated().format(DateTimeFormatter.RFC_1123_DATE_TIME) + "**\n" - + LINESTART + "Users: **" + guild.getMemberCache().size() + "** (" + onlineCount + " online, " + botCount + " bots)\n" + + LINESTART + "Owner: " + (owner == null ? "Unknown" : "**" + owner.getUser().getName() + "**") + "\n" + + LINESTART + "Creation: **" + guild.getTimeCreated().format(DateTimeFormatter.RFC_1123_DATE_TIME) + "**\n" + + LINESTART + "Users: **" + guild.getMemberCount() + "** (" + onlineCount + " online, " + botCount + " bots)\n" + LINESTART + "Channels: **" + guild.getTextChannelCache().size() + "** Text, **" + guild.getVoiceChannelCache().size() + "** Voice, **" + guild.getCategoryCache().size() + "** Categories\n" + LINESTART + "Verification: **" + guild.getVerificationLevel().name() + "**"; + if(!guild.getFeatures().isEmpty()) str += "\n" + LINESTART + "Features: **" + String.join("**, **", guild.getFeatures()) + "**"; - if(guild.getSplashId() != null) - { - builder.setImage(guild.getSplashUrl() + "?size=1024"); - str += "\n" + LINESTART + "Splash: "; - } - if(guild.getIconUrl()!=null) + + if(guild.getIconUrl() != null) builder.setThumbnail(guild.getIconUrl()); + builder.setColor(owner == null ? null : owner.getColor()); builder.setDescription(str); - event.reply(new MessageBuilder().append(title).setEmbed(builder.build()).build()); + + event.reply(new MessageCreateBuilder().addContent(title).setEmbeds(builder.build()).build()); } } \ No newline at end of file diff --git a/src/main/java/com/jagrosh/vortex/commands/general/TouchCmd.java b/src/main/java/com/jagrosh/vortex/commands/general/TouchCmd.java deleted file mode 100644 index 224737f..0000000 --- a/src/main/java/com/jagrosh/vortex/commands/general/TouchCmd.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2018 John Grosh (john.a.grosh@gmail.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.jagrosh.vortex.commands.general; - -import com.jagrosh.jdautilities.command.Command; -import com.jagrosh.jdautilities.command.CommandEvent; -import com.jagrosh.jdautilities.commons.JDAUtilitiesInfo; -import com.jagrosh.vortex.Constants; -import com.jagrosh.vortex.utils.FormatUtil; -import java.awt.Color; -import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.JDAInfo; -import net.dv8tion.jda.api.MessageBuilder; -import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.ChannelType; -import net.dv8tion.jda.api.sharding.ShardManager; -import net.dv8tion.jda.api.entities.User; - -/** - * - * @author John Grosh (john.a.grosh@gmail.com) - */ -public class TouchCmd extends Command -{ - public TouchCmd() - { - this.name = "touch"; - this.help = "touch a user"; - this.guildOnly = false; - this.botPermissions = new Permission[]{Permission.MESSAGE_EMBED_LINKS}; - } - - @Override - protected void execute(CommandEvent event) - { - if (event.getArgs().isEmpty()) { - event.replyError("Please mention a user to touch!"); - return; - } - - // Try to resolve a user from args - User target = event.getMessage().getMentionedUsers().stream().findFirst().orElse(null); - if (target == null) { - event.replyError("Could not find a mentioned user!"); - return; - } - - // Build the response - event.reply(new MessageBuilder() - .setContent(target.getAsMention() + "has been touched. mmmmm, :yum:") - // .setEmbed(new EmbedBuilder() - // .setColor(!event.isFromType(ChannelType.TEXT) ? Color.GRAY : event.getSelfMember().getColor()) - // .setDescription(target.getAsMention() + " has been touching. mmmmmm :yummy:") - // .build()) - .build()); - } -} diff --git a/src/main/java/com/jagrosh/vortex/commands/general/UserinfoCmd.java b/src/main/java/com/jagrosh/vortex/commands/general/UserinfoCmd.java index b9dd158..756e964 100644 --- a/src/main/java/com/jagrosh/vortex/commands/general/UserinfoCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/general/UserinfoCmd.java @@ -1,18 +1,3 @@ -/* - * Copyright 2016 John Grosh (jagrosh). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package com.jagrosh.vortex.commands.general; import java.time.format.DateTimeFormatter; @@ -26,21 +11,15 @@ import java.util.Collections; import java.util.List; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.MessageBuilder; -import net.dv8tion.jda.api.OnlineStatus; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.Activity; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.User; -/** - * - * @author John Grosh (jagrosh) - */ public class UserinfoCmd extends Command { - private final static String USER_EMOJI = "\uD83D\uDC64"; // 👤 - private final static String LINESTART = "\u25AB"; // ▫ + private final static String USER_EMOJI = "\uD83D\uDC64"; + private final static String LINESTART = "\u2192"; public UserinfoCmd() { @@ -68,7 +47,7 @@ event.replyError("I couldn't find the member you were looking for!"); return; } - else if(found.size()>1) + else if(found.size() > 1) { event.replyWarning(FormatUtil.filterEveryone(FormatUtil.listOfMember(found, event.getArgs()))); return; @@ -78,92 +57,61 @@ member = found.get(0); } } + User user = member.getUser(); String title = (user.isBot() ? Emoji.BOT : USER_EMOJI) + " Information about **" + user.getName() + "**:"; StringBuilder str = new StringBuilder(LINESTART + "Discord ID: **" + user.getId() + "** "); user.getFlags().forEach(flag -> str.append(OtherUtil.getEmoji(flag))); + if(user.getAvatarId() != null && user.getAvatarId().startsWith("a_")) str.append(Emoji.BADGE_NITRO); - if(member.getNickname()!=null) + if(member.getNickname() != null) str.append("\n" + LINESTART + "Nickname: **").append(member.getNickname()).append("**"); - String roles=""; + + String roles = ""; roles = member.getRoles().stream().map((rol) -> "`, `"+rol.getName()).reduce(roles, String::concat); if(roles.isEmpty()) - roles="None"; + roles = "None"; else - roles=roles.substring(3)+"`"; + roles = roles.substring(3) + "`"; + str.append("\n" + LINESTART + "Roles: ").append(roles); - //str.append("\n" + LINESTART + "Status: ").append(statusToEmote(member.getOnlineStatus(), member.getActivities())).append("**").append(member.getOnlineStatus().name()).append("**"); - //Activity game = member.getActivities().isEmpty() ? null : member.getActivities().get(0); - //if(game!=null) - // str.append(" (").append(formatGame(game)).append(")"); str.append("\n" + LINESTART + "Account Creation: **").append(user.getTimeCreated().format(DateTimeFormatter.RFC_1123_DATE_TIME)).append("**"); - List joins = new ArrayList<>(event.getGuild().getMembers()); + // Safeguarded from OOM using Cache fallback instead of live array mapping + List joins = new ArrayList<>(event.getGuild().getMemberCache().asList()); Collections.sort(joins, (Member a, Member b) -> a.getTimeJoined().compareTo(b.getTimeJoined())); int index = joins.indexOf(member); + str.append("\n" + LINESTART + "Guild Join Date: **").append(member.getTimeJoined().format(DateTimeFormatter.RFC_1123_DATE_TIME)).append("** `(#").append(index+1).append(")`"); - index-=3; - if(index<0) - index=0; - str.append("\n"+LINESTART+"Join Order: "); + + index -= 3; + if(index < 0) + index = 0; + + str.append("\n" + LINESTART + "Join Order: "); if(joins.get(index).equals(member)) - str.append("[**").append(joins.get(index).getUser().getName()).append("**]()"); + str.append("**").append(joins.get(index).getUser().getName()).append("**"); else str.append(joins.get(index).getUser().getName()); - for(int i=index+1;i=joins.size()) + if(i >= joins.size()) break; Member m = joins.get(i); String uname = m.getUser().getName(); if(m.equals(member)) - uname="[**"+uname+"**]()"; + uname = "**" + uname + "**"; str.append(" > ").append(uname); } - event.reply(new MessageBuilder() - .append(FormatUtil.filterEveryone(title)) - .setEmbed(new EmbedBuilder() + event.reply(new MessageCreateBuilder() + .addContent(FormatUtil.filterEveryone(title)) + .setEmbeds(new EmbedBuilder() .setDescription(str.toString()) .setThumbnail(user.getEffectiveAvatarUrl()) .setColor(member.getColor()).build()) .build()); } - - private static String statusToEmote(OnlineStatus status, List games) - { - Activity game = games.isEmpty() ? null : games.get(0); - if(game!=null && game.getType()==Activity.ActivityType.STREAMING && game.getUrl()!=null && Activity.isValidStreamingUrl(game.getUrl())) - return Emoji.STATUS_STREAMING; - switch(status) { - case ONLINE: return Emoji.STATUS_ONLINE; - case IDLE: return Emoji.STATUS_IDLE; - case DO_NOT_DISTURB: return Emoji.STATUS_DO_NOT_DISTURB; - case INVISIBLE: return Emoji.STATUS_INVISIBLE; - case OFFLINE: return Emoji.STATUS_OFFLINE; - default: return ""; - } - } - - private static String formatGame(Activity game) - { - String str; - switch(game.getType()) - { - case STREAMING: - return "Streaming [*"+game.getName()+"*]("+game.getUrl()+")"; - case LISTENING: - str="Listening to"; - break; - case WATCHING: - str="Watching"; - break; - case DEFAULT: - default: - str="Playing"; - break; - } - return str+" *"+game.getName()+"*"; - } -} +} \ No newline at end of file diff --git a/src/main/java/com/jagrosh/vortex/commands/moderation/BanCmd.java b/src/main/java/com/jagrosh/vortex/commands/moderation/BanCmd.java index 1900a83..720260d 100644 --- a/src/main/java/com/jagrosh/vortex/commands/moderation/BanCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/moderation/BanCmd.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,6 +20,7 @@ import com.jagrosh.vortex.commands.CommandExceptionListener.CommandErrorException; import com.jagrosh.vortex.commands.ModCommand; import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.User; import com.jagrosh.vortex.utils.ArgsUtil; import com.jagrosh.vortex.utils.ArgsUtil.ResolvedArgs; import com.jagrosh.vortex.utils.FormatUtil; @@ -28,6 +29,7 @@ import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.TimeUnit; import net.dv8tion.jda.api.entities.Role; /** @@ -103,7 +105,7 @@ long uid = ids.get(i); String id = Long.toString(uid); boolean last = i+1 == ids.size(); - event.getGuild().ban(id, daysToDelete, reason).queue(success -> + event.getGuild().ban(User.fromId(id), daysToDelete, TimeUnit.DAYS).reason(reason).queue(success -> { builder.append("\n").append(event.getClient().getSuccess()).append(" Successfully banned <@").append(id).append(">").append(time); if(minutes>0) @@ -120,4 +122,4 @@ }); } } -} +} \ No newline at end of file diff --git a/src/main/java/com/jagrosh/vortex/commands/moderation/CheckCmd.java b/src/main/java/com/jagrosh/vortex/commands/moderation/CheckCmd.java index f4a169f..3ba1dcb 100644 --- a/src/main/java/com/jagrosh/vortex/commands/moderation/CheckCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/moderation/CheckCmd.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -27,6 +27,7 @@ import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; /** * @@ -51,7 +52,9 @@ event.replySuccess("This command is used to see a user's strikes and mute/ban status for the current server. Please include a user or user ID to check."); return; } - event.getChannel().sendTyping().queue(); + if (event.getChannel() instanceof TextChannel) { + ((TextChannel) event.getChannel()).sendTyping().queue(); + } List members = FinderUtil.findMembers(event.getArgs(), event.getGuild()); if(!members.isEmpty()) { @@ -105,4 +108,4 @@ + Action.TEMPBAN.getEmoji() + " Ban Time Remaining: " + (minutesBanned <= 0 ? "N/A" : FormatUtil.secondsToTime(minutesBanned * 60)); event.replySuccess(FormatUtil.filterEveryone(str)); } -} +} \ No newline at end of file diff --git a/src/main/java/com/jagrosh/vortex/commands/moderation/CleanCmd.java b/src/main/java/com/jagrosh/vortex/commands/moderation/CleanCmd.java index 5dd4e78..1cc3faa 100644 --- a/src/main/java/com/jagrosh/vortex/commands/moderation/CleanCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/moderation/CleanCmd.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,6 +19,7 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import com.jagrosh.jdautilities.command.CooldownScope; import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.vortex.Vortex; import com.jagrosh.vortex.commands.CommandExceptionListener.CommandErrorException; @@ -31,7 +32,7 @@ import com.jagrosh.vortex.utils.LogUtil; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.EmbedType; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; /** * @@ -50,18 +51,18 @@ private final Pattern NUM_PATTERN = Pattern.compile("\\b(\\d{1,4})\\b"); private final String week2limit = " Note: Messages older than 2 weeks cannot be cleaned."; private final String noparams = "**No valid cleaning parameters included!**\n" - +"This command is to remove many messages quickly. Pinned messages are ignored. " - + "Messages can be filtered with various parameters. Mutliple arguments can be used, and " - + "the order of parameters does not matter. The following parameters are supported:\n" - + " `` - number of posts to delete; between 2 and 1000\n" - + " `bots` - cleans messages by bots\n" - + " `embeds` - cleans messages with embeds\n" - + " `links` - cleans messages containing links\n" - + " `images` - cleans messages with uploaded or embeded images or videos\n" - + " `@user` - cleans messages only from the provided user\n" - + " `userId` - cleans messages only from the provided user (via id)\n" - + " `\"quotes\"` - cleans messages containing the text in quotes\n" - + " `` `regex` `` - cleans messages that match the regex"; + +"This command is to remove many messages quickly. Pinned messages are ignored. " + + "Messages can be filtered with various parameters. Mutliple arguments can be used, and " + + "the order of parameters does not matter. The following parameters are supported:\n" + + " `` - number of posts to delete; between 2 and 1000\n" + + " `bots` - cleans messages by bots\n" + + " `embeds` - cleans messages with embeds\n" + + " `links` - cleans messages containing links\n" + + " `images` - cleans messages with uploaded or embeded images or videos\n" + + " `@user` - cleans messages only from the provided user\n" + + " `userId` - cleans messages only from the provided user (via id)\n" + + " `\"quotes\"` - cleans messages containing the text in quotes\n" + + " `` `regex` `` - cleans messages that match the regex"; public CleanCmd(Vortex vortex) { @@ -140,9 +141,12 @@ int val2 = num+1; String p = pattern; event.async(() -> { + if (!(event.getChannel() instanceof TextChannel)) return; + TextChannel channel = (TextChannel) event.getChannel(); + int val = val2; List msgs = new LinkedList<>(); - MessageHistory mh = event.getChannel().getHistory(); + MessageHistory mh = channel.getHistory(); OffsetDateTime earliest = event.getMessage().getTimeCreated().minusHours(335); while(val>100) { @@ -202,9 +206,9 @@ if(index+1==del.size()) del.get(del.size()-1).delete().complete(); else - event.getTextChannel().deleteMessages(del.subList(index, del.size())).complete(); + channel.deleteMessages(del.subList(index, del.size())).complete(); else - event.getTextChannel().deleteMessages(del.subList(index, index+100)).complete(); + channel.deleteMessages(del.subList(index, index+100)).complete(); index+=100; } }catch(Exception e) @@ -235,7 +239,7 @@ vortex.getTextUploader().upload(LogUtil.logMessagesBackwards("Cleaned Messages", del), "CleanedMessages", (view, download) -> { vortex.getModLogger().postCleanCase(event.getMember(), event.getMessage().getTimeCreated(), del.size(), - event.getTextChannel(), params, null, new EmbedBuilder().setColor(event.getSelfMember().getColor()) + channel, params, null, new EmbedBuilder().setColor(event.getSelfMember().getColor()) .appendDescription("[`"+VIEW+" View`]("+view+") | [`"+DOWNLOAD+" Download`]("+download+")").build()); }); }); @@ -251,4 +255,4 @@ return true; return false; } -} +} \ No newline at end of file diff --git a/src/main/java/com/jagrosh/vortex/commands/moderation/KickCmd.java b/src/main/java/com/jagrosh/vortex/commands/moderation/KickCmd.java index 16a5096..e204f5b 100644 --- a/src/main/java/com/jagrosh/vortex/commands/moderation/KickCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/moderation/KickCmd.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -87,7 +87,7 @@ { Member m = toKick.get(i); boolean last = i+1 == toKick.size(); - event.getGuild().kick(m, reason).queue(success -> + event.getGuild().kick(m).reason(reason).queue(success -> { builder.append("\n").append(event.getClient().getSuccess()).append(" Successfully kicked ").append(FormatUtil.formatUser(m.getUser())); if(last) @@ -100,4 +100,4 @@ }); } } -} +} \ No newline at end of file diff --git a/src/main/java/com/jagrosh/vortex/commands/moderation/SlowmodeCmd.java b/src/main/java/com/jagrosh/vortex/commands/moderation/SlowmodeCmd.java index 1ed1b69..5186549 100644 --- a/src/main/java/com/jagrosh/vortex/commands/moderation/SlowmodeCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/moderation/SlowmodeCmd.java @@ -49,8 +49,8 @@ if(event.getArgs().isEmpty()) { - int slowmodeDuration = vortex.getDatabase().tempslowmodes.timeUntilDisableSlowmode(event.getTextChannel()); - int slowmodeTime = event.getTextChannel().getSlowmode(); + int slowmodeDuration = vortex.getDatabase().tempslowmodes.timeUntilDisableSlowmode(event.getChannel().asTextChannel()); + int slowmodeTime = event.getChannel().asTextChannel().getSlowmode(); if(slowmodeTime <= 0) { @@ -70,8 +70,8 @@ if(args.equals("0") || args.equalsIgnoreCase("off")) { - vortex.getDatabase().tempslowmodes.clearSlowmode(event.getTextChannel()); - event.getTextChannel().getManager() + vortex.getDatabase().tempslowmodes.clearSlowmode(event.getChannel().asTextChannel()); + event.getChannel().asTextChannel().getManager() .setSlowmode(0) .reason(LogUtil.auditReasonFormat(event.getMember(), "Disabled slowmode")) .queue(); @@ -110,14 +110,14 @@ return; } - event.getTextChannel().getManager() + event.getChannel().asTextChannel().getManager() .setSlowmode(slowmodeTime) .reason(LogUtil.auditReasonFormat(event.getMember(), slowmodeDuration/60, "Enabled slowmode")) .queue(s -> { if(slowmodeDuration <= 0) return; vortex.getThreadpool().schedule( - () -> vortex.getDatabase().tempslowmodes.setSlowmode(event.getTextChannel(), Instant.now().plus(slowmodeDuration, ChronoUnit.SECONDS)), + () -> vortex.getDatabase().tempslowmodes.setSlowmode(event.getChannel().asTextChannel(), Instant.now().plus(slowmodeDuration, ChronoUnit.SECONDS)), 10, TimeUnit.SECONDS ); }); diff --git a/src/main/java/com/jagrosh/vortex/commands/moderation/SoftbanCmd.java b/src/main/java/com/jagrosh/vortex/commands/moderation/SoftbanCmd.java index 48139fe..b02b3a8 100644 --- a/src/main/java/com/jagrosh/vortex/commands/moderation/SoftbanCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/moderation/SoftbanCmd.java @@ -89,7 +89,7 @@ { Member m = toSoftban.get(i); boolean last = i+1 == toSoftban.size(); - event.getGuild().ban(m, 1, reason).queue(success -> + event.getGuild().ban(m, 1, TimeUnit.DAYS).setReason(reason).queue(success -> { builder.append("\n").append(event.getClient().getSuccess()).append(" Successfully softbanned ").append(FormatUtil.formatUser(m.getUser())); event.getGuild().unban(m.getUser().getId()).reason(unbanreason).queueAfter(4, TimeUnit.SECONDS); diff --git a/src/main/java/com/jagrosh/vortex/commands/moderation/VoicekickCmd.java b/src/main/java/com/jagrosh/vortex/commands/moderation/VoicekickCmd.java deleted file mode 100644 index 3221bff..0000000 --- a/src/main/java/com/jagrosh/vortex/commands/moderation/VoicekickCmd.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2016 John Grosh (jagrosh). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.jagrosh.vortex.commands.moderation; - -import java.util.LinkedList; -import com.jagrosh.jdautilities.command.CommandEvent; -import com.jagrosh.vortex.Vortex; -import com.jagrosh.vortex.commands.CommandExceptionListener.CommandErrorException; -import com.jagrosh.vortex.commands.ModCommand; -import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.Member; -import com.jagrosh.vortex.utils.ArgsUtil; -import com.jagrosh.vortex.utils.FormatUtil; -import com.jagrosh.vortex.utils.LogUtil; -import java.util.List; -import net.dv8tion.jda.api.entities.Role; - -/** - * - * @author John Grosh (jagrosh) - */ -public class VoicekickCmd extends ModCommand -{ - public VoicekickCmd(Vortex vortex) - { - super(vortex, Permission.VOICE_MOVE_OTHERS); - this.name = "voicekick"; - this.aliases = new String[]{"vckick"}; - this.arguments = "<@users> [reason]"; - this.help = "removes users from voice channels"; - this.botPermissions = new Permission[]{Permission.MANAGE_CHANNEL}; - } - - @Override - protected void execute(CommandEvent event) - { - if(!event.getSelfMember().hasPermission(Permission.VOICE_MOVE_OTHERS, Permission.VOICE_CONNECT)) - throw new CommandErrorException("I need permission to connect to voice channels and move members to do that!"); - ArgsUtil.ResolvedArgs args = ArgsUtil.resolve(event.getArgs(), event.getGuild()); - if(args.isEmpty()) - { - event.replyError("Please include at least one user to kick from voice (@mention or ID)!"); - return; - } - String reason = LogUtil.auditReasonFormat(event.getMember(), args.reason); - Role modrole = vortex.getDatabase().settings.getSettings(event.getGuild()).getModeratorRole(event.getGuild()); - StringBuilder builder = new StringBuilder(); - List toKick = new LinkedList<>(); - - args.members.forEach(m -> - { - if(!event.getMember().canInteract(m)) - builder.append("\n").append(event.getClient().getError()).append(" You do not have permission to voicekick ").append(FormatUtil.formatUser(m.getUser())); - else if(!event.getSelfMember().canInteract(m)) - builder.append("\n").append(event.getClient().getError()).append(" I am unable to voicekick ").append(FormatUtil.formatUser(m.getUser())); - else if(!m.getVoiceState().inVoiceChannel()) - builder.append("\n").append(event.getClient().getWarning()).append(" ").append(FormatUtil.formatUser(m.getUser())).append(" is not in a voice channel!"); - else if(modrole!=null && m.getRoles().contains(modrole)) - builder.append("\n").append(event.getClient().getError()).append(" I won't voicekick ").append(FormatUtil.formatUser(m.getUser())).append(" because they have the Moderator Role"); - else - toKick.add(m); - }); - - args.unresolved.forEach(un -> builder.append("\n").append(event.getClient().getWarning()).append(" Could not resolve `").append(un).append("` to a member")); - - args.users.forEach(u -> builder.append("\n").append(event.getClient().getWarning()).append("The user ").append(FormatUtil.formatUser(u)).append(" is not in this server.")); - - args.ids.forEach(id -> builder.append("\n").append(event.getClient().getWarning()).append("The user <@").append(id).append("> is not in this server.")); - - if(toKick.isEmpty()) - { - event.reply(builder.toString()); - return; - } - - if(toKick.size() > 5) - event.reactSuccess(); - - // do this async because its a nightmare to do it sync - event.async(() -> - { - for(int i=0; i toKick = new LinkedList<>(); + + args.members.forEach(m -> + { + if(!event.getMember().canInteract(m)) + builder.append("\n").append(event.getClient().getError()).append(" You do not have permission to voicekick ").append(FormatUtil.formatUser(m.getUser())); + else if(!event.getSelfMember().canInteract(m)) + builder.append("\n").append(event.getClient().getError()).append(" I am unable to voicekick ").append(FormatUtil.formatUser(m.getUser())); + else if(!m.getVoiceState().inVoiceChannel()) + builder.append("\n").append(event.getClient().getWarning()).append(" ").append(FormatUtil.formatUser(m.getUser())).append(" is not in a voice channel!"); + else if(modrole!=null && m.getRoles().contains(modrole)) + builder.append("\n").append(event.getClient().getError()).append(" I won't voicekick ").append(FormatUtil.formatUser(m.getUser())).append(" because they have the Moderator Role"); + else + toKick.add(m); + }); + + args.unresolved.forEach(un -> builder.append("\n").append(event.getClient().getWarning()).append(" Could not resolve `").append(un).append("` to a member")); + + args.users.forEach(u -> builder.append("\n").append(event.getClient().getWarning()).append("The user ").append(FormatUtil.formatUser(u)).append(" is not in this server.")); + + args.ids.forEach(id -> builder.append("\n").append(event.getClient().getWarning()).append("The user <@").append(id).append("> is not in this server.")); + + if(toKick.isEmpty()) + { + event.reply(builder.toString()); + return; + } + + if(toKick.size() > 5) + event.reactSuccess(); + + // do this async because its a nightmare to do it sync + event.async(() -> + { + for(int i=0; i list = FinderUtil.findVoiceChannels(event.getArgs(), event.getGuild()); - if(list.isEmpty()) - { - event.replyError("No voice channel found matching `"+event.getArgs()+"`!"); - return; - } - if(list.size()>1) - { - event.replyWarning(FormatUtil.filterEveryone(FormatUtil.listOfVoice(list, event.getArgs()))); - return; - } - vc = list.get(0); - } - else - { - vc = event.getMember().getVoiceState().getChannel(); - } - if(!event.getMember().hasPermission(Permission.VOICE_MOVE_OTHERS)) - { - event.replyError("You don't have permission to move users out of **"+vc.getName()+"**!"); - return; - } - if(!event.getSelfMember().hasPermission(Permission.VOICE_MOVE_OTHERS)) - { - event.replyError("I don't have permission to move users out of **"+vc.getName()+"**!"); - return; - } - try - { - event.getGuild().getAudioManager().openAudioConnection(vc); - } - catch(Exception e) - { - event.replyWarning(FormatUtil.filterEveryone("I could not connect to **"+vc.getName()+"**")); - event.getGuild().getAudioManager().closeAudioConnection(); - return; - } - vortex.getEventWaiter().waitForEvent(GuildVoiceMoveEvent.class, - (GuildVoiceMoveEvent e) -> - e.getGuild().equals(event.getGuild()) && e.getMember().equals(event.getGuild().getSelfMember()), - (GuildVoiceMoveEvent e) -> { - event.getGuild().getAudioManager().closeAudioConnection(); - e.getChannelLeft().getMembers().stream().forEach(m -> event.getGuild().moveVoiceMember(m, e.getChannelJoined()).queue()); - }, 1, TimeUnit.MINUTES, () -> { - event.getGuild().getAudioManager().closeAudioConnection(); - event.replyWarning("You waited too long, "+event.getMember().getAsMention()); - }); - event.reply("\uD83C\uDF9B Now, move me and I'll drag users to a new voice channel."); // 🎛 - // failsafe to leave voice channel - event.getClient().getScheduleExecutor().schedule(() -> event.getGuild().getAudioManager().closeAudioConnection(), 2, TimeUnit.MINUTES); - } - -} diff --git a/src/main/java/com/jagrosh/vortex/commands/moderation/VoicemoveCmd.java.fixmel8r b/src/main/java/com/jagrosh/vortex/commands/moderation/VoicemoveCmd.java.fixmel8r new file mode 100644 index 0000000..3f55736 --- /dev/null +++ b/src/main/java/com/jagrosh/vortex/commands/moderation/VoicemoveCmd.java.fixmel8r @@ -0,0 +1,114 @@ +/* + * Copyright 2016 John Grosh (jagrosh). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jagrosh.vortex.commands.moderation; + +import java.util.List; +import java.util.concurrent.TimeUnit; +import com.jagrosh.jdautilities.command.CommandEvent; +import com.jagrosh.jdautilities.commons.utils.FinderUtil; +import com.jagrosh.vortex.Vortex; +import com.jagrosh.vortex.commands.ModCommand; +import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel; +import net.dv8tion.jda.api.events.guild.voice.GuildVoiceMoveEvent; +import com.jagrosh.vortex.utils.FormatUtil; + +/** + * + * @author John Grosh (jagrosh) + */ +public class VoicemoveCmd extends ModCommand +{ + public VoicemoveCmd(Vortex vortex) + { + super(vortex, Permission.VOICE_MOVE_OTHERS); + this.name = "voicemove"; + this.aliases = new String[]{"magnet"}; + this.help = "mass-moves voice channel users"; + this.arguments = "[channel]"; + this.cooldown = 20; + this.cooldownScope = CooldownScope.GUILD; + } + + @Override + protected void execute(CommandEvent event) + { + if(event.getGuild().getSelfMember().getVoiceState().inVoiceChannel()) + { + event.replyWarning("I am already in a voice channel; move me to drag all users."); + return; + } + if(event.getArgs().isEmpty() && !event.getMember().getVoiceState().inVoiceChannel()) + { + event.replyError("You must be in or specify a voice channel to move users from!"); + return; + } + VoiceChannel vc; + if(!event.getArgs().isEmpty()) + { + List list = FinderUtil.findVoiceChannels(event.getArgs(), event.getGuild()); + if(list.isEmpty()) + { + event.replyError("No voice channel found matching `"+event.getArgs()+"`!"); + return; + } + if(list.size()>1) + { + event.replyWarning(FormatUtil.filterEveryone(FormatUtil.listOfVoice(list, event.getArgs()))); + return; + } + vc = list.get(0); + } + else + { + vc = event.getMember().getVoiceState().getChannel(); + } + if(!event.getMember().hasPermission(Permission.VOICE_MOVE_OTHERS)) + { + event.replyError("You don't have permission to move users out of **"+vc.getName()+"**!"); + return; + } + if(!event.getSelfMember().hasPermission(Permission.VOICE_MOVE_OTHERS)) + { + event.replyError("I don't have permission to move users out of **"+vc.getName()+"**!"); + return; + } + try + { + event.getGuild().getAudioManager().openAudioConnection(vc); + } + catch(Exception e) + { + event.replyWarning(FormatUtil.filterEveryone("I could not connect to **"+vc.getName()+"**")); + event.getGuild().getAudioManager().closeAudioConnection(); + return; + } + vortex.getEventWaiter().waitForEvent(GuildVoiceMoveEvent.class, + (GuildVoiceMoveEvent e) -> + e.getGuild().equals(event.getGuild()) && e.getMember().equals(event.getGuild().getSelfMember()), + (GuildVoiceMoveEvent e) -> { + event.getGuild().getAudioManager().closeAudioConnection(); + e.getChannelLeft().getMembers().stream().forEach(m -> event.getGuild().moveVoiceMember(m, e.getChannelJoined()).queue()); + }, 1, TimeUnit.MINUTES, () -> { + event.getGuild().getAudioManager().closeAudioConnection(); + event.replyWarning("You waited too long, "+event.getMember().getAsMention()); + }); + event.reply("\uD83C\uDF9B Now, move me and I'll drag users to a new voice channel."); // 🎛 + // failsafe to leave voice channel + event.getClient().getScheduleExecutor().schedule(() -> event.getGuild().getAudioManager().closeAudioConnection(), 2, TimeUnit.MINUTES); + } + +} diff --git a/src/main/java/com/jagrosh/vortex/commands/owner/EvalCmd.java b/src/main/java/com/jagrosh/vortex/commands/owner/EvalCmd.java index 6462bfd..9e35080 100644 --- a/src/main/java/com/jagrosh/vortex/commands/owner/EvalCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/owner/EvalCmd.java @@ -42,7 +42,7 @@ @Override protected void execute(CommandEvent event) { - event.getChannel().sendTyping().queue(); + event.getChannel().asTextChannel().sendTyping().queue(); event.async(() -> { ScriptEngine se = new ScriptEngineManager().getEngineByName("Nashorn"); @@ -50,7 +50,7 @@ se.put("event", event); se.put("jda", event.getJDA()); se.put("guild", event.getGuild()); - se.put("channel", event.getChannel()); + se.put("channel", event.getChannel().asTextChannel()); String args = event.getArgs().replaceAll("([^(]+?)\\s*->", "function($1)"); try { diff --git a/src/main/java/com/jagrosh/vortex/commands/settings/AvatarlogCmd.java b/src/main/java/com/jagrosh/vortex/commands/settings/AvatarlogCmd.java index 5c0da15..fa08102 100644 --- a/src/main/java/com/jagrosh/vortex/commands/settings/AvatarlogCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/settings/AvatarlogCmd.java @@ -20,7 +20,7 @@ import com.jagrosh.vortex.Vortex; import com.jagrosh.vortex.commands.LogCommand; import com.jagrosh.vortex.database.managers.PremiumManager; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; /** * diff --git a/src/main/java/com/jagrosh/vortex/commands/settings/MessagelogCmd.java b/src/main/java/com/jagrosh/vortex/commands/settings/MessagelogCmd.java index c122ce1..9f961c1 100644 --- a/src/main/java/com/jagrosh/vortex/commands/settings/MessagelogCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/settings/MessagelogCmd.java @@ -18,7 +18,7 @@ import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.vortex.Vortex; import com.jagrosh.vortex.commands.LogCommand; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; /** * diff --git a/src/main/java/com/jagrosh/vortex/commands/settings/ModlogCmd.java b/src/main/java/com/jagrosh/vortex/commands/settings/ModlogCmd.java index ba6a12a..f85610d 100644 --- a/src/main/java/com/jagrosh/vortex/commands/settings/ModlogCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/settings/ModlogCmd.java @@ -19,7 +19,7 @@ import com.jagrosh.vortex.Vortex; import com.jagrosh.vortex.commands.LogCommand; import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; /** * diff --git a/src/main/java/com/jagrosh/vortex/commands/settings/PunishmentCmd.java b/src/main/java/com/jagrosh/vortex/commands/settings/PunishmentCmd.java index 3efb817..a738313 100644 --- a/src/main/java/com/jagrosh/vortex/commands/settings/PunishmentCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/settings/PunishmentCmd.java @@ -25,7 +25,7 @@ import com.jagrosh.vortex.utils.FormatUtil; import com.jagrosh.vortex.utils.OtherUtil; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.MessageBuilder; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; import net.dv8tion.jda.api.Permission; /** @@ -164,10 +164,10 @@ return; } } - event.reply(new MessageBuilder() - .append(event.getClient().getSuccess()) + event.reply(new MessageCreateBuilder() + .addContent(event.getClient().getSuccess()) .append(" ").append(FormatUtil.filterEveryone(successMessage)) - .setEmbed(new EmbedBuilder().setColor(event.getSelfMember().getColor()) + .setEmbeds(new EmbedBuilder().setColor(event.getSelfMember().getColor()) .addField(vortex.getDatabase().actions.getAllPunishmentsDisplay(event.getGuild())) .build()) .build()); diff --git a/src/main/java/com/jagrosh/vortex/commands/settings/ServerlogCmd.java b/src/main/java/com/jagrosh/vortex/commands/settings/ServerlogCmd.java index 2e145fa..0f7b060 100644 --- a/src/main/java/com/jagrosh/vortex/commands/settings/ServerlogCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/settings/ServerlogCmd.java @@ -19,7 +19,7 @@ import com.jagrosh.vortex.Vortex; import com.jagrosh.vortex.commands.LogCommand; import com.jagrosh.vortex.database.managers.PremiumManager; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; /** * diff --git a/src/main/java/com/jagrosh/vortex/commands/settings/SettingsCmd.java b/src/main/java/com/jagrosh/vortex/commands/settings/SettingsCmd.java index 1a1b472..995cd7a 100644 --- a/src/main/java/com/jagrosh/vortex/commands/settings/SettingsCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/settings/SettingsCmd.java @@ -21,7 +21,7 @@ import com.jagrosh.vortex.database.managers.PremiumManager.PremiumInfo; import com.jagrosh.vortex.utils.FormatUtil; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.MessageBuilder; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; import net.dv8tion.jda.api.Permission; /** @@ -46,9 +46,9 @@ protected void execute(CommandEvent event) { PremiumInfo pi = vortex.getDatabase().premium.getPremiumInfo(event.getGuild()); - event.getChannel().sendMessage(new MessageBuilder() - .append(FormatUtil.filterEveryone("**" + event.getSelfUser().getName() + "** settings on **" + event.getGuild().getName() + "**:")) - .setEmbed(new EmbedBuilder() + event.getChannel().asTextChannel().sendMessage(new MessageCreateBuilder() + .addContent(FormatUtil.filterEveryone("**" + event.getSelfUser().getName() + "** settings on **" + event.getGuild().getName() + "**:")) + .setEmbeds(new EmbedBuilder() //.setThumbnail(event.getGuild().getIconId()==null ? event.getSelfUser().getEffectiveAvatarUrl() : event.getGuild().getIconUrl()) .addField(vortex.getDatabase().settings.getSettingsDisplay(event.getGuild())) .addField(vortex.getDatabase().actions.getAllPunishmentsDisplay(event.getGuild())) diff --git a/src/main/java/com/jagrosh/vortex/commands/settings/SetupCmd.java b/src/main/java/com/jagrosh/vortex/commands/settings/SetupCmd.java index 8f9e97c..7b06f6c 100644 --- a/src/main/java/com/jagrosh/vortex/commands/settings/SetupCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/settings/SetupCmd.java @@ -10,8 +10,8 @@ import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.PermissionOverride; import net.dv8tion.jda.api.entities.Role; -import net.dv8tion.jda.api.entities.TextChannel; -import net.dv8tion.jda.api.entities.VoiceChannel; +import net.dv8tion.jda.api.entities.channel.concrete.*; +import com.jagrosh.jdautilities.command.CooldownScope; /** * Command for setting up the bot in the server. @@ -64,7 +64,7 @@ { waitForConfirmation(event, "This will enable all automod defaults. Any existing settings will not be overwritten.", () -> { - event.getChannel().sendTyping().queue(); + event.getChannel().asTextChannel().sendTyping().queue(); StringBuilder sb = new StringBuilder("**Automod setup complete!**"); AutomodSettings ams = vortex.getDatabase().automod.getSettings(event.getGuild()); if(ams.inviteStrikes==0) @@ -183,9 +183,9 @@ { po = cat.getPermissionOverride(mutedRole); if(po==null) - cat.createPermissionOverride(mutedRole).setDeny(Permission.MESSAGE_WRITE, Permission.MESSAGE_ADD_REACTION, Permission.VOICE_CONNECT, Permission.VOICE_SPEAK, Permission.USE_PUBLIC_THREADS, Permission.USE_PRIVATE_THREADS).complete(); + cat.createPermissionOverride(mutedRole).setDeny(Permission.MESSAGE_SEND, Permission.MESSAGE_ADD_REACTION, Permission.VOICE_CONNECT, Permission.VOICE_SPEAK, Permission.CREATE_PUBLIC_THREADS, Permission.CREATE_PRIVATE_THREADS).complete(); else - po.getManager().deny(Permission.MESSAGE_WRITE, Permission.MESSAGE_ADD_REACTION, Permission.VOICE_CONNECT, Permission.VOICE_SPEAK, Permission.USE_PUBLIC_THREADS, Permission.USE_PRIVATE_THREADS).complete(); + po.getManager().deny(Permission.MESSAGE_SEND, Permission.MESSAGE_ADD_REACTION, Permission.VOICE_CONNECT, Permission.VOICE_SPEAK, Permission.CREATE_PUBLIC_THREADS, Permission.CREATE_PRIVATE_THREADS).complete(); } sb.append(event.getClient().getSuccess()).append(" Category overrides complete!\n"); m.editMessage(sb + Constants.LOADING + " Making Text Channel overrides...").complete(); @@ -193,9 +193,9 @@ { po = tc.getPermissionOverride(mutedRole); if(po==null) - tc.createPermissionOverride(mutedRole).setDeny(Permission.MESSAGE_WRITE, Permission.MESSAGE_ADD_REACTION, Permission.USE_PUBLIC_THREADS, Permission.USE_PRIVATE_THREADS).complete(); + tc.createPermissionOverride(mutedRole).setDeny(Permission.MESSAGE_SEND, Permission.MESSAGE_ADD_REACTION, Permission.CREATE_PUBLIC_THREADS, Permission.CREATE_PRIVATE_THREADS).complete(); else - po.getManager().deny(Permission.MESSAGE_WRITE, Permission.MESSAGE_ADD_REACTION, Permission.USE_PUBLIC_THREADS, Permission.USE_PRIVATE_THREADS).complete(); + po.getManager().deny(Permission.MESSAGE_SEND, Permission.MESSAGE_ADD_REACTION, Permission.CREATE_PUBLIC_THREADS, Permission.CREATE_PRIVATE_THREADS).complete(); } sb.append(event.getClient().getSuccess()).append(" Text Channel overrides complete!\n"); m.editMessage(sb + Constants.LOADING + " Making Voice Channel overrides...").complete(); @@ -229,7 +229,7 @@ { if(re.getName().equals(CONFIRM)) confirm.run(); - }).build().display(event.getChannel()); + }).build().display(event.getChannel().asTextChannel()); } private class VerificationSetupCmd extends Command diff --git a/src/main/java/com/jagrosh/vortex/commands/settings/SetupCmdOLD.disabled b/src/main/java/com/jagrosh/vortex/commands/settings/SetupCmdOLD.disabled index cbf82dd..b0e3468 100644 --- a/src/main/java/com/jagrosh/vortex/commands/settings/SetupCmdOLD.disabled +++ b/src/main/java/com/jagrosh/vortex/commands/settings/SetupCmdOLD.disabled @@ -25,8 +25,8 @@ import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.PermissionOverride; import net.dv8tion.jda.api.entities.Role; -import net.dv8tion.jda.api.entities.TextChannel; -import net.dv8tion.jda.api.entities.VoiceChannel; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel; /** * @@ -201,9 +201,9 @@ { po = cat.getPermissionOverride(mutedRole); if(po==null) - cat.createPermissionOverride(mutedRole).setDeny(Permission.MESSAGE_WRITE, Permission.MESSAGE_ADD_REACTION, Permission.VOICE_CONNECT, Permission.VOICE_SPEAK, Permission.USE_PUBLIC_THREADS, Permission.USE_PRIVATE_THREADS).complete(); + cat.createPermissionOverride(mutedRole).setDeny(Permission.MESSAGE_SEND, Permission.MESSAGE_ADD_REACTION, Permission.VOICE_CONNECT, Permission.VOICE_SPEAK, Permission.CREATE_PUBLIC_THREADS, Permission.CREATE_PRIVATE_THREADS).complete(); else - po.getManager().deny(Permission.MESSAGE_WRITE, Permission.MESSAGE_ADD_REACTION, Permission.VOICE_CONNECT, Permission.VOICE_SPEAK, Permission.USE_PUBLIC_THREADS, Permission.USE_PRIVATE_THREADS).complete(); + po.getManager().deny(Permission.MESSAGE_SEND, Permission.MESSAGE_ADD_REACTION, Permission.VOICE_CONNECT, Permission.VOICE_SPEAK, Permission.CREATE_PUBLIC_THREADS, Permission.CREATE_PRIVATE_THREADS).complete(); } sb.append(event.getClient().getSuccess()).append(" Category overrides complete!\n"); m.editMessage(sb + Constants.LOADING + " Making Text Channel overrides...").complete(); @@ -211,9 +211,9 @@ { po = tc.getPermissionOverride(mutedRole); if(po==null) - tc.createPermissionOverride(mutedRole).setDeny(Permission.MESSAGE_WRITE, Permission.MESSAGE_ADD_REACTION, Permission.USE_PUBLIC_THREADS, Permission.USE_PRIVATE_THREADS).complete(); + tc.createPermissionOverride(mutedRole).setDeny(Permission.MESSAGE_SEND, Permission.MESSAGE_ADD_REACTION, Permission.CREATE_PUBLIC_THREADS, Permission.CREATE_PRIVATE_THREADS).complete(); else - po.getManager().deny(Permission.MESSAGE_WRITE, Permission.MESSAGE_ADD_REACTION, Permission.USE_PUBLIC_THREADS, Permission.USE_PRIVATE_THREADS).complete(); + po.getManager().deny(Permission.MESSAGE_SEND, Permission.MESSAGE_ADD_REACTION, Permission.CREATE_PUBLIC_THREADS, Permission.CREATE_PRIVATE_THREADS).complete(); } sb.append(event.getClient().getSuccess()).append(" Text Channel overrides complete!\n"); m.editMessage(sb + Constants.LOADING + " Making Voice Channel overrides...").complete(); diff --git a/src/main/java/com/jagrosh/vortex/commands/settings/VoicelogCmd.java b/src/main/java/com/jagrosh/vortex/commands/settings/VoicelogCmd.java index 0a14abc..c581b27 100644 --- a/src/main/java/com/jagrosh/vortex/commands/settings/VoicelogCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/settings/VoicelogCmd.java @@ -19,7 +19,7 @@ import com.jagrosh.vortex.Vortex; import com.jagrosh.vortex.commands.LogCommand; import com.jagrosh.vortex.database.managers.PremiumManager; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; /** * diff --git a/src/main/java/com/jagrosh/vortex/commands/tools/AnnounceCmd.java b/src/main/java/com/jagrosh/vortex/commands/tools/AnnounceCmd.java index 57c3308..4b3cc63 100644 --- a/src/main/java/com/jagrosh/vortex/commands/tools/AnnounceCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/tools/AnnounceCmd.java @@ -16,6 +16,7 @@ package com.jagrosh.vortex.commands.tools; import com.jagrosh.jdautilities.command.Command; +import com.jagrosh.jdautilities.command.CooldownScope; import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.commons.utils.FinderUtil; import com.jagrosh.vortex.Constants; @@ -27,7 +28,7 @@ import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Role; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; /** * @@ -93,7 +94,7 @@ String reason = "Announcement by "+event.getAuthor().getName(); role.getManager().setMentionable(true).reason(reason).queue(s -> { - tc.sendMessage(fmessage).allowedMentions(EnumSet.of(Message.MentionType.ROLE)).queue(m -> + tc.sendMessage(fmessage).setAllowedMentions(EnumSet.of(Message.MentionType.ROLE)).queue(m -> { event.replySuccess("Announcement for `"+role.getName()+"` sent to "+tc.getAsMention()+"!"); role.getManager().setMentionable(false).reason(reason).queue(s2->{}, f2->{}); diff --git a/src/main/java/com/jagrosh/vortex/commands/tools/AuditCmd.disabled.no.fuckoff.fucku b/src/main/java/com/jagrosh/vortex/commands/tools/AuditCmd.disabled.no.fuckoff.fucku new file mode 100644 index 0000000..a8b0498 --- /dev/null +++ b/src/main/java/com/jagrosh/vortex/commands/tools/AuditCmd.disabled.no.fuckoff.fucku @@ -0,0 +1,241 @@ +// /* +// * Copyright 2018 John Grosh (john.a.grosh@gmail.com). +// * +// * Licensed under the Apache License, Version 2.0 (the "License"); +// * you may not use this file except in compliance with the License. +// * You may obtain a copy of the License at +// * +// * http://www.apache.org/licenses/LICENSE-2.0 +// * +// * Unless required by applicable law or agreed to in writing, software +// * distributed under the License is distributed on an "AS IS" BASIS, +// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// * See the License for the specific language governing permissions and +// * limitations under the License. +// */ +// package com.jagrosh.vortex.commands.tools; + +// import com.jagrosh.jdautilities.command.Command; +// import com.jagrosh.jdautilities.command.CommandEvent; +// import com.jagrosh.jdautilities.commons.utils.FinderUtil; +// import com.jagrosh.vortex.commands.CommandExceptionListener.CommandErrorException; +// import com.jagrosh.vortex.commands.CommandExceptionListener.CommandWarningException; +// import com.jagrosh.vortex.utils.FormatUtil; +// import java.time.format.DateTimeFormatter; +// import java.util.List; +// import net.dv8tion.jda.api.EmbedBuilder; +// import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; +// import net.dv8tion.jda.api.Permission; +// import net.dv8tion.jda.api.audit.ActionType; +// import net.dv8tion.jda.api.audit.AuditLogChange; +// import net.dv8tion.jda.api.entities.Emote; +// import net.dv8tion.jda.api.entities.Role; +// import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +// import net.dv8tion.jda.api.entities.User; +// import net.dv8tion.jda.api.requests.restaction.pagination.AuditLogPaginationAction; + +// /** +// * +// * @author John Grosh (john.a.grosh@gmail.com) +// */ +// public class AuditCmd extends Command +// { +// private final static String LINESTART = "\u25AB"; // ▫ +// private final static String UNKNOWN = "*Unknown*"; + +// private final String actions; + +// public AuditCmd() +// { +// this.name = "audit"; +// this.aliases = new String[]{"auditlog","auditlogs","audits"}; +// this.arguments = " [target]"; +// this.help = "fetches recent audit logs"; +// this.guildOnly = true; +// this.botPermissions = new Permission[]{Permission.MESSAGE_EMBED_LINKS, Permission.VIEW_AUDIT_LOGS, Permission.MESSAGE_EXT_EMOJI}; +// this.userPermissions = new Permission[]{Permission.VIEW_AUDIT_LOGS}; +// this.cooldown = 5; +// this.category = new Category("Tools"); +// StringBuilder sb = new StringBuilder("\n\nValid actions: `"); +// for(ActionType type: ActionType.values()) +// sb.append(type.name()).append("`, `"); +// actions = sb.toString().substring(0, sb.length()-3); +// } + +// @Override +// protected void execute(CommandEvent event) +// { +// String[] parts = event.getArgs().split("\\s+", 2); +// AuditLogPaginationAction action = event.getGuild().retrieveAuditLogs().cache(false).limit(10); +// switch(parts[0].toLowerCase()) +// { +// case "all": +// break; +// case "from": +// if(parts.length==1) +// throw new CommandErrorException("Please include a user"); +// List list = FinderUtil.findUsers(parts[1], event.getJDA()); +// if(list.isEmpty()) +// throw new CommandWarningException("No users found matching `"+parts[1]+"`"); +// if(list.size()>1) +// throw new CommandWarningException(FormatUtil.listOfUser(list, event.getArgs())); +// action = action.user(list.get(0)); +// break; +// case "action": +// if(parts.length==1) +// throw new CommandErrorException("Please include an action"+actions); +// ActionType type = null; +// for(ActionType t: ActionType.values()) +// { +// if(t.name().toLowerCase().replace("_", "").equals(parts[1].toLowerCase().replace("_", "").replace(" ", ""))) +// { +// type = t; +// break; +// } +// } +// if(type==null) +// throw new CommandErrorException("Please include a valid action"+actions); +// action = action.type(type); +// break; +// default: +// throw new CommandErrorException("Valid subcommands:\n\n" +// + "`" + event.getClient().getPrefix() + name + " all` - shows recent audit log entries\n" +// + "`" + event.getClient().getPrefix() + name + " from ` - shows recent entries by a user\n" +// + "`" + event.getClient().getPrefix() + name + " action ` shows recent entries of a certain action"); +// } +// event.getChannel().asTextChannel().sendTyping().queue(); +// action.queue(list -> +// { +// if(list.isEmpty()) +// { +// event.replyWarning("No audit log entries found matching your criteria"); +// return; +// } +// EmbedBuilder eb = new EmbedBuilder().setColor(event.getSelfMember().getColor()); +// list.forEach(ale -> +// { +// StringBuilder sb = new StringBuilder(); +// sb.append(LINESTART).append("User: ").append(FormatUtil.formatFullUser(ale.getUser())); +// switch(ale.getTargetType()) +// { +// case CHANNEL: +// TextChannel tc = event.getGuild().getTextChannelById(ale.getTargetIdLong()); +// sb.append("\n").append(LINESTART).append("Channel: ") +// .append(tc==null ? UNKNOWN : "**#"+tc.getName()+"**") +// .append(" (ID:").append(ale.getTargetId()).append(")"); +// break; +// case EMOTE: +// Emote e = event.getGuild().getEmoteById(ale.getTargetIdLong()); +// sb.append("\n").append(LINESTART).append("Emote: ") +// .append(e==null ? UNKNOWN : e.getAsMention()) +// .append(" (ID:").append(ale.getTargetId()).append(")"); +// break; +// case GUILD: +// break; +// case INVITE: +// break; +// case MEMBER: +// User u = event.getJDA().getUserById(ale.getTargetIdLong()); +// sb.append("\n").append(LINESTART).append("Member: ") +// .append(u==null ? UNKNOWN : FormatUtil.formatUser(u)) +// .append(" (ID:").append(ale.getTargetId()).append(")"); +// break; +// case ROLE: +// Role r = event.getGuild().getRoleById(ale.getTargetIdLong()); +// sb.append("\n").append(LINESTART).append("Role: ") +// .append(r==null ? UNKNOWN : "**"+r.getName()+"**") +// .append(" (ID:").append(ale.getTargetId()).append(")"); +// break; +// case WEBHOOK: +// sb.append("\n").append(LINESTART).append("Webhook ID: ").append(ale.getTargetId()); +// break; +// case UNKNOWN: +// default: +// sb.append("\n").append(LINESTART).append("Target ID: ").append(ale.getTargetId()); +// } +// ale.getChanges().keySet().forEach(change -> +// { +// AuditLogChange alc = ale.getChangeByKey(change); +// if(alc != null) +// sb.append("\n").append(LINESTART).append(fixCase(change)).append(": ") +// .append(alc.getOldValue()==null ? "" : "**"+alc.getOldValue()+"**") +// .append(alc.getOldValue()==null || alc.getNewValue()==null ? "" : " → ") +// .append(alc.getNewValue()==null ? "" : "**"+alc.getNewValue()+"**"); +// }); +// ale.getOptions().keySet().forEach(option -> +// { +// sb.append("\n").append(LINESTART).append(fixCase(option)).append(": ") +// .append(ale.getOptionByName(option)==null ? UNKNOWN : "**"+ale.getOptionByName(option)+"**"); +// }); +// if(ale.getReason()!=null) +// sb.append("\n").append(LINESTART).append("Reason: ").append(ale.getReason()); +// sb.append("\n").append(LINESTART).append("Time: **").append(ale.getTimeCreated().format(DateTimeFormatter.RFC_1123_DATE_TIME)).append("**\n\u200B"); +// String str = sb.length()>1024 ? sb.substring(0,1020)+" ..." : sb.toString(); +// eb.addField(actionToEmote(ale.getType())+" "+fixCase(ale.getType().name()), str, true); +// }); +// event.reply(new MessageCreateBuilder() +// .setContent(event.getClient().getSuccess()+" Recent Audit Logs in **"+FormatUtil.filterEveryone(event.getGuild().getName())+"**:") +// .setEmbeds(eb.build()).build()); +// }, f -> event.replyWarning("Failed to retrieve audit logs")); +// } + +// private String fixCase(String input) +// { +// String ret = ""; +// for(int i=0; i"; +// case KICK: return "<:DeleteUser:274789150920671232>"; +// case UNBAN: return "<:Unban:274789150689984513>"; +// case PRUNE: return "<:removeMember:417574812718858250>"; + +// case CHANNEL_CREATE: return "<:addChannel:417574812425125888>"; +// case CHANNEL_DELETE: return "<:deleteChannel:417574812622258186>"; +// case CHANNEL_UPDATE: return "<:updateChannel:417574812240576514>"; + +// case CHANNEL_OVERRIDE_CREATE: return "<:addChannel:417574812425125888>"; +// case CHANNEL_OVERRIDE_DELETE: return "<:deleteChannel:417574812622258186>"; +// case CHANNEL_OVERRIDE_UPDATE: return "<:updateChannel:417574812240576514>"; + +// case EMOTE_CREATE: return "<:createEmoji:417574812689498112>"; +// case EMOTE_DELETE: return "<:deleteEmoji:417574812521725962>"; +// case EMOTE_UPDATE: return "<:updateEmoji:417574812601548800>"; + +// case GUILD_UPDATE: return "<:updateServer:417574812534177793>"; + +// case INVITE_CREATE: return "<:addInvite:417574812517662721>"; +// case INVITE_DELETE: return "<:deleteInvite:417574812521725953>"; +// case INVITE_UPDATE: return "<:updateInvite:417574812429320192>"; + +// case MEMBER_ROLE_UPDATE: return "<:updateMember:417574812504948736>"; +// case MEMBER_UPDATE: return "<:updateMember:417574812504948736>"; + +// case MESSAGE_CREATE: return "<:createMessage:446853279926845452>"; +// case MESSAGE_DELETE: return "<:deleteMessage:417574812399960065>"; +// case MESSAGE_UPDATE: return "<:updateMessage:446853280308396032>"; + +// case ROLE_CREATE: return "<:createRole:417574812399960075>"; +// case ROLE_DELETE: return "<:deleteRole:417574812463136769>"; +// case ROLE_UPDATE: return "<:updateRole:417574812165210126>"; + +// case WEBHOOK_CREATE: return "<:createWebhook:417574812714532864>"; +// case WEBHOOK_REMOVE: return "<:deleteWebhook:417574812098101250>"; +// case WEBHOOK_UPDATE: return "<:updateWebhook:417574812534439946>"; + +// case UNKNOWN: return "\u2753"; // ❓ +// default: return "\u2753"; // ❓ +// } +// } +// } diff --git a/src/main/java/com/jagrosh/vortex/commands/tools/AuditCmd.java b/src/main/java/com/jagrosh/vortex/commands/tools/AuditCmd.java deleted file mode 100644 index b42af66..0000000 --- a/src/main/java/com/jagrosh/vortex/commands/tools/AuditCmd.java +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright 2018 John Grosh (john.a.grosh@gmail.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.jagrosh.vortex.commands.tools; - -import com.jagrosh.jdautilities.command.Command; -import com.jagrosh.jdautilities.command.CommandEvent; -import com.jagrosh.jdautilities.commons.utils.FinderUtil; -import com.jagrosh.vortex.commands.CommandExceptionListener.CommandErrorException; -import com.jagrosh.vortex.commands.CommandExceptionListener.CommandWarningException; -import com.jagrosh.vortex.utils.FormatUtil; -import java.time.format.DateTimeFormatter; -import java.util.List; -import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.MessageBuilder; -import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.audit.ActionType; -import net.dv8tion.jda.api.audit.AuditLogChange; -import net.dv8tion.jda.api.entities.Emote; -import net.dv8tion.jda.api.entities.Role; -import net.dv8tion.jda.api.entities.TextChannel; -import net.dv8tion.jda.api.entities.User; -import net.dv8tion.jda.api.requests.restaction.pagination.AuditLogPaginationAction; - -/** - * - * @author John Grosh (john.a.grosh@gmail.com) - */ -public class AuditCmd extends Command -{ - private final static String LINESTART = "\u25AB"; // ▫ - private final static String UNKNOWN = "*Unknown*"; - - private final String actions; - - public AuditCmd() - { - this.name = "audit"; - this.aliases = new String[]{"auditlog","auditlogs","audits"}; - this.arguments = " [target]"; - this.help = "fetches recent audit logs"; - this.guildOnly = true; - this.botPermissions = new Permission[]{Permission.MESSAGE_EMBED_LINKS, Permission.VIEW_AUDIT_LOGS, Permission.MESSAGE_EXT_EMOJI}; - this.userPermissions = new Permission[]{Permission.VIEW_AUDIT_LOGS}; - this.cooldown = 5; - this.category = new Category("Tools"); - StringBuilder sb = new StringBuilder("\n\nValid actions: `"); - for(ActionType type: ActionType.values()) - sb.append(type.name()).append("`, `"); - actions = sb.toString().substring(0, sb.length()-3); - } - - @Override - protected void execute(CommandEvent event) - { - String[] parts = event.getArgs().split("\\s+", 2); - AuditLogPaginationAction action = event.getGuild().retrieveAuditLogs().cache(false).limit(10); - switch(parts[0].toLowerCase()) - { - case "all": - break; - case "from": - if(parts.length==1) - throw new CommandErrorException("Please include a user"); - List list = FinderUtil.findUsers(parts[1], event.getJDA()); - if(list.isEmpty()) - throw new CommandWarningException("No users found matching `"+parts[1]+"`"); - if(list.size()>1) - throw new CommandWarningException(FormatUtil.listOfUser(list, event.getArgs())); - action = action.user(list.get(0)); - break; - case "action": - if(parts.length==1) - throw new CommandErrorException("Please include an action"+actions); - ActionType type = null; - for(ActionType t: ActionType.values()) - { - if(t.name().toLowerCase().replace("_", "").equals(parts[1].toLowerCase().replace("_", "").replace(" ", ""))) - { - type = t; - break; - } - } - if(type==null) - throw new CommandErrorException("Please include a valid action"+actions); - action = action.type(type); - break; - default: - throw new CommandErrorException("Valid subcommands:\n\n" - + "`" + event.getClient().getPrefix() + name + " all` - shows recent audit log entries\n" - + "`" + event.getClient().getPrefix() + name + " from ` - shows recent entries by a user\n" - + "`" + event.getClient().getPrefix() + name + " action ` shows recent entries of a certain action"); - } - event.getChannel().sendTyping().queue(); - action.queue(list -> - { - if(list.isEmpty()) - { - event.replyWarning("No audit log entries found matching your criteria"); - return; - } - EmbedBuilder eb = new EmbedBuilder().setColor(event.getSelfMember().getColor()); - list.forEach(ale -> - { - StringBuilder sb = new StringBuilder(); - sb.append(LINESTART).append("User: ").append(FormatUtil.formatFullUser(ale.getUser())); - switch(ale.getTargetType()) - { - case CHANNEL: - TextChannel tc = event.getGuild().getTextChannelById(ale.getTargetIdLong()); - sb.append("\n").append(LINESTART).append("Channel: ") - .append(tc==null ? UNKNOWN : "**#"+tc.getName()+"**") - .append(" (ID:").append(ale.getTargetId()).append(")"); - break; - case EMOTE: - Emote e = event.getGuild().getEmoteById(ale.getTargetIdLong()); - sb.append("\n").append(LINESTART).append("Emote: ") - .append(e==null ? UNKNOWN : e.getAsMention()) - .append(" (ID:").append(ale.getTargetId()).append(")"); - break; - case GUILD: - break; - case INVITE: - break; - case MEMBER: - User u = event.getJDA().getUserById(ale.getTargetIdLong()); - sb.append("\n").append(LINESTART).append("Member: ") - .append(u==null ? UNKNOWN : FormatUtil.formatUser(u)) - .append(" (ID:").append(ale.getTargetId()).append(")"); - break; - case ROLE: - Role r = event.getGuild().getRoleById(ale.getTargetIdLong()); - sb.append("\n").append(LINESTART).append("Role: ") - .append(r==null ? UNKNOWN : "**"+r.getName()+"**") - .append(" (ID:").append(ale.getTargetId()).append(")"); - break; - case WEBHOOK: - sb.append("\n").append(LINESTART).append("Webhook ID: ").append(ale.getTargetId()); - break; - case UNKNOWN: - default: - sb.append("\n").append(LINESTART).append("Target ID: ").append(ale.getTargetId()); - } - ale.getChanges().keySet().forEach(change -> - { - AuditLogChange alc = ale.getChangeByKey(change); - if(alc != null) - sb.append("\n").append(LINESTART).append(fixCase(change)).append(": ") - .append(alc.getOldValue()==null ? "" : "**"+alc.getOldValue()+"**") - .append(alc.getOldValue()==null || alc.getNewValue()==null ? "" : " → ") - .append(alc.getNewValue()==null ? "" : "**"+alc.getNewValue()+"**"); - }); - ale.getOptions().keySet().forEach(option -> - { - sb.append("\n").append(LINESTART).append(fixCase(option)).append(": ") - .append(ale.getOptionByName(option)==null ? UNKNOWN : "**"+ale.getOptionByName(option)+"**"); - }); - if(ale.getReason()!=null) - sb.append("\n").append(LINESTART).append("Reason: ").append(ale.getReason()); - sb.append("\n").append(LINESTART).append("Time: **").append(ale.getTimeCreated().format(DateTimeFormatter.RFC_1123_DATE_TIME)).append("**\n\u200B"); - String str = sb.length()>1024 ? sb.substring(0,1020)+" ..." : sb.toString(); - eb.addField(actionToEmote(ale.getType())+" "+fixCase(ale.getType().name()), str, true); - }); - event.reply(new MessageBuilder() - .setContent(event.getClient().getSuccess()+" Recent Audit Logs in **"+FormatUtil.filterEveryone(event.getGuild().getName())+"**:") - .setEmbed(eb.build()).build()); - }, f -> event.replyWarning("Failed to retrieve audit logs")); - } - - private String fixCase(String input) - { - String ret = ""; - for(int i=0; i"; - case KICK: return "<:DeleteUser:274789150920671232>"; - case UNBAN: return "<:Unban:274789150689984513>"; - case PRUNE: return "<:removeMember:417574812718858250>"; - - case CHANNEL_CREATE: return "<:addChannel:417574812425125888>"; - case CHANNEL_DELETE: return "<:deleteChannel:417574812622258186>"; - case CHANNEL_UPDATE: return "<:updateChannel:417574812240576514>"; - - case CHANNEL_OVERRIDE_CREATE: return "<:addChannel:417574812425125888>"; - case CHANNEL_OVERRIDE_DELETE: return "<:deleteChannel:417574812622258186>"; - case CHANNEL_OVERRIDE_UPDATE: return "<:updateChannel:417574812240576514>"; - - case EMOTE_CREATE: return "<:createEmoji:417574812689498112>"; - case EMOTE_DELETE: return "<:deleteEmoji:417574812521725962>"; - case EMOTE_UPDATE: return "<:updateEmoji:417574812601548800>"; - - case GUILD_UPDATE: return "<:updateServer:417574812534177793>"; - - case INVITE_CREATE: return "<:addInvite:417574812517662721>"; - case INVITE_DELETE: return "<:deleteInvite:417574812521725953>"; - case INVITE_UPDATE: return "<:updateInvite:417574812429320192>"; - - case MEMBER_ROLE_UPDATE: return "<:updateMember:417574812504948736>"; - case MEMBER_UPDATE: return "<:updateMember:417574812504948736>"; - - case MESSAGE_CREATE: return "<:createMessage:446853279926845452>"; - case MESSAGE_DELETE: return "<:deleteMessage:417574812399960065>"; - case MESSAGE_UPDATE: return "<:updateMessage:446853280308396032>"; - - case ROLE_CREATE: return "<:createRole:417574812399960075>"; - case ROLE_DELETE: return "<:deleteRole:417574812463136769>"; - case ROLE_UPDATE: return "<:updateRole:417574812165210126>"; - - case WEBHOOK_CREATE: return "<:createWebhook:417574812714532864>"; - case WEBHOOK_REMOVE: return "<:deleteWebhook:417574812098101250>"; - case WEBHOOK_UPDATE: return "<:updateWebhook:417574812534439946>"; - - case UNKNOWN: return "\u2753"; // ❓ - default: return "\u2753"; // ❓ - } - } -} diff --git a/src/main/java/com/jagrosh/vortex/commands/tools/ExportCmd.java b/src/main/java/com/jagrosh/vortex/commands/tools/ExportCmd.java index 1056fbe..bed5682 100644 --- a/src/main/java/com/jagrosh/vortex/commands/tools/ExportCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/tools/ExportCmd.java @@ -21,6 +21,7 @@ import com.jagrosh.vortex.database.Database; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Guild; +import com.jagrosh.jdautilities.command.CooldownScope; import org.json.JSONObject; /** @@ -61,6 +62,6 @@ .put("inviteWhitelist", db.inviteWhitelist.getWhitelistJson(g)) .put("filters", db.filters.getFiltersJson(g)) .put("premium", db.premium.getPremiumInfoJson(g)); - event.getChannel().sendFile(obj.toString(1).getBytes(), "vortex_data_" + g.getId() + ".json").queue(); + event.getChannel().asTextChannel().sendFile(obj.toString(1).getBytes(), "vortex_data_" + g.getId() + ".json").queue(); } } diff --git a/src/main/java/com/jagrosh/vortex/commands/tools/InvitepruneCmd.java b/src/main/java/com/jagrosh/vortex/commands/tools/InvitepruneCmd.java index f1900fd..5fbb7e3 100644 --- a/src/main/java/com/jagrosh/vortex/commands/tools/InvitepruneCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/tools/InvitepruneCmd.java @@ -83,7 +83,7 @@ private void pruneInvites(int uses, CommandEvent event) { - event.getChannel().sendTyping().queue(); + event.getChannel().asTextChannel().sendTyping().queue(); event.getGuild().retrieveInvites().queue(list -> { List toPrune = list.stream().filter(i -> i.getInviter()!=null && !i.getInviter().isBot() && i.getUses()<=uses).collect(Collectors.toList()); @@ -105,6 +105,6 @@ { if(re.getName().equals(CONFIRM)) confirm.run(); - }).build().display(event.getChannel()); + }).build().display(event.getChannel().asTextChannel()); } } diff --git a/src/main/java/com/jagrosh/vortex/commands/tools/LookupCmd.java b/src/main/java/com/jagrosh/vortex/commands/tools/LookupCmd.java deleted file mode 100644 index da25272..0000000 --- a/src/main/java/com/jagrosh/vortex/commands/tools/LookupCmd.java +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Copyright 2018 John Grosh (john.a.grosh@gmail.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://wwwidget.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.jagrosh.vortex.commands.tools; - -import com.jagrosh.jdautilities.command.Command; -import com.jagrosh.jdautilities.command.CommandEvent; -import com.jagrosh.vortex.Constants; -import com.jagrosh.vortex.Emoji; -import com.jagrosh.vortex.Vortex; -import com.jagrosh.vortex.automod.InviteResolver; -import com.jagrosh.vortex.database.managers.PremiumManager; -import com.jagrosh.vortex.utils.FormatUtil; -import com.jagrosh.vortex.utils.OtherUtil; -import java.time.format.DateTimeFormatter; -import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.MessageBuilder; -import net.dv8tion.jda.api.entities.ChannelType; -import net.dv8tion.jda.api.entities.Invite; -import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.User; -import net.dv8tion.jda.api.exceptions.RateLimitedException; -import net.dv8tion.jda.api.utils.TimeUtil; -import net.dv8tion.jda.api.utils.WidgetUtil; -import net.dv8tion.jda.api.utils.WidgetUtil.Widget; - -/** - * - * @author John Grosh (john.a.grosh@gmail.com) - */ -public class LookupCmd extends Command -{ - private final static String USER_EMOJI = "\uD83D\uDC64"; // 👤 - private final static String GUILD_EMOJI = "\uD83D\uDDA5"; // 🖥 - private final static String UNKNOWN_ID = "\uD83C\uDD94"; // 🆔 - private final static String LINESTART = "\u25AB"; // ▫ - - private final InviteResolver ir = new InviteResolver(); - private final Vortex vortex; - - public LookupCmd(Vortex vortex) - { - this.vortex = vortex; - this.name = "lookup"; - this.arguments = ""; - this.help = "finds information about a user or server"; - this.cooldown = 5; - this.category = new Category("Tools"); - } - - @Override - protected void execute(CommandEvent event) - { - if(event.isFromType(ChannelType.TEXT) && event.getMember().getRoles().isEmpty()) - { - event.reactError(); - return; - } - if(event.getArgs().isEmpty()) - { - event.replyError("Please provide a User ID, Server ID, or Invite Code\n" - + "This command provides information about a user or server. " - + "All of the information provided is information that Discord makes publically-available."); - return; - } - event.getChannel().sendTyping().queue(); - event.async(() -> - { - // determine if this is a valid ID - long id = -1; - try - { - id = Long.parseLong(event.getArgs()); - } - catch(NumberFormatException ignore) {} - - // if it's valid and we find a user, we're done - if(id > 0 && lookupUser(id, event)) - return; - - // require Vortex Plus for looking up guilds - if(!vortex.getDatabase().premium.getPremiumInfo(event.getGuild()).level.isAtLeast(PremiumManager.Level.PLUS)) - { - event.reply("No users found. Searching for guilds is not available here.\n" + PremiumManager.Level.PLUS.getRequirementMessage()); - return; - } - - // if valid id, use widget, otherwise try invite code - if(id > 0) - lookupGuild(id, event); - else - lookupGuild(extractCode(event.getArgs()), event); - }); - } - - private String extractCode(String args) - { - return args.substring(args.lastIndexOf("/")+1); - } - - private boolean lookupUser(long userId, CommandEvent event) - { - User u = vortex.getShardManager().getUserById(userId); - if(u==null) try - { - u = vortex.getShardManager().retrieveUserById(userId).complete(false); - } - catch(RateLimitedException ratelimited) - { - event.reactWarning(); - return true; - } - catch(Exception ignore) {} - if(u == null) - return false; - String text = (u.isBot() ? Emoji.BOT : USER_EMOJI) + " Information about **" + u.getName() + "**:"; - EmbedBuilder eb = new EmbedBuilder(); - eb.setThumbnail(u.getEffectiveAvatarUrl()); - StringBuilder str = new StringBuilder(LINESTART + "Discord ID: **" + u.getId() + "** "); - u.getFlags().forEach(flag -> str.append(OtherUtil.getEmoji(flag))); - if(u.getAvatarId() != null && u.getAvatarId().startsWith("a_")) - str.append(Emoji.BADGE_NITRO); - str.append("\n" + LINESTART + "Account Creation: **").append(TimeUtil.getDateTimeString(u.getTimeCreated())).append("**"); - eb.setDescription(str.toString()); - event.reply(new MessageBuilder().append(FormatUtil.filterEveryone(text)).setEmbeds(eb.build()).build()); - return true; - } - - private void lookupGuild(long guildId, CommandEvent event) - { - Invite invite = null; - Widget widget = null; - try - { - widget = WidgetUtil.getWidget(guildId); - } - catch(RateLimitedException ratelimited) - { - event.reactWarning(); - return; - } - catch(Exception ignore) {} - if(widget != null && widget.isAvailable()) - { - String invCode = widget.getInviteCode(); - if(invCode != null) - { - try - { - invite = ir.resolveFull(invCode, event.getJDA()); - } - catch(Exception ignore) {} - } - } - event.reply(constructMessage(invite, widget, guildId)); - } - - private void lookupGuild(String inviteCode, CommandEvent event) - { - Invite invite = null; - Widget widget = null; - try - { - invite = ir.resolveFull(inviteCode, event.getJDA()); - } - catch(Exception ex) - { - event.reactWarning(); - return; - } - if(invite != null) - { - Invite.Guild g = invite.getGuild(); - if(g != null) - { - try - { - widget = WidgetUtil.getWidget(g.getIdLong()); - } - catch(Exception ignore) {} - } - } - event.reply(constructMessage(invite, widget, 0)); - } - - private Message constructMessage(Invite invite, Widget widget, long input) - { - String gname = null; - long gid = 0L; - int users = -1; - if(invite == null) - { - if(widget == null) - { - if(input == 0) - return new MessageBuilder().append(Constants.ERROR + " No users, guilds, or invites found.").build(); - - return new MessageBuilder() - .append(UNKNOWN_ID + " Information about an unknown ID:") - .setEmbeds(new EmbedBuilder() - .appendDescription(LINESTART + "Creation: " + "**"+TimeUtil.getTimeCreated(input).format(DateTimeFormatter.RFC_1123_DATE_TIME)+"**").build()) - .build(); - } - - - gid = widget.getIdLong(); - if(widget.isAvailable()) - { - gname = widget.getName(); - users = widget.getMembers().size(); - } - } - else - { - Invite.Guild g = invite.getGuild(); - if(g != null) - { - gid = g.getIdLong(); - gname = g.getName(); - users = g.getOnlineCount(); - } - } - - String text = GUILD_EMOJI + " Information about " + (gname == null ? "an unknown guild" : "**"+gname+"**") + ":"; - EmbedBuilder eb = new EmbedBuilder(); - eb.appendDescription(LINESTART + "ID: " + (gid == 0 ? "N/A" : "**"+gid+"**") - + "\n" + LINESTART + "Creation: " + (gid == 0 ? "N/A" : "**"+TimeUtil.getTimeCreated(gid).format(DateTimeFormatter.RFC_1123_DATE_TIME)+"**") - + "\n" + LINESTART + "Users: " + (users == -1 ? "N/A" : "**" + users + "** online") - + (widget != null && widget.isAvailable() ? "\n" + LINESTART + "Channels: **" + widget.getVoiceChannels().size() + "** voice" : "")); - if(invite != null) - { - Invite.Guild g = invite.getGuild(); - eb.setThumbnail(g.getIconUrl()); - eb.setImage(g.getSplashId() == null ? null : g.getSplashUrl() + "?size=1024"); - eb.addField("Invite Info", LINESTART + "Invite: **" + invite.getCode() + "**" - + "\n" + LINESTART + "Channel: **" + (invite.getChannel().getType() == ChannelType.TEXT ? "#" : "") + invite.getChannel().getName() + "** (ID:" +invite.getChannel().getId() + ")" - + "\n" + LINESTART + "Inviter: " + (invite.getInviter() == null ? "N/A" : FormatUtil.formatFullUser(invite.getInviter())) - + (g.getSplashId() == null ? "" : "\n" + LINESTART + "Splash: "), false); - } - return new MessageBuilder().append(FormatUtil.filterEveryone(text)).setEmbeds(eb.build()).build(); - } -} diff --git a/src/main/java/com/jagrosh/vortex/commands/tools/LookupCmd.java.fucku b/src/main/java/com/jagrosh/vortex/commands/tools/LookupCmd.java.fucku new file mode 100644 index 0000000..d1f3ce6 --- /dev/null +++ b/src/main/java/com/jagrosh/vortex/commands/tools/LookupCmd.java.fucku @@ -0,0 +1,254 @@ +/* + * Copyright 2018 John Grosh (john.a.grosh@gmail.com). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://wwwidget.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jagrosh.vortex.commands.tools; + +import com.jagrosh.jdautilities.command.Command; +import com.jagrosh.jdautilities.command.CommandEvent; +import com.jagrosh.vortex.Constants; +import com.jagrosh.vortex.Emoji; +import com.jagrosh.vortex.Vortex; +import com.jagrosh.vortex.automod.InviteResolver; +import com.jagrosh.vortex.database.managers.PremiumManager; +import com.jagrosh.vortex.utils.FormatUtil; +import com.jagrosh.vortex.utils.OtherUtil; +import java.time.format.DateTimeFormatter; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; +import net.dv8tion.jda.api.entities.channel.ChannelType; +import net.dv8tion.jda.api.entities.Invite; +import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.exceptions.RateLimitedException; +import net.dv8tion.jda.api.utils.TimeUtil; +import net.dv8tion.jda.api.utils.WidgetUtil; +import net.dv8tion.jda.api.entities.GuildWidget; + +/** + * + * @author John Grosh (john.a.grosh@gmail.com) + */ +public class LookupCmd extends Command +{ + private final static String USER_EMOJI = "\uD83D\uDC64"; // 👤 + private final static String GUILD_EMOJI = "\uD83D\uDDA5"; // 🖥 + private final static String UNKNOWN_ID = "\uD83C\uDD94"; // 🆔 + private final static String LINESTART = "\u25AB"; // ▫ + + private final InviteResolver ir = new InviteResolver(); + private final Vortex vortex; + + public LookupCmd(Vortex vortex) + { + this.vortex = vortex; + this.name = "lookup"; + this.arguments = ""; + this.help = "finds information about a user or server"; + this.cooldown = 5; + this.category = new Category("Tools"); + } + + @Override + protected void execute(CommandEvent event) + { + if(event.isFromType(ChannelType.TEXT) && event.getMember().getRoles().isEmpty()) + { + event.reactError(); + return; + } + if(event.getArgs().isEmpty()) + { + event.replyError("Please provide a User ID, Server ID, or Invite Code\n" + + "This command provides information about a user or server. " + + "All of the information provided is information that Discord makes publically-available."); + return; + } + event.getChannel().asTextChannel().sendTyping().queue(); + event.async(() -> + { + // determine if this is a valid ID + long id = -1; + try + { + id = Long.parseLong(event.getArgs()); + } + catch(NumberFormatException ignore) {} + + // if it's valid and we find a user, we're done + if(id > 0 && lookupUser(id, event)) + return; + + // require Vortex Plus for looking up guilds + if(!vortex.getDatabase().premium.getPremiumInfo(event.getGuild()).level.isAtLeast(PremiumManager.Level.PLUS)) + { + event.reply("No users found. Searching for guilds is not available here.\n" + PremiumManager.Level.PLUS.getRequirementMessage()); + return; + } + + // if valid id, use widget, otherwise try invite code + if(id > 0) + lookupGuild(id, event); + else + lookupGuild(extractCode(event.getArgs()), event); + }); + } + + private String extractCode(String args) + { + return args.substring(args.lastIndexOf("/")+1); + } + + private boolean lookupUser(long userId, CommandEvent event) + { + User u = vortex.getShardManager().getUserById(userId); + if(u==null) try + { + u = vortex.getShardManager().retrieveUserById(userId).complete(false); + } + catch(RateLimitedException ratelimited) + { + event.reactWarning(); + return true; + } + catch(Exception ignore) {} + if(u == null) + return false; + String text = (u.isBot() ? Emoji.BOT : USER_EMOJI) + " Information about **" + u.getName() + "**:"; + EmbedBuilder eb = new EmbedBuilder(); + eb.setThumbnail(u.getEffectiveAvatarUrl()); + StringBuilder str = new StringBuilder(LINESTART + "Discord ID: **" + u.getId() + "** "); + u.getFlags().forEach(flag -> str.append(OtherUtil.getEmoji(flag))); + if(u.getAvatarId() != null && u.getAvatarId().startsWith("a_")) + str.append(Emoji.BADGE_NITRO); + str.append("\n" + LINESTART + "Account Creation: **").append(TimeUtil.getDateTimeString(u.getTimeCreated())).append("**"); + eb.setDescription(str.toString()); + event.reply(new MessageCreateBuilder().addContent(FormatUtil.filterEveryone(text)).setEmbeds(eb.build()).build()); + return true; + } + + private void lookupGuild(long guildId, CommandEvent event) + { + Invite invite = null; + GuildWidget widget = null; + try + { + widget = WidgetUtil.getWidget(guildId); + } + catch(RateLimitedException ratelimited) + { + event.reactWarning(); + return; + } + catch(Exception ignore) {} + if(widget != null && widget.isAvailable()) + { + String invCode = widget.getInviteCode(); + if(invCode != null) + { + try + { + invite = ir.resolveFull(invCode, event.getJDA()); + } + catch(Exception ignore) {} + } + } + event.reply(constructMessage(invite, widget, guildId)); + } + + private void lookupGuild(String inviteCode, CommandEvent event) + { + Invite invite = null; + GuildWidget widget = null; + try + { + invite = ir.resolveFull(inviteCode, event.getJDA()); + } + catch(Exception ex) + { + event.reactWarning(); + return; + } + if(invite != null) + { + Invite.Guild g = invite.getGuild(); + if(g != null) + { + try + { + widget = WidgetUtil.getWidget(g.getIdLong()); + } + catch(Exception ignore) {} + } + } + event.reply(constructMessage(invite, widget, 0)); + } + + private Message constructMessage(Invite invite, GuildWidget widget, long input) + { + String gname = null; + long gid = 0L; + int users = -1; + if(invite == null) + { + if(widget == null) + { + if(input == 0) + return new MessageCreateBuilder().addContent(Constants.ERROR + " No users, guilds, or invites found.").build(); + + return new MessageCreateBuilder() + .addContent(UNKNOWN_ID + " Information about an unknown ID:") + .setEmbeds(new EmbedBuilder() + .appendDescription(LINESTART + "Creation: " + "**"+TimeUtil.getTimeCreated(input).format(DateTimeFormatter.RFC_1123_DATE_TIME)+"**").build()) + .build(); + } + + + gid = widget.getIdLong(); + if(widget.isAvailable()) + { + gname = widget.getName(); + users = widget.getMembers().size(); + } + } + else + { + Invite.Guild g = invite.getGuild(); + if(g != null) + { + gid = g.getIdLong(); + gname = g.getName(); + users = g.getOnlineCount(); + } + } + + String text = GUILD_EMOJI + " Information about " + (gname == null ? "an unknown guild" : "**"+gname+"**") + ":"; + EmbedBuilder eb = new EmbedBuilder(); + eb.appendDescription(LINESTART + "ID: " + (gid == 0 ? "N/A" : "**"+gid+"**") + + "\n" + LINESTART + "Creation: " + (gid == 0 ? "N/A" : "**"+TimeUtil.getTimeCreated(gid).format(DateTimeFormatter.RFC_1123_DATE_TIME)+"**") + + "\n" + LINESTART + "Users: " + (users == -1 ? "N/A" : "**" + users + "** online") + + (widget != null && widget.isAvailable() ? "\n" + LINESTART + "Channels: **" + widget.getVoiceChannels().size() + "** voice" : "")); + if(invite != null) + { + Invite.Guild g = invite.getGuild(); + eb.setThumbnail(g.getIconUrl()); + eb.setImage(g.getSplashId() == null ? null : g.getSplashUrl() + "?size=1024"); + eb.addField("Invite Info", LINESTART + "Invite: **" + invite.getCode() + "**" + + "\n" + LINESTART + "Channel: **" + (invite.getChannel().getType() == ChannelType.TEXT ? "#" : "") + invite.getChannel().getName() + "** (ID:" +invite.getChannel().getId() + ")" + + "\n" + LINESTART + "Inviter: " + (invite.getInviter() == null ? "N/A" : FormatUtil.formatFullUser(invite.getInviter())) + + (g.getSplashId() == null ? "" : "\n" + LINESTART + "Splash: "), false); + } + return new MessageCreateBuilder().addContent(FormatUtil.filterEveryone(text)).setEmbeds(eb.build()).build(); + } +} diff --git a/src/main/java/com/jagrosh/vortex/database/managers/GuildSettingsDataManager.java b/src/main/java/com/jagrosh/vortex/database/managers/GuildSettingsDataManager.java index 02006a3..5708109 100644 --- a/src/main/java/com/jagrosh/vortex/database/managers/GuildSettingsDataManager.java +++ b/src/main/java/com/jagrosh/vortex/database/managers/GuildSettingsDataManager.java @@ -33,7 +33,7 @@ import net.dv8tion.jda.api.entities.Guild.VerificationLevel; import net.dv8tion.jda.api.entities.MessageEmbed.Field; import net.dv8tion.jda.api.entities.Role; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import org.json.JSONObject; /** diff --git a/src/main/java/com/jagrosh/vortex/database/managers/IgnoreManager.java b/src/main/java/com/jagrosh/vortex/database/managers/IgnoreManager.java index 94d0d38..66a2e88 100644 --- a/src/main/java/com/jagrosh/vortex/database/managers/IgnoreManager.java +++ b/src/main/java/com/jagrosh/vortex/database/managers/IgnoreManager.java @@ -29,7 +29,7 @@ import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Role; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import org.json.JSONArray; /** diff --git a/src/main/java/com/jagrosh/vortex/database/managers/TempBanManager.java b/src/main/java/com/jagrosh/vortex/database/managers/TempBanManager.java index 5cab81a..b7f8dd4 100644 --- a/src/main/java/com/jagrosh/vortex/database/managers/TempBanManager.java +++ b/src/main/java/com/jagrosh/vortex/database/managers/TempBanManager.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -29,6 +29,7 @@ import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.User; import org.json.JSONObject; /** @@ -120,9 +121,9 @@ Guild g = shards.getGuildById(GUILD_ID.getValue(rs)); if(g==null || g.getMemberCache().isEmpty() || !g.getSelfMember().hasPermission(Permission.BAN_MEMBERS)) continue; - g.unban(Long.toString(USER_ID.getValue(rs))).reason("Temporary Ban Completed").queue(s->{}, f->{}); + g.unban(User.fromId(Long.toString(USER_ID.getValue(rs)))).reason("Temporary Ban Completed").queue(s->{}, f->{}); rs.deleteRow(); } }); } -} +} \ No newline at end of file diff --git a/src/main/java/com/jagrosh/vortex/database/managers/TempSlowmodeManager.java b/src/main/java/com/jagrosh/vortex/database/managers/TempSlowmodeManager.java index 1d605e3..4340d78 100644 --- a/src/main/java/com/jagrosh/vortex/database/managers/TempSlowmodeManager.java +++ b/src/main/java/com/jagrosh/vortex/database/managers/TempSlowmodeManager.java @@ -25,7 +25,7 @@ import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Guild; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import org.json.JSONObject; import java.time.Instant; diff --git a/src/main/java/com/jagrosh/vortex/logging/BasicLogger.java b/src/main/java/com/jagrosh/vortex/logging/BasicLogger.java index ab1df6e..040f871 100644 --- a/src/main/java/com/jagrosh/vortex/logging/BasicLogger.java +++ b/src/main/java/com/jagrosh/vortex/logging/BasicLogger.java @@ -29,14 +29,14 @@ import java.util.List; import java.util.stream.Collectors; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.MessageBuilder; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.channel.concrete.*; import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.utils.FileUpload; import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent; import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent; -import net.dv8tion.jda.api.events.guild.voice.GuildVoiceJoinEvent; -import net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent; -import net.dv8tion.jda.api.events.guild.voice.GuildVoiceMoveEvent; +import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent; import net.dv8tion.jda.api.events.user.update.UserUpdateAvatarEvent; import net.dv8tion.jda.api.events.user.update.UserUpdateDiscriminatorEvent; import net.dv8tion.jda.api.events.user.update.UserUpdateNameEvent; @@ -82,9 +82,9 @@ try { usage.increment(tc.getGuild().getIdLong()); - tc.sendMessage(new MessageBuilder() - .append(FormatUtil.filterEveryone(LogUtil.basiclogFormat(now, vortex.getDatabase().settings.getSettings(tc.getGuild()).getTimezone(), emote, message))) - .setEmbed(embed) + tc.sendMessage(new MessageCreateBuilder() + .addContent(FormatUtil.filterEveryone(LogUtil.basiclogFormat(now, vortex.getDatabase().settings.getSettings(tc.getGuild()).getTimezone(), emote, message))) + .setEmbeds(embed) .build()).queue(); } catch(PermissionException ignore) {} @@ -95,8 +95,10 @@ try { usage.increment(tc.getGuild().getIdLong()); - tc.sendMessage(FormatUtil.filterEveryone(LogUtil.basiclogFormat(now, vortex.getDatabase().settings.getSettings(tc.getGuild()).getTimezone(), emote, message))) - .addFile(file, filename).queue(); + tc.sendMessage(new MessageCreateBuilder() + .addContent(FormatUtil.filterEveryone(LogUtil.basiclogFormat(now, vortex.getDatabase().settings.getSettings(tc.getGuild()).getTimezone(), emote, message))) + .addFiles(FileUpload.fromData(file, filename)) + .build()).queue(); } catch(PermissionException ignore) {} } @@ -126,7 +128,7 @@ else edit.appendDescription("\n**To:** "+newm); log(newMessage.getTimeEdited()==null ? newMessage.getTimeCreated(): newMessage.getTimeEdited(), tc, EDIT, - FormatUtil.formatFullUser(newMessage.getAuthor())+" edited a message in "+newMessage.getTextChannel().getAsMention()+":", edit.build()); + FormatUtil.formatFullUser(newMessage.getAuthor())+" edited a message in "+newMessage.getChannel().asTextChannel().getAsMention()+":", edit.build()); } public void logMessageDelete(CachedMessage oldMessage) @@ -200,7 +202,7 @@ for(int i=0; i [Donations]("+Constants.DONATION_LINK+")"; } -} +} \ No newline at end of file diff --git a/src/main/java/com/jagrosh/vortex/utils/LogUtil.java b/src/main/java/com/jagrosh/vortex/utils/LogUtil.java index f105360..2fac782 100644 --- a/src/main/java/com/jagrosh/vortex/utils/LogUtil.java +++ b/src/main/java/com/jagrosh/vortex/utils/LogUtil.java @@ -27,7 +27,7 @@ import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.sharding.ShardManager; @@ -119,7 +119,7 @@ public static String logMessagesForwards(String title, List messages) { - TextChannel deltc = messages.get(0).getTextChannel(); + TextChannel deltc = messages.get(0).getChannel().asTextChannel(); Guild delg = messages.get(0).getGuild(); StringBuilder sb = new StringBuilder("-- "+title+" -- #"+deltc.getName()+" ("+deltc.getId()+") -- "+delg.getName()+" ("+delg.getId()+") --"); Message m; @@ -150,7 +150,7 @@ public static String logMessagesBackwards(String title, List messages) { - TextChannel deltc = messages.get(0).getTextChannel(); + TextChannel deltc = messages.get(0).getChannel().asTextChannel(); Guild delg = messages.get(0).getGuild(); StringBuilder sb = new StringBuilder("-- "+title+" -- #"+deltc.getName()+" ("+deltc.getId()+") -- "+delg.getName()+" ("+delg.getId()+") --"); Message m; diff --git a/src/main/java/com/jagrosh/vortex/utils/OtherUtil.java b/src/main/java/com/jagrosh/vortex/utils/OtherUtil.java index 9a2cd68..41e1f42 100644 --- a/src/main/java/com/jagrosh/vortex/utils/OtherUtil.java +++ b/src/main/java/com/jagrosh/vortex/utils/OtherUtil.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -154,4 +154,4 @@ default: return "\u2753"; } } -} +} \ No newline at end of file