diff --git a/lists/copypastas.txt b/lists/copypastas.txt index afbc771..bb30d4a 100644 --- a/lists/copypastas.txt +++ b/lists/copypastas.txt @@ -25,4 +25,5 @@ Shrek || years old && is love && is life && spread && push against && straight in the // Scams -Fake Libra Site || getlⅰbra.tech \ No newline at end of file +Fake Libra Site || getlⅰbra.tech +Fake Libra Site (2) || buylⅰbra.τech diff --git a/src/main/java/com/jagrosh/vortex/Constants.java b/src/main/java/com/jagrosh/vortex/Constants.java index 96dfc7c..67ced9e 100644 --- a/src/main/java/com/jagrosh/vortex/Constants.java +++ b/src/main/java/com/jagrosh/vortex/Constants.java @@ -44,10 +44,11 @@ // public final static String BOT_INVITE = "https://discordapp.com/oauth2/authorize?client_id=169463754382114816&scope=bot&permissions="+Permission.getRaw(PERMISSIONS); public final static String OWNER_ID = "113156185389092864"; public final static String DONATION_LINK = "https://patreon.com/jagrosh"; - public final static String NEED_PRO = WARNING + " Sorry, this feature requires Vortex Pro. Vortex Pro is not available yet."; public final static class Wiki { + public final static String PRIMARY_LINK = "https://jagrosh.com/vortex"; + public final static String SHORT_WIKI = "https://git.io/fxHam"; public final static String SHORT_COMMANDS = "https://git.io/vAr0G"; diff --git a/src/main/java/com/jagrosh/vortex/Vortex.java b/src/main/java/com/jagrosh/vortex/Vortex.java index 10c7afd..ae81aac 100644 --- a/src/main/java/com/jagrosh/vortex/Vortex.java +++ b/src/main/java/com/jagrosh/vortex/Vortex.java @@ -46,6 +46,8 @@ import com.typesafe.config.ConfigFactory; import java.util.EnumSet; 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.exceptions.PermissionException; @@ -71,27 +73,29 @@ 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(50); + threadpool = Executors.newScheduledThreadPool(100); database = new Database(config.getString("database.host"), config.getString("database.username"), config.getString("database.password")); - uploader = new TextUploader(this, config.getLong("uploader.guild"), config.getLong("uploader.category")); + uploader = new TextUploader(altBot, config.getLong("uploader.guild"), config.getLong("uploader.category")); modlog = new ModLogger(this); basiclog = new BasicLogger(this, config); messages = new MessageCache(); logwebhook = new WebhookClientBuilder(config.getString("webhook-url")).build(); - automod = new AutoMod(this, config); + automod = new AutoMod(this, altBot, config); strikehandler = new StrikeHandler(this); listener = new CommandExceptionListener(); CommandClient client = new CommandClientBuilder() .setPrefix(Constants.PREFIX) - .setActivity(Activity.playing(Constants.Wiki.SHORT_WIKI)) + .setActivity(Activity.playing(Constants.Wiki.PRIMARY_LINK)) .setOwnerId(Constants.OWNER_ID) .setServerInvite(Constants.SERVER_INVITE) .setEmojis(Constants.SUCCESS, Constants.WARNING, Constants.ERROR) @@ -268,6 +272,7 @@ { database.automod.setResolveUrls(gid, false); database.settings.setAvatarLogChannel(gid, null); + database.settings.setVoiceLogChannel(gid, null); database.filters.deleteAllFilters(gid); }); } diff --git a/src/main/java/com/jagrosh/vortex/automod/AutoMod.java b/src/main/java/com/jagrosh/vortex/automod/AutoMod.java index 500bcac..43be3d7 100644 --- a/src/main/java/com/jagrosh/vortex/automod/AutoMod.java +++ b/src/main/java/com/jagrosh/vortex/automod/AutoMod.java @@ -37,6 +37,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; +import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.entities.Guild.VerificationLevel; @@ -68,16 +69,17 @@ private String[] refLinkList; private final URLResolver urlResolver; - private final InviteResolver inviteResolver = new InviteResolver(); + private final InviteResolver 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, Config config) + public AutoMod(Vortex vortex, JDA altBot, Config config) { this.vortex = vortex; - urlResolver = config.getBoolean("url-resolver.active") ? new ActiveURLResolver(config) : new DummyURLResolver(); + this.inviteResolver = new InviteResolver(altBot); + this.urlResolver = config.getBoolean("url-resolver.active") ? new ActiveURLResolver(config) : new DummyURLResolver(); loadCopypastas(); loadReferralDomains(); } @@ -432,7 +434,7 @@ for(String inviteCode : invites) { LOG.info("Resolving invite in " + message.getGuild().getId() + ": " + inviteCode); - long gid = inviteResolver.resolve(message.getJDA(), inviteCode); + long gid = inviteResolver.resolve(inviteCode); if(gid != message.getGuild().getIdLong() && !inviteWhitelist.contains(gid)) { strikeTotal += settings.inviteStrikes; @@ -491,7 +493,7 @@ { String code = resolved.replaceAll(INVITE_LINK, "$1"); LOG.info("Delayed resolving invite in " + message.getGuild().getId() + ": " + code); - long invite = inviteResolver.resolve(message.getJDA(), code); + long invite = inviteResolver.resolve(code); 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 54d3a6e..4de347e 100644 --- a/src/main/java/com/jagrosh/vortex/automod/InviteResolver.java +++ b/src/main/java/com/jagrosh/vortex/automod/InviteResolver.java @@ -27,17 +27,23 @@ */ public class InviteResolver { + private final JDA altBot; private final Logger log = LoggerFactory.getLogger(InviteResolver.class); private final FixedCache cached = new FixedCache<>(5000); - public long resolve(JDA jda, String code) + public InviteResolver(JDA altBot) + { + this.altBot = altBot; + } + + public long resolve(String code) { log.debug("Attempting to resolve " + code); if(cached.contains(code)) return cached.get(code); try { - Invite i = Invite.resolve(jda, code).complete(false); + Invite i = Invite.resolve(altBot, code).complete(false); cached.put(code, i.getGuild().getIdLong()); return i.getGuild().getIdLong(); } diff --git a/src/main/java/com/jagrosh/vortex/commands/automod/FilterCmd.java b/src/main/java/com/jagrosh/vortex/commands/automod/FilterCmd.java index 15238b9..a1536fc 100644 --- a/src/main/java/com/jagrosh/vortex/commands/automod/FilterCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/automod/FilterCmd.java @@ -81,7 +81,7 @@ { if(!vortex.getDatabase().premium.getPremiumInfo(event.getGuild()).level.isAtLeast(PremiumManager.Level.PRO)) { - event.reply(Constants.NEED_PRO); + event.reply(PremiumManager.Level.PRO.getRequirementMessage()); return; } diff --git a/src/main/java/com/jagrosh/vortex/commands/automod/ResolvelinksCmd.java b/src/main/java/com/jagrosh/vortex/commands/automod/ResolvelinksCmd.java index 709f605..30b2d7f 100644 --- a/src/main/java/com/jagrosh/vortex/commands/automod/ResolvelinksCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/automod/ResolvelinksCmd.java @@ -53,7 +53,7 @@ event.replySuccess("Link Resolving has been turned `"+event.getArgs().toUpperCase()+"`"); } else - event.reply(Constants.NEED_PRO); + event.reply(PremiumManager.Level.PRO.getRequirementMessage()); } else { diff --git a/src/main/java/com/jagrosh/vortex/commands/owner/ExportCmd.java b/src/main/java/com/jagrosh/vortex/commands/owner/ExportCmd.java new file mode 100644 index 0000000..11210bd --- /dev/null +++ b/src/main/java/com/jagrosh/vortex/commands/owner/ExportCmd.java @@ -0,0 +1,59 @@ +/* + * Copyright 2020 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.owner; + +import com.jagrosh.jdautilities.command.Command; +import com.jagrosh.jdautilities.command.CommandEvent; +import com.jagrosh.vortex.Vortex; +import net.dv8tion.jda.api.Permission; +import org.json.JSONObject; + +/** + * + * @author John Grosh (john.a.grosh@gmail.com) + */ +public class ExportCmd extends Command +{ + private final Vortex vortex; + + public ExportCmd(Vortex vortex) + { + this.vortex = vortex; + this.name = "export"; + this.arguments = ""; + this.help = "exports all server data as json"; + this.category = new Category("Tools"); + this.userPermissions = new Permission[]{Permission.MESSAGE_ATTACH_FILES}; + this.ownerCommand = true; + } + + @Override + protected void execute(CommandEvent event) + { + long gid; + try + { + gid = Long.parseLong(event.getArgs()); + } + catch(NumberFormatException ex) + { + event.reactError(); + return; + } + JSONObject obj = new JSONObject(); + + } +} 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 ce0fdec..dfd61a1 100644 --- a/src/main/java/com/jagrosh/vortex/commands/settings/AvatarlogCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/settings/AvatarlogCmd.java @@ -58,6 +58,6 @@ event.replySuccess("Avatar Logs will now be sent in "+tc.getAsMention()); } else - event.reply(Constants.NEED_PRO); + event.reply(PremiumManager.Level.PRO.getRequirementMessage()); } } 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 8b62082..0a14abc 100644 --- a/src/main/java/com/jagrosh/vortex/commands/settings/VoicelogCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/settings/VoicelogCmd.java @@ -18,6 +18,7 @@ import com.jagrosh.jdautilities.command.CommandEvent; 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; /** @@ -47,10 +48,15 @@ @Override protected void setLogChannel(CommandEvent event, TextChannel tc) { - vortex.getDatabase().settings.setVoiceLogChannel(event.getGuild(), tc); - if(tc==null) - event.replySuccess("Voice Logs will not be sent"); + if(vortex.getDatabase().premium.getPremiumInfo(event.getGuild()).level.isAtLeast(PremiumManager.Level.PLUS)) + { + vortex.getDatabase().settings.setVoiceLogChannel(event.getGuild(), tc); + if(tc==null) + event.replySuccess("Voice Logs will not be sent"); + else + event.replySuccess("Voice Logs will now be sent in "+tc.getAsMention()); + } else - event.replySuccess("Voice Logs will now be sent in "+tc.getAsMention()); + event.reply(PremiumManager.Level.PLUS.getRequirementMessage()); } } 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 d5e3dcd..fae7945 100644 --- a/src/main/java/com/jagrosh/vortex/commands/tools/InvitepruneCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/tools/InvitepruneCmd.java @@ -18,7 +18,6 @@ import com.jagrosh.jdautilities.command.Command; import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.menu.ButtonMenu; -import com.jagrosh.vortex.Constants; import com.jagrosh.vortex.Vortex; import com.jagrosh.vortex.commands.CommandExceptionListener.CommandErrorException; import com.jagrosh.vortex.commands.CommandExceptionListener.CommandWarningException; 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 dd69e91..380afa2 100644 --- a/src/main/java/com/jagrosh/vortex/commands/tools/LookupCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/tools/LookupCmd.java @@ -17,20 +17,21 @@ import com.jagrosh.jdautilities.command.Command; import com.jagrosh.jdautilities.command.CommandEvent; +import com.jagrosh.vortex.Constants; import com.jagrosh.vortex.Vortex; +import com.jagrosh.vortex.database.managers.PremiumManager; import com.jagrosh.vortex.utils.FormatUtil; 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.MiscUtil; +import net.dv8tion.jda.api.utils.TimeUtil; import net.dv8tion.jda.api.utils.WidgetUtil; import net.dv8tion.jda.api.utils.WidgetUtil.Widget; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * @@ -43,9 +44,7 @@ private final static String GUILD_EMOJI = "\uD83D\uDDA5"; // 🖥 private final static String LINESTART = "\u25AB"; // ▫ - private final Logger log = LoggerFactory.getLogger(LookupCmd.class); private final Vortex vortex; - private boolean debug = true; public LookupCmd(Vortex vortex) { @@ -73,124 +72,173 @@ return; } event.getChannel().sendTyping().queue(); - log.info(event.getGuild().getId() + " - " + event.getMember().getUser().getId() + ": " + event.getMessage().getContentRaw()); - if(debug && event.getGuild().getMemberById(113156185389092864L)==null && event.getGuild().getMemberById(194257036828082176L)==null) - { - event.reactError(); - return; - } event.async(() -> { + // determine if this is a valid ID + long id = -1; try { - long id = Long.parseLong(event.getArgs()); - User u = vortex.getShardManager().getUserById(id); - if(u==null) try - { - u = event.getJDA().retrieveUserById(id).complete(); - } - catch(Exception ignore) {} - if(u!=null) - { - 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: **"+u.getTimeCreated().format(DateTimeFormatter.RFC_1123_DATE_TIME)+"**"; - eb.setDescription(str); - event.reply(new MessageBuilder().append(FormatUtil.filterEveryone(text)).setEmbed(eb.build()).build()); - return; - } - - Widget widget = WidgetUtil.getWidget(id); - if(widget!=null) - { - if(!widget.isAvailable()) - { - event.replySuccess("Guild with ID `"+id+"` found; no further information found."); - return; - } - Invite inv = null; - if(widget.getInviteCode()!=null) - { - try - { - inv = Invite.resolve(event.getJDA(), widget.getInviteCode()).complete(); - } - catch(Exception ignore){} - } - String text = GUILD_EMOJI + " Information about **"+widget.getName()+"**:"; - EmbedBuilder eb = new EmbedBuilder(); - String str = LINESTART+"ID: **"+widget.getId()+"**\n" - +LINESTART+"Creation: **"+widget.getTimeCreated().format(DateTimeFormatter.RFC_1123_DATE_TIME)+"**\n" - +LINESTART+"Channels: **"+widget.getVoiceChannels().size()+"** Voice\n" - +LINESTART+"Users: **"+widget.getMembers().size()+"** online\n"; - if(inv!=null) - { - eb.setThumbnail(inv.getGuild().getIconUrl()); - str+=LINESTART+"Invite: **"+inv.getCode()+"** "+(inv.getChannel().getType()==ChannelType.TEXT - ? "#"+inv.getChannel().getName() : inv.getChannel().getName())+" (ID:"+inv.getChannel().getId()+")"; - - if(inv.getGuild().getSplashId()!=null) - { - str += "\n"+LINESTART+"Splash: "; - eb.setImage(inv.getGuild().getSplashUrl()+"?size=1024"); - } - } - eb.setDescription(str); - event.reply(new MessageBuilder().append(FormatUtil.filterEveryone(text)).setEmbed(eb.build()).build()); - return; - } + id = Long.parseLong(event.getArgs()); } catch(NumberFormatException ignore) {} - catch(RateLimitedException ex) + + // 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.reactWarning(); + event.reply(PremiumManager.Level.PLUS.getRequirementMessage()); return; } - catch(Exception ex) - { - ex.printStackTrace(); - } - String code = event.getArgs().substring(event.getArgs().indexOf("/")+1); - Invite inv = null; - try - { - inv = Invite.resolve(event.getJDA(), code).complete(); - } - catch(Exception ignore){} - if(inv==null) - { - event.replyError("No users, guilds, or invites found."); - return; - } - Widget widget = null; - try - { - widget = WidgetUtil.getWidget(inv.getGuild().getIdLong()); - } - catch(RateLimitedException ignore) {} - String text = GUILD_EMOJI + " Information about Invite Code **"+code+"**:"; - EmbedBuilder eb = new EmbedBuilder(); - eb.setThumbnail(inv.getGuild().getIconUrl()); - String str = LINESTART+"Guild: **"+inv.getGuild().getName()+"**\n" - + LINESTART+"Channel: **"+(inv.getChannel().getType()==ChannelType.TEXT?"#":"")+inv.getChannel().getName()+"** (ID:"+inv.getChannel().getId()+")\n" - + LINESTART+"Inviter: "+(inv.getInviter()==null?"N/A":"**"+inv.getInviter().getName()+"**#"+inv.getInviter().getDiscriminator()+" (ID:"+inv.getInviter().getId()+")"); - eb.setDescription(str); - str = LINESTART+"ID: **"+inv.getGuild().getId()+"**\n" - +LINESTART+"Creation: **"+inv.getGuild().getTimeCreated().format(DateTimeFormatter.RFC_1123_DATE_TIME)+"**\n"; - if(widget!=null && widget.isAvailable()) - str += LINESTART+"Channels: **"+widget.getVoiceChannels().size()+"** Voice\n" - +LINESTART+"Users: **"+widget.getMembers().size()+"** online"; - if(inv.getGuild().getSplashId()!=null) - { - str += "\n"+LINESTART+"Splash: "; - eb.setImage(inv.getGuild().getSplashUrl()+"?size=1024"); - } - eb.addField("Guild Info", str, false); - event.reply(new MessageBuilder().append(FormatUtil.filterEveryone(text)).setEmbed(eb.build()).build()); + + // 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.indexOf("/")+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() ? 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); + event.reply(new MessageBuilder().append(FormatUtil.filterEveryone(text)).setEmbed(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 = Invite.resolve(event.getJDA(), invCode, true).complete(false); + } + catch(Exception ignore) {} + } + } + event.reply(constructMessage(invite, widget)); + } + + private void lookupGuild(String inviteCode, CommandEvent event) + { + Invite invite = null; + Widget widget = null; + try + { + invite = Invite.resolve(event.getJDA(), inviteCode, true).complete(false); + } + catch(RateLimitedException ratelimited) + { + event.reactWarning(); + return; + } + catch(Exception ignore) {} + 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)); + } + + private Message constructMessage(Invite invite, Widget widget) + { + String gname; + long gid; + int users; + if(invite == null) + { + if(widget == null) + return new MessageBuilder().append(Constants.ERROR + " No users, guilds, or invites found.").build(); + else if (!widget.isAvailable()) + return new MessageBuilder().append(Constants.SUCCESS + " Guild with ID `" + widget.getId() + "` found; no further information found.").build(); + gid = widget.getIdLong(); + gname = widget.getName(); + users = widget.getMembers().size(); + } + else + { + Invite.Guild g = invite.getGuild(); + if(g == null) + { + gid = 0L; + gname = "Unknown Guild"; + users = 0; + } + else + { + gid = g.getIdLong(); + gname = g.getName(); + users = g.getOnlineCount(); + } + } + + String text = GUILD_EMOJI + " Information about **" + gname + "**:"; + EmbedBuilder eb = new EmbedBuilder(); + eb.appendDescription(LINESTART + "ID: **" + gid + "**" + + "\n" + LINESTART + "Creation: **" + 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(invite.getGuild().getIconUrl()); + eb.setImage(invite.getGuild().getSplashId() == null ? null : invite.getGuild().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())) + + (invite.getGuild().getSplashId() == null ? "" : "\n" + LINESTART + "Splash: "), false); + } + return new MessageBuilder().append(FormatUtil.filterEveryone(text)).setEmbed(eb.build()).build(); + } +} \ No newline at end of file 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 6b97446..8b0500a 100644 --- a/src/main/java/com/jagrosh/vortex/database/managers/GuildSettingsDataManager.java +++ b/src/main/java/com/jagrosh/vortex/database/managers/GuildSettingsDataManager.java @@ -171,8 +171,13 @@ public void setVoiceLogChannel(Guild guild, TextChannel tc) { - invalidateCache(guild); - readWrite(select(GUILD_ID.is(guild.getIdLong()), GUILD_ID, VOICELOG_ID), rs -> + setVoiceLogChannel(guild.getIdLong(), tc); + } + + public void setVoiceLogChannel(long guildId, TextChannel tc) + { + invalidateCache(guildId); + readWrite(select(GUILD_ID.is(guildId), GUILD_ID, VOICELOG_ID), rs -> { if(rs.next()) { @@ -182,7 +187,7 @@ else { rs.moveToInsertRow(); - GUILD_ID.updateValue(rs, guild.getIdLong()); + GUILD_ID.updateValue(rs, guildId); VOICELOG_ID.updateValue(rs, tc==null ? 0L : tc.getIdLong()); rs.insertRow(); } 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 d34e679..8eaf834 100644 --- a/src/main/java/com/jagrosh/vortex/database/managers/PremiumManager.java +++ b/src/main/java/com/jagrosh/vortex/database/managers/PremiumManager.java @@ -19,12 +19,14 @@ import com.jagrosh.easysql.DatabaseConnector; import com.jagrosh.easysql.SQLColumn; import com.jagrosh.easysql.columns.*; +import com.jagrosh.vortex.Constants; import java.sql.ResultSet; import java.sql.SQLException; import java.time.Instant; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.time.temporal.TemporalUnit; +import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import net.dv8tion.jda.api.entities.Guild; @@ -37,7 +39,7 @@ { public static final SQLColumn GUILD_ID = new LongColumn("GUILD_ID", false, 0L, true); public static final SQLColumn UNTIL = new InstantColumn("UNTIL", false, Instant.EPOCH); - public static final SQLColumn LEVEL = new IntegerColumn("LEVEL", false, 1); + public static final SQLColumn LEVEL = new IntegerColumn("LEVEL", false, 0); private final PremiumInfo NO_PREMIUM = new PremiumInfo(); @@ -46,6 +48,17 @@ super(connector, "PREMIUM"); } + public List getPremiumGuilds() + { + return read(selectAll(LEVEL.isGreaterThan(-1)), rs -> + { + List list = new ArrayList<>(); + while(rs.next()) + list.add(GUILD_ID.getValue(rs)); + return list; + }); + } + public PremiumInfo getPremiumInfo(Guild guild) { return read(selectAll(GUILD_ID.is(guild.getIdLong())), rs -> @@ -132,7 +145,7 @@ public static enum Level { NONE("No Premium"), - BASIC("Vortex Basic"), + PLUS("Vortex Plus"), PRO("Vortex Pro"), ULTRA("Vortex Ultra"); @@ -147,6 +160,11 @@ { return ordinal() >= other.ordinal(); } + + public String getRequirementMessage() + { + return Constants.WARNING + " Sorry, this feature requires " + name + ". " + name + " is not available yet."; + } } public class PremiumInfo @@ -169,10 +187,10 @@ public String getFooterString() { if(level==Level.NONE) - return "This server does not have Vortex Pro"; + return "This server does does not have Vortex Plus or Vortex Pro"; if(until.getEpochSecond()==Instant.MAX.getEpochSecond()) - return "This server has "+level.name+" permanently"; - return "This server has "+level.name+" until"; + return "This server has " + level.name + " permanently"; + return "This server has " + level.name + " until"; } public Instant getTimestamp() diff --git a/src/main/java/com/jagrosh/vortex/database/managers/StrikeManager.java b/src/main/java/com/jagrosh/vortex/database/managers/StrikeManager.java index 9af8e04..29e9a2a 100644 --- a/src/main/java/com/jagrosh/vortex/database/managers/StrikeManager.java +++ b/src/main/java/com/jagrosh/vortex/database/managers/StrikeManager.java @@ -19,6 +19,8 @@ import com.jagrosh.easysql.DatabaseConnector; import com.jagrosh.easysql.SQLColumn; import com.jagrosh.easysql.columns.*; +import java.util.HashMap; +import java.util.Map; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; @@ -66,34 +68,6 @@ }); } - /*public int[] setStrikes(Member target, int strikes) - { - return setStrikes(target.getGuild(), target.getUser().getIdLong(), strikes); - } - - public int[] setStrikes(Guild guild, long targetId, int strikes) - { - return readWrite(selectAll(GUILD_ID.is(guild.getId())+" AND "+USER_ID.is(targetId)), rs -> - { - if(rs.next()) - { - int current = STRIKES.getValue(rs); - STRIKES.updateValue(rs, strikes<0 ? 0 : strikes); - rs.updateRow(); - return new int[]{current, strikes<0 ? 0 : strikes}; - } - else - { - rs.moveToInsertRow(); - GUILD_ID.updateValue(rs, guild.getIdLong()); - USER_ID.updateValue(rs, targetId); - STRIKES.updateValue(rs, strikes<0 ? 0 : strikes); - rs.insertRow(); - return new int[]{0, strikes<0 ? 0 : strikes}; - } - }); - }//*/ - public int[] removeStrikes(Member target, int strikes) { return removeStrikes(target.getGuild(), target.getUser().getIdLong(), strikes); @@ -118,4 +92,20 @@ return 0; }); } + + public Map getAllStrikes(Guild guild) + { + return getAllStrikes(guild.getIdLong()); + } + + public Map getAllStrikes(long guildId) + { + return read(selectAll(GUILD_ID.is(guildId)), rs -> + { + HashMap map = new HashMap<>(); + while(rs.next()) + map.put(USER_ID.getValue(rs), STRIKES.getValue(rs)); + return map; + }); + } } diff --git a/src/main/java/com/jagrosh/vortex/logging/ModLogger.java b/src/main/java/com/jagrosh/vortex/logging/ModLogger.java index f4cce32..ab69863 100644 --- a/src/main/java/com/jagrosh/vortex/logging/ModLogger.java +++ b/src/main/java/com/jagrosh/vortex/logging/ModLogger.java @@ -77,9 +77,18 @@ } if(!toUpdate.isEmpty()) { + LOG.info("DEBUG Modlog updating " + toUpdate.size() + " guilds: " + toUpdate.toString()); try { - toUpdate.forEach(gid -> update(vortex.getShardManager().getGuildById(gid), 40)); + long time, diff; + for(long gid: toUpdate) + { + time = System.currentTimeMillis(); + update(vortex.getShardManager().getGuildById(gid), 40); + diff = System.currentTimeMillis() - time; + if(diff > 10000) + LOG.warn("Took " + diff + "ms to update " + gid); + } } catch(Exception ex) { LOG.error("Exception thrown during modlog update loop: "+ex); diff --git a/src/main/java/com/jagrosh/vortex/logging/TextUploader.java b/src/main/java/com/jagrosh/vortex/logging/TextUploader.java index c58646c..24332de 100644 --- a/src/main/java/com/jagrosh/vortex/logging/TextUploader.java +++ b/src/main/java/com/jagrosh/vortex/logging/TextUploader.java @@ -15,9 +15,9 @@ */ package com.jagrosh.vortex.logging; -import com.jagrosh.vortex.Vortex; import java.nio.charset.StandardCharsets; 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; @@ -37,21 +37,21 @@ * message logs. */ private final Logger LOG = LoggerFactory.getLogger("Upload"); - private final Vortex vortex; + private final JDA altBot; private final long categoryId; private final long guildId; private int index = 0; - public TextUploader(Vortex vortex, long guildId, long categoryId) + public TextUploader(JDA altBot, long guildId, long categoryId) { - this.vortex = vortex; + this.altBot = altBot; this.guildId = guildId; this.categoryId = categoryId; } public void upload(String content, String filename, Result done) { - Guild guild = vortex.getShardManager().getGuildById(guildId); + Guild guild = altBot.getGuildById(guildId); if(guild==null) return; Category category = guild.getCategoryById(categoryId); diff --git a/src/main/resources/reference.conf b/src/main/resources/reference.conf index ac45c92..1103102 100644 --- a/src/main/resources/reference.conf +++ b/src/main/resources/reference.conf @@ -1,6 +1,7 @@ bot-token = "" shards-total = 0 webhook-url = "" +alt-token = "" database { host = ""