diff --git a/src/main/java/com/jagrosh/vortex/Vortex.java b/src/main/java/com/jagrosh/vortex/Vortex.java index e31d2c9..5e175ba 100644 --- a/src/main/java/com/jagrosh/vortex/Vortex.java +++ b/src/main/java/com/jagrosh/vortex/Vortex.java @@ -45,8 +45,6 @@ import com.typesafe.config.ConfigFactory; import java.util.Arrays; import java.util.concurrent.TimeUnit; -import net.dv8tion.jda.api.JDA; -import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.entities.Activity; import net.dv8tion.jda.api.entities.ChannelType; import net.dv8tion.jda.api.entities.Message; @@ -54,6 +52,7 @@ import net.dv8tion.jda.api.requests.restaction.MessageAction; import net.dv8tion.jda.api.sharding.DefaultShardManagerBuilder; import net.dv8tion.jda.api.sharding.ShardManager; +import net.dv8tion.jda.api.utils.MemberCachePolicy; import net.dv8tion.jda.api.utils.cache.CacheFlag; /** @@ -74,24 +73,22 @@ private final AutoMod automod; private final StrikeHandler strikehandler; private final CommandExceptionListener listener; - private final JDA altBot; public Vortex() throws Exception { System.setProperty("config.file", System.getProperty("config.file", "application.conf")); Config config = ConfigFactory.load(); - altBot = new JDABuilder(config.getString("alt-token")).build(); waiter = new EventWaiter(Executors.newSingleThreadScheduledExecutor(), false); threadpool = Executors.newScheduledThreadPool(100); database = new Database(config.getString("database.host"), config.getString("database.username"), config.getString("database.password")); - uploader = new TextUploader(altBot, config.getLong("uploader.guild"), config.getLong("uploader.category")); + uploader = new TextUploader(config.getStringList("upload-webhooks")); modlog = new ModLogger(this); basiclog = new BasicLogger(this, config); messages = new MessageCache(); logwebhook = new WebhookClientBuilder(config.getString("webhook-url")).build(); - automod = new AutoMod(this, altBot, config); + automod = new AutoMod(this, config); strikehandler = new StrikeHandler(this); listener = new CommandExceptionListener(); CommandClient client = new CommandClientBuilder() @@ -186,21 +183,22 @@ //.setCarbonitexKey(config.getString("listing.carbon")) .build(); MessageAction.setDefaultMentions(Arrays.asList(Message.MentionType.EMOTE, Message.MentionType.CHANNEL)); - shards = DefaultShardManagerBuilder.createDefault(config.getString("bot-token"), Constants.INTENTS) + shards = DefaultShardManagerBuilder.create(config.getString("bot-token"), Constants.INTENTS) + .setMemberCachePolicy(MemberCachePolicy.ALL) + .enableCache(CacheFlag.MEMBER_OVERRIDES, CacheFlag.VOICE_STATE) + .disableCache(CacheFlag.EMOTE, CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS) .setShardsTotal(config.getInt("shards-total")) .addEventListeners(new Listener(this), client, waiter) .setStatus(OnlineStatus.DO_NOT_DISTURB) .setActivity(Activity.playing("loading...")) .setBulkDeleteSplittingEnabled(false) .setRequestTimeoutRetry(true) - .disableCache(CacheFlag.EMOTE, CacheFlag.ACTIVITY) .build(); modlog.start(); threadpool.scheduleWithFixedDelay(() -> cleanPremium(), 0, 2, TimeUnit.HOURS); threadpool.scheduleWithFixedDelay(() -> leavePointlessGuilds(), 5, 30, TimeUnit.MINUTES); - threadpool.scheduleWithFixedDelay(() -> System.gc(), 12, 6, TimeUnit.HOURS); } @@ -282,7 +280,7 @@ { shards.getGuilds().stream().filter(g -> { - if(!g.isAvailable()) + if(!g.isLoaded()) return false; if(Constants.OWNER_ID.equals(g.getOwnerId())) return false; diff --git a/src/main/java/com/jagrosh/vortex/automod/AutoMod.java b/src/main/java/com/jagrosh/vortex/automod/AutoMod.java index ec95853..91fad03 100644 --- a/src/main/java/com/jagrosh/vortex/automod/AutoMod.java +++ b/src/main/java/com/jagrosh/vortex/automod/AutoMod.java @@ -69,16 +69,15 @@ private String[] refLinkList; private final URLResolver urlResolver; - private final InviteResolver 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<>(); private final Usage usage = new Usage(); - public AutoMod(Vortex vortex, JDA altBot, Config config) + public AutoMod(Vortex vortex, Config config) { this.vortex = vortex; - this.inviteResolver = new InviteResolver(altBot); this.urlResolver = config.getBoolean("url-resolver.active") ? new ActiveURLResolver(config) : new DummyURLResolver(); loadCopypastas(); loadReferralDomains(); @@ -432,7 +431,7 @@ for(String inviteCode : invites) { LOG.info("Resolving invite in " + message.getGuild().getId() + ": " + inviteCode); - long gid = inviteResolver.resolve(inviteCode); + long gid = inviteResolver.resolve(inviteCode, message.getJDA()); if(gid != message.getGuild().getIdLong() && !inviteWhitelist.contains(gid)) { strikeTotal += settings.inviteStrikes; @@ -491,7 +490,7 @@ { String code = resolved.replaceAll(INVITE_LINK, "$1"); LOG.info("Delayed resolving invite in " + message.getGuild().getId() + ": " + code); - long invite = inviteResolver.resolve(code); + long invite = inviteResolver.resolve(code, message.getJDA()); if(invite != message.getGuild().getIdLong() && !inviteWhitelist.contains(invite)) containsInvite = true; } diff --git a/src/main/java/com/jagrosh/vortex/automod/InviteResolver.java b/src/main/java/com/jagrosh/vortex/automod/InviteResolver.java index 4de347e..5d9d135 100644 --- a/src/main/java/com/jagrosh/vortex/automod/InviteResolver.java +++ b/src/main/java/com/jagrosh/vortex/automod/InviteResolver.java @@ -27,23 +27,17 @@ */ public class InviteResolver { - private final JDA altBot; private final Logger log = LoggerFactory.getLogger(InviteResolver.class); private final FixedCache cached = new FixedCache<>(5000); - public InviteResolver(JDA altBot) - { - this.altBot = altBot; - } - - public long resolve(String code) + public long resolve(String code, JDA jda) { log.debug("Attempting to resolve " + code); if(cached.contains(code)) return cached.get(code); try { - Invite i = Invite.resolve(altBot, code).complete(false); + Invite i = Invite.resolve(jda, code).complete(false); cached.put(code, i.getGuild().getIdLong()); return i.getGuild().getIdLong(); } diff --git a/src/main/java/com/jagrosh/vortex/commands/ModCommand.java b/src/main/java/com/jagrosh/vortex/commands/ModCommand.java index 9fcbadd..b17b69b 100644 --- a/src/main/java/com/jagrosh/vortex/commands/ModCommand.java +++ b/src/main/java/com/jagrosh/vortex/commands/ModCommand.java @@ -19,6 +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.Role; /** @@ -32,9 +33,10 @@ public ModCommand(Vortex vortex, Permission... altPerms) { this.vortex = vortex; + this.guildOnly = true; this.category = new Category("Moderation", event -> { - if(event.getGuild()==null) + if(event.getChannelType() != ChannelType.TEXT) { event.replyError("This command is not available in Direct Messages!"); return false; 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 60d5449..8c5bba3 100644 --- a/src/main/java/com/jagrosh/vortex/commands/general/AboutCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/general/AboutCmd.java @@ -25,6 +25,7 @@ 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; /** @@ -48,7 +49,7 @@ event.reply(new MessageBuilder() .setContent(Constants.VORTEX_EMOJI + " **All about Vortex** " + Constants.VORTEX_EMOJI) .setEmbed(new EmbedBuilder() - .setColor(event.getGuild()==null ? Color.GRAY : event.getSelfMember().getColor()) + .setColor(!event.isFromType(ChannelType.TEXT) ? Color.GRAY : event.getSelfMember().getColor()) .setDescription("Hello, I am **Vortex**#8540, a bot designed to keep your server safe and make moderating fast and easy!\n" + "I was written in Java by **jagrosh**#4824 using [JDA](" + JDAInfo.GITHUB + ") and [JDA-Utilities](" + JDAUtilitiesInfo.GITHUB + ")\n" + "Type `" + event.getClient().getPrefix() + event.getClient().getHelpWord() + "` for help and information.\n\n" 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 68b3898..765fe6b 100644 --- a/src/main/java/com/jagrosh/vortex/commands/general/UserinfoCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/general/UserinfoCmd.java @@ -20,6 +20,7 @@ import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.commons.utils.FinderUtil; import com.jagrosh.vortex.utils.FormatUtil; +import com.jagrosh.vortex.utils.OtherUtil; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -79,34 +80,35 @@ } User user = member.getUser(); String title = (user.isBot() ? BOT_EMOJI : USER_EMOJI)+" Information about **"+user.getName()+"** #"+user.getDiscriminator()+":"; - String str = LINESTART+"Discord ID: **"+user.getId()+"**"+(user.getAvatarId()!=null && user.getAvatarId().startsWith("a_")?" <:nitro:314068430611415041>":""); + StringBuilder str = new StringBuilder(LINESTART + "Discord ID: **" + user.getId() + "** "); + user.getFlags().forEach(flag -> str.append(OtherUtil.getEmoji(flag))); if(member.getNickname()!=null) - str+="\n"+LINESTART+"Nickname: **"+member.getNickname()+"**"; + str.append("\n" + LINESTART + "Nickname: **").append(member.getNickname()).append("**"); String roles=""; roles = member.getRoles().stream().map((rol) -> "`, `"+rol.getName()).reduce(roles, String::concat); if(roles.isEmpty()) roles="None"; else roles=roles.substring(3)+"`"; - str+="\n"+LINESTART+"Roles: "+roles; - str+="\n"+LINESTART+"Status: "+statusToEmote(member.getOnlineStatus(), member.getActivities())+"**"+member.getOnlineStatus().name()+"**"; - Activity game = member.getActivities().isEmpty() ? null : member.getActivities().get(0); - if(game!=null) - str+=" ("+formatGame(game)+")"; - str+="\n"+LINESTART+"Account Creation: **"+user.getTimeCreated().format(DateTimeFormatter.RFC_1123_DATE_TIME)+"**"; + 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()); Collections.sort(joins, (Member a, Member b) -> a.getTimeJoined().compareTo(b.getTimeJoined())); int index = joins.indexOf(member); - str+="\n"+LINESTART+"Guild Join Date: **"+member.getTimeJoined().format(DateTimeFormatter.RFC_1123_DATE_TIME) + "** `(#"+(index+1)+")`"; + str.append("\n" + LINESTART + "Guild Join Date: **").append(member.getTimeJoined().format(DateTimeFormatter.RFC_1123_DATE_TIME)).append("** `(#").append(index).append(1).append(")`"); index-=3; if(index<0) index=0; - str+="\n"+LINESTART+"Join Order: "; + str.append("\n"+LINESTART+"Join Order: "); if(joins.get(index).equals(member)) - str+="[**"+joins.get(index).getUser().getName()+"**]()"; + str.append("[**").append(joins.get(index).getUser().getName()).append("**]()"); else - str+=joins.get(index).getUser().getName(); + str.append(joins.get(index).getUser().getName()); for(int i=index+1;i=joins.size()) @@ -115,13 +117,13 @@ String uname = m.getUser().getName(); if(m.equals(member)) uname="[**"+uname+"**]()"; - str+=" > "+uname; + str.append(" > ").append(uname); } event.reply(new MessageBuilder() .append(FormatUtil.filterEveryone(title)) .setEmbed(new EmbedBuilder() - .setDescription(str) + .setDescription(str.toString()) .setThumbnail(user.getEffectiveAvatarUrl()) .setColor(member.getColor()).build()) .build()); 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 0048356..9b052d3 100644 --- a/src/main/java/com/jagrosh/vortex/commands/moderation/BanCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/moderation/BanCmd.java @@ -46,7 +46,6 @@ this.arguments = "<@users> [time] [reason]"; this.help = "bans users"; this.botPermissions = new Permission[]{Permission.BAN_MEMBERS}; - this.guildOnly = true; } @Override 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 d3dd86c..f4a169f 100644 --- a/src/main/java/com/jagrosh/vortex/commands/moderation/CheckCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/moderation/CheckCmd.java @@ -40,7 +40,6 @@ this.name = "check"; this.arguments = ""; this.help = "checks a user"; - this.guildOnly = true; this.botPermissions = new Permission[]{Permission.BAN_MEMBERS}; } 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 ff47690..5dd4e78 100644 --- a/src/main/java/com/jagrosh/vortex/commands/moderation/CleanCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/moderation/CleanCmd.java @@ -71,7 +71,6 @@ this.arguments = ""; this.help = "cleans messages matching filters"; this.botPermissions = new Permission[]{Permission.MESSAGE_MANAGE, Permission.MESSAGE_HISTORY}; - this.guildOnly = true; this.cooldown = 10; this.cooldownScope = CooldownScope.CHANNEL; } 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 002fd55..16a5096 100644 --- a/src/main/java/com/jagrosh/vortex/commands/moderation/KickCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/moderation/KickCmd.java @@ -40,7 +40,6 @@ this.arguments = "<@users> [reason]"; this.help = "kicks users"; this.botPermissions = new Permission[]{Permission.KICK_MEMBERS}; - this.guildOnly = true; } @Override diff --git a/src/main/java/com/jagrosh/vortex/commands/moderation/MuteCmd.java b/src/main/java/com/jagrosh/vortex/commands/moderation/MuteCmd.java index 0893b67..401679c 100644 --- a/src/main/java/com/jagrosh/vortex/commands/moderation/MuteCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/moderation/MuteCmd.java @@ -43,7 +43,6 @@ this.arguments = "<@users> [time] [reason]"; this.help = "applies muted role to users"; this.botPermissions = new Permission[]{Permission.MANAGE_ROLES}; - this.guildOnly = true; } @Override diff --git a/src/main/java/com/jagrosh/vortex/commands/moderation/PardonCmd.java b/src/main/java/com/jagrosh/vortex/commands/moderation/PardonCmd.java index 9d975f6..1480eb5 100644 --- a/src/main/java/com/jagrosh/vortex/commands/moderation/PardonCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/moderation/PardonCmd.java @@ -35,7 +35,6 @@ this.name = "pardon"; this.arguments = "[numstrikes] <@users> "; this.help = "removes strikes from users"; - this.guildOnly = true; } @Override diff --git a/src/main/java/com/jagrosh/vortex/commands/moderation/ReasonCmd.java b/src/main/java/com/jagrosh/vortex/commands/moderation/ReasonCmd.java index e728dea..b6eb1a7 100644 --- a/src/main/java/com/jagrosh/vortex/commands/moderation/ReasonCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/moderation/ReasonCmd.java @@ -32,7 +32,6 @@ this.name = "reason"; this.help = "updates a modlog reason"; this.arguments = "[case] "; - this.guildOnly = true; } @Override 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 ed38e77..48139fe 100644 --- a/src/main/java/com/jagrosh/vortex/commands/moderation/SoftbanCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/moderation/SoftbanCmd.java @@ -41,7 +41,6 @@ this.arguments = "<@users> [reason]"; this.help = "bans and unbans users"; this.botPermissions = new Permission[]{Permission.BAN_MEMBERS}; - this.guildOnly = true; } @Override diff --git a/src/main/java/com/jagrosh/vortex/commands/moderation/StrikeCmd.java b/src/main/java/com/jagrosh/vortex/commands/moderation/StrikeCmd.java index 358a61e..4de0acf 100644 --- a/src/main/java/com/jagrosh/vortex/commands/moderation/StrikeCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/moderation/StrikeCmd.java @@ -40,7 +40,6 @@ this.name = "strike"; this.arguments = "[number] <@users> "; this.help = "applies strikes to users"; - this.guildOnly = true; } @Override diff --git a/src/main/java/com/jagrosh/vortex/commands/moderation/UnbanCmd.java b/src/main/java/com/jagrosh/vortex/commands/moderation/UnbanCmd.java index cca6430..85c10b0 100644 --- a/src/main/java/com/jagrosh/vortex/commands/moderation/UnbanCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/moderation/UnbanCmd.java @@ -40,7 +40,6 @@ this.arguments = "<@users> [reason]"; this.help = "unbans users"; this.botPermissions = new Permission[]{Permission.BAN_MEMBERS}; - this.guildOnly = true; } @Override diff --git a/src/main/java/com/jagrosh/vortex/commands/moderation/UnmuteCmd.java b/src/main/java/com/jagrosh/vortex/commands/moderation/UnmuteCmd.java index 4469dfd..092a5d9 100644 --- a/src/main/java/com/jagrosh/vortex/commands/moderation/UnmuteCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/moderation/UnmuteCmd.java @@ -40,7 +40,6 @@ this.arguments = "<@users> [reason]"; this.help = "removes muted role from users"; this.botPermissions = new Permission[]{Permission.MANAGE_ROLES}; - this.guildOnly = true; } @Override diff --git a/src/main/java/com/jagrosh/vortex/commands/moderation/VoicekickCmd.java b/src/main/java/com/jagrosh/vortex/commands/moderation/VoicekickCmd.java index db37434..3221bff 100644 --- a/src/main/java/com/jagrosh/vortex/commands/moderation/VoicekickCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/moderation/VoicekickCmd.java @@ -42,7 +42,6 @@ this.arguments = "<@users> [reason]"; this.help = "removes users from voice channels"; this.botPermissions = new Permission[]{Permission.MANAGE_CHANNEL}; - this.guildOnly = true; } @Override diff --git a/src/main/java/com/jagrosh/vortex/commands/moderation/VoicemoveCmd.java b/src/main/java/com/jagrosh/vortex/commands/moderation/VoicemoveCmd.java index 547e1c9..ae181d8 100644 --- a/src/main/java/com/jagrosh/vortex/commands/moderation/VoicemoveCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/moderation/VoicemoveCmd.java @@ -39,7 +39,6 @@ this.aliases = new String[]{"magnet"}; this.help = "mass-moves voice channel users"; this.arguments = "[channel]"; - this.guildOnly = true; } @Override 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 1dc6f6b..ecf9ac9 100644 --- a/src/main/java/com/jagrosh/vortex/commands/tools/AnnounceCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/tools/AnnounceCmd.java @@ -22,8 +22,10 @@ import com.jagrosh.vortex.commands.CommandExceptionListener.CommandErrorException; import com.jagrosh.vortex.commands.CommandExceptionListener.CommandWarningException; import com.jagrosh.vortex.utils.FormatUtil; +import java.util.EnumSet; import java.util.List; 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; @@ -82,9 +84,7 @@ if(parts2.length<2 || parts2[1].isEmpty()) throw new CommandErrorException(FORMAT); - String message = role.getAsMention()+": "+parts2[1]; - if(!event.getMember().hasPermission(tc, Permission.MESSAGE_MENTION_EVERYONE)) - message = FormatUtil.filterEveryone(message); + String message = role.getAsMention()+": " + FormatUtil.filterEveryone(parts2[1]); if(message.length() > 2000) message = message.substring(0, 2000); String fmessage = message; @@ -93,7 +93,7 @@ String reason = "Announcement by "+event.getAuthor().getName()+"#"+event.getAuthor().getDiscriminator(); role.getManager().setMentionable(true).reason(reason).queue(s -> { - tc.sendMessage(fmessage).queue(m -> + tc.sendMessage(fmessage).allowedMentions(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/LookupCmd.java b/src/main/java/com/jagrosh/vortex/commands/tools/LookupCmd.java index 7ae19ac..94f6727 100644 --- a/src/main/java/com/jagrosh/vortex/commands/tools/LookupCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/tools/LookupCmd.java @@ -21,6 +21,7 @@ import com.jagrosh.vortex.Vortex; 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; @@ -89,7 +90,7 @@ // require Vortex Plus for looking up guilds if(!vortex.getDatabase().premium.getPremiumInfo(event.getGuild()).level.isAtLeast(PremiumManager.Level.PLUS)) { - event.reply(PremiumManager.Level.PLUS.getRequirementMessage()); + event.reply("No users found. Searching for guilds is not available here.\n" + PremiumManager.Level.PLUS.getRequirementMessage()); return; } @@ -124,11 +125,10 @@ String text = (u.isBot() ? BOT_EMOJI : USER_EMOJI) + " Information about **" + u.getName() + "**#" + u.getDiscriminator() + ":"; EmbedBuilder eb = new EmbedBuilder(); eb.setThumbnail(u.getEffectiveAvatarUrl()); - String str = LINESTART + "Discord ID: **" + u.getId() + "**"; - if(u.getAvatarId() != null && u.getAvatarId().startsWith("a_")) - str+= " <:nitro:314068430611415041>"; - str += "\n" + LINESTART + "Account Creation: **" + TimeUtil.getDateTimeString(u.getTimeCreated()) + "**"; - eb.setDescription(str); + StringBuilder str = new StringBuilder(LINESTART + "Discord ID: **" + u.getId() + "** "); + u.getFlags().forEach(flag -> str.append(OtherUtil.getEmoji(flag))); + str.append("\n" + LINESTART + "Account Creation: **").append(TimeUtil.getDateTimeString(u.getTimeCreated())).append("**"); + eb.setDescription(str.toString()); event.reply(new MessageBuilder().append(FormatUtil.filterEveryone(text)).setEmbed(eb.build()).build()); return true; } diff --git a/src/main/java/com/jagrosh/vortex/database/managers/PremiumManager.java b/src/main/java/com/jagrosh/vortex/database/managers/PremiumManager.java index 56cfd41..f9b8125 100644 --- a/src/main/java/com/jagrosh/vortex/database/managers/PremiumManager.java +++ b/src/main/java/com/jagrosh/vortex/database/managers/PremiumManager.java @@ -172,7 +172,7 @@ public String getRequirementMessage() { - return Constants.WARNING + " Sorry, this feature requires " + name + ". " + name + " is not available yet."; + return Constants.WARNING + " Sorry, this feature requires Vortex Pro. Vortex Pro is not available yet."; } } @@ -196,7 +196,7 @@ public String getFooterString() { if(level==Level.NONE) - return "This server does does not have Vortex Plus or Vortex Pro"; + return "This server does does not have Vortex Pro"; if(until.getEpochSecond()==Instant.MAX.getEpochSecond()) return "This server has " + level.name + " permanently"; return "This server has " + level.name + " until"; diff --git a/src/main/java/com/jagrosh/vortex/logging/TextUploader.java b/src/main/java/com/jagrosh/vortex/logging/TextUploader.java index 24332de..f3c9160 100644 --- a/src/main/java/com/jagrosh/vortex/logging/TextUploader.java +++ b/src/main/java/com/jagrosh/vortex/logging/TextUploader.java @@ -15,12 +15,12 @@ */ package com.jagrosh.vortex.logging; +import club.minnced.discord.webhook.WebhookClient; +import club.minnced.discord.webhook.WebhookClientBuilder; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; import java.util.List; -import net.dv8tion.jda.api.JDA; -import net.dv8tion.jda.api.entities.Category; -import net.dv8tion.jda.api.entities.Guild; -import net.dv8tion.jda.api.entities.TextChannel; +import java.util.function.BiConsumer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,30 +37,28 @@ * message logs. */ private final Logger LOG = LoggerFactory.getLogger("Upload"); - private final JDA altBot; - private final long categoryId; - private final long guildId; + private final List webhooks = new ArrayList<>(); private int index = 0; - public TextUploader(JDA altBot, long guildId, long categoryId) + public TextUploader(List urls) { - this.altBot = altBot; - this.guildId = guildId; - this.categoryId = categoryId; + urls.forEach(url -> webhooks.add(new WebhookClientBuilder(url).build())); } - public void upload(String content, String filename, Result done) + public synchronized void upload(String content, String filename, BiConsumer done) { - Guild guild = altBot.getGuildById(guildId); - if(guild==null) - return; - Category category = guild.getCategoryById(categoryId); - List list = category.getTextChannels(); - list.get(index % list.size()).sendFile(content.getBytes(StandardCharsets.UTF_8), filename+".txt", null).queue( - m -> done.consume( - "https://txt.discord.website?txt="+m.getAttachments().get(0).getUrl().substring(m.getAttachments().get(0).getUrl().indexOf("s/")+2, m.getAttachments().get(0).getUrl().length()-4), - m.getAttachments().get(0).getUrl()), - f -> LOG.error("Failed to upload: "+f)); + webhooks.get(index % webhooks.size()).send(content.getBytes(StandardCharsets.UTF_8), filename+".txt").whenCompleteAsync((msg, err) -> + { + if(msg != null) + { + String url = msg.getAttachments().get(0).getUrl(); + done.accept("https://txt.discord.website?txt=" + url.substring(url.indexOf("s/")+2, url.length()-4), url); + } + else if(err != null) + { + LOG.error("Failed to upload: ", err); + } + }); index++; } diff --git a/src/main/java/com/jagrosh/vortex/utils/OtherUtil.java b/src/main/java/com/jagrosh/vortex/utils/OtherUtil.java index 1acf3d3..a0b6721 100644 --- a/src/main/java/com/jagrosh/vortex/utils/OtherUtil.java +++ b/src/main/java/com/jagrosh/vortex/utils/OtherUtil.java @@ -23,6 +23,7 @@ import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.User.UserFlag; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -124,4 +125,26 @@ return new String[0]; } } + + public static String getEmoji(UserFlag flag) + { + switch(flag) + { + case BUG_HUNTER_LEVEL_1: return "<:bughunter:585765206769139723>"; + case BUG_HUNTER_LEVEL_2: return "<:bughunter:585765206769139723>"; + case EARLY_SUPPORTER: return "<:supporter:585763690868113455>"; + case HYPESQUAD: return "<:hypesquad_events:585765895939424258>"; + case HYPESQUAD_BALANCE: return "<:balance:585763004574859273>"; + case HYPESQUAD_BRAVERY: return "<:bravery:585763004218343426>"; + case HYPESQUAD_BRILLIANCE: return "<:brilliance:585763004495298575>"; + case PARTNER: return "<:partner:314068430556758017>"; + case STAFF: return "<:staff:314068430787706880>"; + case SYSTEM: return "<:system:738519297265106954>"; + case TEAM_USER: return "\u2753"; + case UNKNOWN: return "\u2753"; + case VERIFIED_BOT: return "<:verified_bot:738519297265238057>"; + case VERIFIED_DEVELOPER: return "<:badgeVerifiedDev:698313392728834049>"; + default: return "\u2753"; + } + } }