Skip to content

Commit

Permalink
fixed typo
Browse files Browse the repository at this point in the history
updated server info
args uses set internally to prevent duplicates
prevent shutdowns so shards can be restarted
  • Loading branch information
jagrosh committed Aug 18, 2018
1 parent 010697e commit 7cf2d82
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 41 deletions.
11 changes: 11 additions & 0 deletions lists/referral_domains.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@

// IP Loggers
iplogger.com
iplogger.org
iplogger.ru
blasze.tk
ps3cfw.com
2no.co
yip.su
gotyouripboi.com

// Grabify (IP Loggers)
grabify.link
Expand All @@ -24,6 +29,11 @@ starbucksisbadforyou.com
bucks.as
discörd.com
minecräft.com
discördapp.com
freegiftcards.co
disçordapp.com
särahah.eu
särahah.pl
shört.co
cyberh1.xyz

Expand All @@ -50,6 +60,7 @@ featu.re
pointsprizes.com
weeklyjob.online
justdoit.cards
free.gg

// Scams
oprewards.com
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>3.7.0_384</version>
<version>3.7.1_395</version>
</dependency>
<dependency>
<groupId>com.jagrosh</groupId>
<artifactId>jda-utilities</artifactId>
<version>2.1.1</version>
<version>2.1.4</version>
<type>pom</type>
</dependency>
<dependency>
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/com/jagrosh/vortex/Vortex.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import net.dv8tion.jda.bot.sharding.ShardManager;
import net.dv8tion.jda.core.entities.ChannelType;
import net.dv8tion.jda.core.exceptions.PermissionException;
import net.dv8tion.jda.core.utils.SessionControllerAdapter;
import net.dv8tion.jda.webhook.WebhookClient;
import net.dv8tion.jda.webhook.WebhookClientBuilder;

Expand Down Expand Up @@ -84,7 +85,7 @@ public Vortex() throws Exception
* 9 - number of shards
*/
List<String> tokens = Files.readAllLines(Paths.get("config.txt"));
waiter = new EventWaiter();
waiter = new EventWaiter(Executors.newSingleThreadScheduledExecutor(), false);
threadpool = Executors.newScheduledThreadPool(40);
database = new Database(tokens.get(4), tokens.get(5), tokens.get(6));
uploader = new TextUploader(this, Long.parseLong(tokens.get(8)));
Expand All @@ -103,6 +104,8 @@ public Vortex() throws Exception
.setLinkedCacheSize(0)
.setGuildSettingsManager(database.settings)
.setListener(new CommandExceptionListener())
.setScheduleExecutor(threadpool)
.setShutdownAutomatically(false)
.addCommands(// General
new AboutCommand(Color.CYAN, "and I'm here to keep your Discord server safe and make moderating easy!",
new String[]{"Moderation commands","Configurable automoderation","Very easy setup"},Constants.PERMISSIONS),
Expand Down Expand Up @@ -188,6 +191,22 @@ public Vortex() throws Exception
.setGame(Game.playing("loading..."))
.setBulkDeleteSplittingEnabled(false)
.setRequestTimeoutRetry(true)
.setSessionController(new SessionControllerAdapter()
{
@Override
protected void runWorker()
{
synchronized (lock)
{
if (workerHandle == null)
{
workerHandle = new SessionControllerAdapter.QueueWorker(15);
System.gc();
workerHandle.start();
}
}
}
})
.build();

modlog.start();
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/jagrosh/vortex/automod/StrikeHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void pardonStrikes(Member moderator, OffsetDateTime nowo, long targetId,

public void applyStrikes(Member moderator, OffsetDateTime nowo, User target, int number, String reason)
{
boolean shouldDM = moderator.getGuild().getMemberById(target.getIdLong())!=null;
boolean isMember = moderator.getGuild().getMemberById(target.getIdLong())!=null;
Instant now = nowo.toInstant();
int[] counts = vortex.getDatabase().strikes.addStrikes(moderator.getGuild(), target.getIdLong(), number);
if(counts[0]>110 && counts[1]>110)
Expand All @@ -79,15 +79,15 @@ public void applyStrikes(Member moderator, OffsetDateTime nowo, User target, int
if(punishments.isEmpty())
{
vortex.getModLogger().postStrikeCase(moderator, nowo, number, counts[0], counts[1], target, reason);
OtherUtil.safeDM(target, dmmsg, shouldDM, ()->{});
OtherUtil.safeDM(target, dmmsg, isMember, ()->{});
}
else
{
String notimeaudit = LogUtil.auditStrikeReasonFormat(moderator, 0, counts[0], counts[1], reason);
boolean canBan = moderator.getGuild().getSelfMember().hasPermission(Permission.BAN_MEMBERS);
if(punishments.stream().anyMatch(p -> p.action==Action.BAN) && canBan)
{
OtherUtil.safeDM(target, dmmsg + punish(Action.BAN, moderator.getGuild()), shouldDM,
OtherUtil.safeDM(target, dmmsg + punish(Action.BAN, moderator.getGuild()), isMember,
() -> moderator.getGuild().getController().ban(target, 7, notimeaudit).queue());
vortex.getDatabase().tempbans.clearBan(moderator.getGuild(), target.getIdLong());
return;
Expand All @@ -106,7 +106,7 @@ else if(p.action==Action.TEMPBAN && p.time>banDuration)
if(banDuration>0 && canBan)
{
int finalBanDuration = banDuration;
OtherUtil.safeDM(target, dmmsg + punishTime(Action.TEMPBAN, moderator.getGuild(), banDuration), shouldDM,
OtherUtil.safeDM(target, dmmsg + punishTime(Action.TEMPBAN, moderator.getGuild(), banDuration), isMember,
() -> moderator.getGuild().getController().ban(target, 7, 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)
Expand All @@ -115,7 +115,7 @@ else if(p.action==Action.TEMPBAN && p.time>banDuration)
}
if(punishments.stream().anyMatch(p -> p.action==Action.SOFTBAN) && canBan)
{
OtherUtil.safeDM(target, dmmsg + punish(Action.SOFTBAN, moderator.getGuild()), shouldDM,
OtherUtil.safeDM(target, dmmsg + punish(Action.SOFTBAN, moderator.getGuild()), isMember,
() -> moderator.getGuild().getController().ban(target, 7, notimeaudit).queue(
s -> moderator.getGuild().getController().unban(target).reason(notimeaudit).queueAfter(4, TimeUnit.SECONDS)));
if(muteDuration>0)
Expand All @@ -127,7 +127,7 @@ else if(p.action==Action.TEMPBAN && p.time>banDuration)
{
if(moderator.getGuild().isMember(target))
{
OtherUtil.safeDM(target, dmmsg + punish(Action.KICK, moderator.getGuild()), shouldDM,
OtherUtil.safeDM(target, dmmsg + punish(Action.KICK, moderator.getGuild()), isMember,
() -> moderator.getGuild().getController().kick(target.getId(), notimeaudit).queue());
}
else
Expand All @@ -147,7 +147,7 @@ else if(p.action==Action.TEMPBAN && p.time>banDuration)
if(muted==null || mem==null || !moderator.getGuild().getSelfMember().canInteract(muted))
{
vortex.getModLogger().postStrikeCase(moderator, nowo, number, counts[0], counts[1], target, reason);
OtherUtil.safeDM(target, dmmsg, shouldDM, ()->{});
OtherUtil.safeDM(target, dmmsg, isMember, ()->{});
return;
}
if(mem.getRoles().contains(muted))
Expand All @@ -163,7 +163,7 @@ else if(p.action==Action.TEMPBAN && p.time>banDuration)
.queue();
}
OtherUtil.safeDM(target, dmmsg + (muteDuration==Integer.MAX_VALUE ? punish(Action.MUTE, moderator.getGuild())
: punishTime(Action.TEMPMUTE, moderator.getGuild(), muteDuration)), shouldDM, ()->{});
: punishTime(Action.TEMPMUTE, moderator.getGuild(), muteDuration)), isMember, ()->{});
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ else if(!event.getArgs().matches("\\d{1,8}\\s*\\/\\s*\\d{1,8}"))
{
event.replyError("Valid options are `OFF`, `ON`, or `<joins>/<seconds>`"
+ "\nSetting to `OFF` means the bot will never automatically enable raid mode"
+ "\nSetting to `ON` will use the recommended value of 10 joins per 10 seconds to rigger Anti-Raid mode"
+ "\nSetting to `ON` will use the recommended value of 10 joins per 10 seconds to trigger Anti-Raid mode"
+ "\nSetting a customizable threshhold is possible; ex: `10/20` for 10 joins in 20 seconds"
+ "\nFor more information, check out the wiki: <"+Constants.Wiki.RAID_MODE+">");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
*/
public class ServerinfoCmd extends Command
{
private final String linestart = "\u25AB";
private final static String LINESTART = "\u25AB";

public ServerinfoCmd()
{
this.name = "serverinfo";
Expand All @@ -42,7 +43,8 @@ public ServerinfoCmd()
}

@Override
protected void execute(CommandEvent event) {
protected void execute(CommandEvent event)
{
Guild guild = event.getGuild();
long onlineCount = guild.getMembers().stream().filter((u) -> (u.getOnlineStatus()!=OnlineStatus.OFFLINE)).count();
long botCount = guild.getMembers().stream().filter(m -> m.getUser().isBot()).count();
Expand All @@ -54,23 +56,24 @@ protected void execute(CommandEvent event) {
case HIGH: verif = "(╯°□°)╯︵ ┻━┻"; break;
default: verif = guild.getVerificationLevel().name(); break;
}
String str = linestart+"ID: **"+guild.getId()+"**\n"
+linestart+"Owner: "+FormatUtil.formatUser(guild.getOwner().getUser())+"\n"
+linestart+"Location: "+guild.getRegion().getEmoji()+" **"+guild.getRegion().getName()+"**\n"
+linestart+"Creation: **"+guild.getCreationTime().format(DateTimeFormatter.RFC_1123_DATE_TIME)+"**\n"
+linestart+"Users: **"+guild.getMembers().size()+"** ("+onlineCount+" online, "+botCount+" bots)\n"
+linestart+"Channels: **"+guild.getTextChannels().size()+"** Text, **"+guild.getVoiceChannels().size()+"** Voice\n"
+linestart+"Verification: **"+verif+"**";
String str = LINESTART+"ID: **"+guild.getId()+"**\n"
+LINESTART+"Owner: "+FormatUtil.formatUser(guild.getOwner().getUser())+"\n"
+LINESTART+"Location: "+(guild.getRegion().getEmoji()==null ? "\u2754" : guild.getRegion().getEmoji())+" **"+guild.getRegion().getName()+"**\n"
+LINESTART+"Creation: **"+guild.getCreationTime().format(DateTimeFormatter.RFC_1123_DATE_TIME)+"**\n"
+LINESTART+"Users: **"+guild.getMemberCache().size()+"** ("+onlineCount+" online, "+botCount+" bots)\n"
+LINESTART+"Channels: **"+guild.getTextChannelCache().size()+"** Text, **"+guild.getVoiceChannelCache().size()+"** Voice, **"+guild.getCategoryCache().size()+"** Categories\n"
+LINESTART+"Verification: **"+verif+"**";
if(!guild.getFeatures().isEmpty())
str += "\n"+LINESTART+"Features: **"+String.join("**, **", guild.getFeatures())+"**";
if(guild.getSplashId()!=null)
{
builder.setImage(guild.getSplashUrl()+"?size=1024");
str += "\n<:partner:314068430556758017> **Discord Partner** <:partner:314068430556758017>";
str += "\n"+LINESTART+"Splash: ";
}
if(guild.getIconUrl()!=null)
builder.setThumbnail(guild.getIconUrl());
builder.setColor(guild.getOwner().getColor());
builder.setDescription(str);
event.reply(new MessageBuilder().append(title).setEmbed(builder.build()).build());
}

}
17 changes: 10 additions & 7 deletions src/main/java/com/jagrosh/vortex/commands/moderation/BanCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import com.jagrosh.vortex.utils.LogUtil;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import net.dv8tion.jda.core.entities.Role;

/**
Expand Down Expand Up @@ -66,6 +68,7 @@ else if(args.time > 60)
String reason = LogUtil.auditReasonFormat(event.getMember(), minutes, args.reason);
Role modrole = vortex.getDatabase().settings.getSettings(event.getGuild()).getModeratorRole(event.getGuild());
StringBuilder builder = new StringBuilder();
List<Long> ids = new ArrayList<>(args.ids);

args.members.forEach(m ->
{
Expand All @@ -76,29 +79,29 @@ else if(!event.getSelfMember().canInteract(m))
else if(modrole!=null && m.getRoles().contains(modrole))
builder.append("\n").append(event.getClient().getError()).append(" I won't ban ").append(FormatUtil.formatUser(m.getUser())).append(" because they have the Moderator Role");
else
args.ids.add(m.getUser().getIdLong());
ids.add(m.getUser().getIdLong());
});

args.unresolved.forEach(un -> builder.append("\n").append(event.getClient().getWarning()).append(" Could not resolve `").append(un).append("` to a user ID"));

args.users.forEach(u -> args.ids.add(u.getIdLong()));
args.users.forEach(u -> ids.add(u.getIdLong()));

if(args.ids.isEmpty())
if(ids.isEmpty())
{
event.reply(builder.toString());
return;
}

if(args.ids.size() > 5)
if(ids.size() > 5)
event.reactSuccess();

Instant unbanTime = Instant.now().plus(minutes, ChronoUnit.MINUTES);
String time = minutes==0 ? "" : " for "+FormatUtil.secondsToTimeCompact(minutes*60);
for(int i=0; i<args.ids.size(); i++)
for(int i=0; i<ids.size(); i++)
{
long uid = args.ids.get(i);
long uid = ids.get(i);
String id = Long.toString(uid);
boolean last = i+1 == args.ids.size();
boolean last = i+1 == ids.size();
event.getGuild().getController().ban(id, 1, reason).queue(success ->
{
builder.append("\n").append(event.getClient().getSuccess()).append(" Successfully banned <@").append(id).append(">").append(time);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.jagrosh.vortex.utils.FormatUtil;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Role;
import net.dv8tion.jda.core.entities.User;
Expand Down Expand Up @@ -127,7 +128,7 @@ else if(modrole!=null && m.getRoles().contains(modrole))
});
}

private void strikeAll(List<User> users, int numstrikes, String reason, StringBuilder builder, CommandEvent event)
private void strikeAll(Set<User> users, int numstrikes, String reason, StringBuilder builder, CommandEvent event)
{
users.forEach(u ->
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected void execute(CommandEvent event)
for(int i=0; i<toUnban.size(); i++)
{
Ban ban = toUnban.get(i);
boolean last = i+1 == args.ids.size();
boolean last = i+1 == toUnban.size();
event.getGuild().getController().unban(ban.getUser()).reason(reason).queue(success ->
{
builder.append("\n").append(event.getClient().getSuccess()).append(" Successfully unbanned ").append(FormatUtil.formatUser(ban.getUser()));
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/com/jagrosh/vortex/utils/ArgsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
*/
package com.jagrosh.vortex.utils;

import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.dv8tion.jda.core.entities.Guild;
Expand All @@ -41,10 +43,10 @@ public static ResolvedArgs resolve(String args, Guild guild)

public static ResolvedArgs resolve(String args, boolean allowTime, Guild guild)
{
List<Member> members = new LinkedList<>();
List<User> users = new LinkedList<>();
List<Long> ids = new LinkedList<>();
List<String> unresolved = new LinkedList<>();
Set<Member> members = new LinkedHashSet<>();
Set<User> users = new LinkedHashSet<>();
Set<Long> ids = new LinkedHashSet<>();
Set<String> unresolved = new LinkedHashSet<>();
Matcher mat;
User u;
long i;
Expand Down Expand Up @@ -125,14 +127,14 @@ else if(guild.isMember(u))

public static class ResolvedArgs
{
public final List<Member> members;
public final List<User> users;
public final List<Long> ids;
public final List<String> unresolved;
public final Set<Member> members;
public final Set<User> users;
public final Set<Long> ids;
public final Set<String> unresolved;
public final int time;
public final String reason;

private ResolvedArgs(List<Member> members, List<User> users, List<Long> ids, List<String> unresolved, int time, String reason)
private ResolvedArgs(Set<Member> members, Set<User> users, Set<Long> ids, Set<String> unresolved, int time, String reason)
{
this.members = members;
this.users = users;
Expand Down

0 comments on commit 7cf2d82

Please sign in to comment.