Skip to content

Commit

Permalink
more multi-bot overlap fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jagrosh committed Dec 20, 2020
1 parent 89c0419 commit 8d25404
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 22 deletions.
3 changes: 0 additions & 3 deletions src/main/java/com/jagrosh/vortex/Listener.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,6 @@ else if (event instanceof ReadyEvent)
LOG.info("Shard "+shardinfo+" is ready.");
vortex.getLogWebhook().send("\uD83C\uDF00 Shard `"+shardinfo+"` has connected. Guilds: `" // 🌀
+event.getJDA().getGuildCache().size()+"` Users: `"+event.getJDA().getUserCache().size()+"`");
vortex.getThreadpool().scheduleWithFixedDelay(() -> vortex.getDatabase().tempbans.checkUnbans(event.getJDA()), 0, 2, TimeUnit.MINUTES);
vortex.getThreadpool().scheduleWithFixedDelay(() -> vortex.getDatabase().tempmutes.checkUnmutes(event.getJDA(), vortex.getDatabase().settings), 0, 45, TimeUnit.SECONDS);
vortex.getThreadpool().scheduleWithFixedDelay(() -> vortex.getDatabase().tempslowmodes.checkSlowmode(event.getJDA()), 0, 45, TimeUnit.SECONDS);
}
}
}
14 changes: 3 additions & 11 deletions src/main/java/com/jagrosh/vortex/Vortex.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,22 +193,14 @@ public Vortex() throws Exception
.setStatus(OnlineStatus.DO_NOT_DISTURB)
.setActivity(Activity.playing("loading..."))
.build();
/*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)
.build();*/

modlog.start();

threadpool.scheduleWithFixedDelay(() -> cleanPremium(), 0, 2, TimeUnit.HOURS);
threadpool.scheduleWithFixedDelay(() -> leavePointlessGuilds(), 5, 30, TimeUnit.MINUTES);
threadpool.scheduleWithFixedDelay(() -> database.tempbans.checkUnbans(shards), 0, 2, TimeUnit.MINUTES);
threadpool.scheduleWithFixedDelay(() -> database.tempmutes.checkUnmutes(shards, database.settings), 0, 45, TimeUnit.SECONDS);
threadpool.scheduleWithFixedDelay(() -> database.tempslowmodes.checkSlowmode(shards), 0, 45, TimeUnit.SECONDS);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.jagrosh.easysql.SQLColumn;
import com.jagrosh.easysql.columns.InstantColumn;
import com.jagrosh.easysql.columns.LongColumn;
import com.jagrosh.vortex.utils.MultiBotManager;
import com.jagrosh.vortex.utils.Pair;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
Expand Down Expand Up @@ -110,13 +111,13 @@ public int timeUntilUnban(Guild guild, long userId)
});
}

public void checkUnbans(JDA jda)
public void checkUnbans(MultiBotManager shards)
{
readWrite(selectAll(FINISH.isLessThan(Instant.now().getEpochSecond())), rs ->
{
while(rs.next())
{
Guild g = jda.getGuildById(GUILD_ID.getValue(rs));
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->{});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.jagrosh.easysql.SQLColumn;
import com.jagrosh.easysql.columns.InstantColumn;
import com.jagrosh.easysql.columns.LongColumn;
import com.jagrosh.vortex.utils.MultiBotManager;
import com.jagrosh.vortex.utils.Pair;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
Expand Down Expand Up @@ -141,13 +142,13 @@ public int timeUntilUnmute(Guild guild, long userId)
});
}

public void checkUnmutes(JDA jda, GuildSettingsDataManager data)
public void checkUnmutes(MultiBotManager shards, GuildSettingsDataManager data)
{
readWrite(selectAll(FINISH.isLessThan(Instant.now().getEpochSecond())), rs ->
{
while(rs.next())
{
Guild g = jda.getGuildById(GUILD_ID.getValue(rs));
Guild g = shards.getGuildById(GUILD_ID.getValue(rs));
if(g==null || g.getMemberCache().isEmpty() || !g.getSelfMember().hasPermission(Permission.MANAGE_ROLES))
continue;
Role mRole = data.getSettings(g).getMutedRole(g);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.jagrosh.easysql.SQLColumn;
import com.jagrosh.easysql.columns.InstantColumn;
import com.jagrosh.easysql.columns.LongColumn;
import com.jagrosh.vortex.utils.MultiBotManager;
import com.jagrosh.vortex.utils.Pair;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.Permission;
Expand Down Expand Up @@ -107,13 +108,13 @@ public int timeUntilDisableSlowmode(TextChannel channel)
});
}

public void checkSlowmode(JDA jda)
public void checkSlowmode(MultiBotManager shards)
{
readWrite(selectAll(FINISH.isLessThan(Instant.now().getEpochSecond())), rs ->
{
while(rs.next())
{
TextChannel tc = jda.getTextChannelById(CHANNEL_ID.getValue(rs));
TextChannel tc = shards.getTextChannelById(CHANNEL_ID.getValue(rs));
if(tc==null)
continue;
if(tc.getGuild().getSelfMember().hasPermission(tc, Permission.MANAGE_CHANNEL))
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/jagrosh/vortex/logging/ModLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,9 @@ private int getCaseNumber(TextChannel tc) // not async
}
}

private static int getCaseNumber(Message m)
private int getCaseNumber(Message m)
{
if(m.getAuthor().getIdLong()!=m.getJDA().getSelfUser().getIdLong())
if(!vortex.getShardManager().getBotIds().contains(m.getAuthor().getIdLong()))
return -1;
if(!m.getContentRaw().startsWith("`["))
return -1;
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/jagrosh/vortex/utils/MultiBotManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import javax.security.auth.login.LoginException;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.Activity;
Expand Down Expand Up @@ -57,6 +58,11 @@ public List<ShardManager> getShardManagers()
return bots;
}

public List<Long> getBotIds()
{
return bots.stream().map(bot -> bot.getShards().get(0).getSelfUser().getIdLong()).collect(Collectors.toList());
}

public RestAction<User> retrieveUserById(long id)
{
if(!bots.isEmpty())
Expand Down

0 comments on commit 8d25404

Please sign in to comment.