Skip to content

Commit

Permalink
Merge branch 'master' into feature/jda4
Browse files Browse the repository at this point in the history
  • Loading branch information
jagrosh committed May 13, 2020
2 parents e2b8bbc + fe7cac7 commit bf71f6c
Show file tree
Hide file tree
Showing 18 changed files with 321 additions and 171 deletions.
3 changes: 2 additions & 1 deletion lists/copypastas.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ Rick & Morty || have to have a very high IQ && extremely && solid grasp && deftl
Shrek || years old && is love && is life && spread && push against && straight in the

// Scams
Fake Libra Site || getlⅰbra.tech
Fake Libra Site || getlⅰbra.tech
Fake Libra Site (2) || buylⅰbra.τech
3 changes: 2 additions & 1 deletion src/main/java/com/jagrosh/vortex/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ public class Constants
// 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";

Expand Down
13 changes: 9 additions & 4 deletions src/main/java/com/jagrosh/vortex/Vortex.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -71,27 +73,29 @@ public class Vortex
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)
Expand Down Expand Up @@ -268,6 +272,7 @@ public void cleanPremium()
{
database.automod.setResolveUrls(gid, false);
database.settings.setAvatarLogChannel(gid, null);
database.settings.setVoiceLogChannel(gid, null);
database.filters.deleteAllFilters(gid);
});
}
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/jagrosh/vortex/automod/AutoMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,16 +69,17 @@ public class AutoMod

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<String,DupeStatus> spams = new FixedCache<>(3000);
private final HashMap<Long,OffsetDateTime> 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();
}
Expand Down Expand Up @@ -432,7 +434,7 @@ else if(offenses>settings.dupeDeleteThresh)
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;
Expand Down Expand Up @@ -491,7 +493,7 @@ else if(offenses>settings.dupeDeleteThresh)
{
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;
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/jagrosh/vortex/automod/InviteResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,23 @@
*/
public class InviteResolver
{
private final JDA altBot;
private final Logger log = LoggerFactory.getLogger(InviteResolver.class);
private final FixedCache<String,Long> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected void execute(CommandEvent event)
{
if(!vortex.getDatabase().premium.getPremiumInfo(event.getGuild()).level.isAtLeast(PremiumManager.Level.PRO))
{
event.reply(Constants.NEED_PRO);
event.reply(PremiumManager.Level.PRO.getRequirementMessage());
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected void execute(CommandEvent event)
event.replySuccess("Link Resolving has been turned `"+event.getArgs().toUpperCase()+"`");
}
else
event.reply(Constants.NEED_PRO);
event.reply(PremiumManager.Level.PRO.getRequirementMessage());
}
else
{
Expand Down
59 changes: 59 additions & 0 deletions src/main/java/com/jagrosh/vortex/commands/owner/ExportCmd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2020 John Grosh ([email protected]).
*
* 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 ([email protected])
*/
public class ExportCmd extends Command
{
private final Vortex vortex;

public ExportCmd(Vortex vortex)
{
this.vortex = vortex;
this.name = "export";
this.arguments = "<serverid>";
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();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ protected void setLogChannel(CommandEvent event, TextChannel tc)
event.replySuccess("Avatar Logs will now be sent in "+tc.getAsMention());
}
else
event.reply(Constants.NEED_PRO);
event.reply(PremiumManager.Level.PRO.getRequirementMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -47,10 +48,15 @@ protected void showCurrentChannel(CommandEvent event)
@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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit bf71f6c

Please sign in to comment.