Skip to content

Commit e64f73b

Browse files
committed
more changes or something why dont I commit things anymore idk
1 parent 65279e2 commit e64f73b

16 files changed

+174
-18
lines changed

pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<version>3.0.5</version>
3737
<type>pom</type>
3838
</dependency>
39-
<dependency>
39+
<dependency>
4040
<groupId>com.jagrosh</groupId>
4141
<artifactId>EasySQL</artifactId>
4242
<version>0.3</version>
@@ -46,6 +46,11 @@
4646
<artifactId>discord-webhooks</artifactId>
4747
<version>0.1.8</version>
4848
</dependency>
49+
<dependency>
50+
<groupId>com.squareup.okhttp3</groupId>
51+
<artifactId>okhttp</artifactId>
52+
<version>3.13.0</version>
53+
</dependency>
4954
<dependency>
5055
<groupId>ch.qos.logback</groupId>
5156
<artifactId>logback-classic</artifactId>

src/main/java/com/jagrosh/vortex/Listener.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,21 @@ else if (event instanceof GuildMemberRoleRemoveEvent)
167167
}
168168
else if (event instanceof UserUpdateNameEvent)
169169
{
170+
// Make sure the name actually changed
170171
UserUpdateNameEvent unue = (UserUpdateNameEvent)event;
171-
// Log the name change
172-
vortex.getBasicLogger().logNameChange(unue);
173-
unue.getUser().getMutualGuilds().stream().map(g -> g.getMember(unue.getUser())).forEach(m -> vortex.getAutoMod().dehoist(m));
172+
if(!unue.getNewName().equals(unue.getOldName()))
173+
{
174+
// Log the name change
175+
vortex.getBasicLogger().logNameChange(unue);
176+
unue.getUser().getMutualGuilds().stream().map(g -> g.getMember(unue.getUser())).forEach(m -> vortex.getAutoMod().dehoist(m));
177+
}
174178
}
175179
else if (event instanceof UserUpdateDiscriminatorEvent)
176180
{
177-
vortex.getBasicLogger().logNameChange((UserUpdateDiscriminatorEvent)event);
181+
// Make sure the discrim actually changed
182+
UserUpdateDiscriminatorEvent udue = (UserUpdateDiscriminatorEvent) event;
183+
if(!udue.getNewDiscriminator().equals(udue.getOldDiscriminator()))
184+
vortex.getBasicLogger().logDiscrimChange((UserUpdateDiscriminatorEvent)event);
178185
}
179186
else if (event instanceof GuildMemberUpdateNicknameEvent)
180187
{

src/main/java/com/jagrosh/vortex/Vortex.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
import com.jagrosh.vortex.logging.ModLogger;
4141
import com.jagrosh.vortex.logging.TextUploader;
4242
import com.jagrosh.vortex.utils.FormatUtil;
43-
import com.jagrosh.vortex.utils.MultiBotManager;
43+
import com.jagrosh.vortex.managers.MultiBotManager;
44+
import com.jagrosh.vortex.managers.UptimeManager;
4445
import com.jagrosh.vortex.utils.OtherUtil;
4546
import com.typesafe.config.Config;
4647
import com.typesafe.config.ConfigFactory;
@@ -72,6 +73,7 @@ public class Vortex
7273
private final WebhookClient logwebhook;
7374
private final AutoMod automod;
7475
private final StrikeHandler strikehandler;
76+
private final UptimeManager uptime;
7577
private final CommandExceptionListener listener;
7678
private final Config config;
7779

@@ -91,6 +93,7 @@ public Vortex() throws Exception
9193
logwebhook = new WebhookClientBuilder(config.getString("webhook-url")).build();
9294
automod = new AutoMod(this, config);
9395
strikehandler = new StrikeHandler(this);
96+
uptime = new UptimeManager(logwebhook, database, threadpool, 1);
9497
listener = new CommandExceptionListener();
9598
CommandClient client = new CommandClientBuilder()
9699
.setPrefix(Constants.PREFIX)
@@ -198,6 +201,7 @@ public Vortex() throws Exception
198201
.build();
199202

200203
modlog.start();
204+
uptime.start();
201205

202206
threadpool.scheduleWithFixedDelay(() -> cleanPremium(), 0, 2, TimeUnit.HOURS);
203207
threadpool.scheduleWithFixedDelay(() -> leavePointlessGuilds(), 5, 30, TimeUnit.MINUTES);

src/main/java/com/jagrosh/vortex/commands/owner/PremiumCmd.java

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public PremiumCmd(Vortex vortex)
4242
this.ownerCommand = true;
4343
this.guildOnly = false;
4444
this.hidden = true;
45-
this.children = new Command[]{ new PremiumAddCmd(), new PremiumInfoCmd(), new PremiumUserCmd() };
45+
this.children = new Command[]{ new PremiumAddCmd(), new PremiumInfoCmd(), new PremiumUserCmd(), new PremiumRemoveCmd() };
4646
}
4747

4848
@Override
@@ -161,6 +161,7 @@ private PremiumInfoCmd()
161161
{
162162
this.name = "info";
163163
this.help = "shows premium info";
164+
this.arguments = "";
164165
this.ownerCommand = true;
165166
this.guildOnly = false;
166167
this.hidden = true;
@@ -178,4 +179,58 @@ protected void execute(CommandEvent event)
178179
}).collect(Collectors.joining("\n")));
179180
}
180181
}
182+
183+
private class PremiumRemoveCmd extends Command
184+
{
185+
public PremiumRemoveCmd()
186+
{
187+
this.name = "remove";
188+
this.help = "removes premium";
189+
this.arguments = "<guildId>";
190+
this.ownerCommand = true;
191+
this.guildOnly = false;
192+
this.hidden = true;
193+
}
194+
195+
@Override
196+
protected void execute(CommandEvent event)
197+
{
198+
String[] parts = event.getArgs().split("\\s+", 1);
199+
if(parts.length < 1)
200+
{
201+
event.replyError("Too few arguments");
202+
return;
203+
}
204+
205+
Guild guild;
206+
try
207+
{
208+
guild = vortex.getShardManager().getGuildById(Long.parseLong(parts[0]));
209+
}
210+
catch(NumberFormatException ex)
211+
{
212+
event.replyError("Invalid guild ID");
213+
return;
214+
}
215+
216+
if(guild == null)
217+
{
218+
event.replyError("No guild found with ID `" + parts[0] + "`");
219+
return;
220+
}
221+
222+
PremiumInfo before = vortex.getDatabase().premium.getPremiumInfo(guild);
223+
if(before == null || before.level == PremiumManager.Level.NONE)
224+
{
225+
event.replyError("Guild `" + guild.getName() + "` does not have premium!");
226+
return;
227+
}
228+
229+
// remove 5 years, so that the cleanup will still happen correctly
230+
// tbh there should be a better cleanup system
231+
vortex.getDatabase().premium.addPremium(guild, PremiumManager.Level.NONE, -5 * 365, ChronoUnit.DAYS);
232+
PremiumInfo after = vortex.getDatabase().premium.getPremiumInfo(guild);
233+
event.replySuccess("Before: " + before + "\n" + event.getClient().getSuccess() + " After: " + after);
234+
}
235+
}
181236
}

src/main/java/com/jagrosh/vortex/database/managers/PremiumManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.jagrosh.easysql.SQLColumn;
2121
import com.jagrosh.easysql.columns.*;
2222
import com.jagrosh.vortex.Constants;
23-
import com.jagrosh.vortex.utils.MultiBotManager;
23+
import com.jagrosh.vortex.managers.MultiBotManager;
2424
import java.sql.ResultSet;
2525
import java.sql.SQLException;
2626
import java.time.Instant;

src/main/java/com/jagrosh/vortex/database/managers/TempBanManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.jagrosh.easysql.SQLColumn;
2121
import com.jagrosh.easysql.columns.InstantColumn;
2222
import com.jagrosh.easysql.columns.LongColumn;
23-
import com.jagrosh.vortex.utils.MultiBotManager;
23+
import com.jagrosh.vortex.managers.MultiBotManager;
2424
import com.jagrosh.vortex.utils.Pair;
2525
import java.time.Instant;
2626
import java.time.temporal.ChronoUnit;

src/main/java/com/jagrosh/vortex/database/managers/TempMuteManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.jagrosh.easysql.SQLColumn;
2121
import com.jagrosh.easysql.columns.InstantColumn;
2222
import com.jagrosh.easysql.columns.LongColumn;
23-
import com.jagrosh.vortex.utils.MultiBotManager;
23+
import com.jagrosh.vortex.managers.MultiBotManager;
2424
import com.jagrosh.vortex.utils.Pair;
2525
import java.time.Instant;
2626
import java.time.temporal.ChronoUnit;

src/main/java/com/jagrosh/vortex/database/managers/TempSlowmodeManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.jagrosh.easysql.SQLColumn;
2121
import com.jagrosh.easysql.columns.InstantColumn;
2222
import com.jagrosh.easysql.columns.LongColumn;
23-
import com.jagrosh.vortex.utils.MultiBotManager;
23+
import com.jagrosh.vortex.managers.MultiBotManager;
2424
import com.jagrosh.vortex.utils.Pair;
2525
import net.dv8tion.jda.api.JDA;
2626
import net.dv8tion.jda.api.Permission;

src/main/java/com/jagrosh/vortex/logging/BasicLogger.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public void logNameChange(UserUpdateNameEvent event)
222222
});
223223
}
224224

225-
public void logNameChange(UserUpdateDiscriminatorEvent event)
225+
public void logDiscrimChange(UserUpdateDiscriminatorEvent event)
226226
{
227227
OffsetDateTime now = OffsetDateTime.now();
228228
event.getJDA().getMutualGuilds(event.getEntity()).stream()
@@ -232,7 +232,7 @@ public void logNameChange(UserUpdateDiscriminatorEvent event)
232232
.forEachOrdered(tc ->
233233
{
234234
log(now, tc, NAME, "**"+event.getUser().getName()+"**#"+event.getOldDiscriminator()+" (ID:"
235-
+event.getUser().getId()+") has changed names to "+FormatUtil.formatUser(event.getUser()), null);
235+
+event.getUser().getId()+") has changed discrims to "+FormatUtil.formatUser(event.getUser()), null);
236236
});
237237
}
238238

src/main/java/com/jagrosh/vortex/logging/MessageCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package com.jagrosh.vortex.logging;
1717

1818
import com.jagrosh.vortex.utils.FixedCache;
19-
import com.jagrosh.vortex.utils.MultiBotManager;
19+
import com.jagrosh.vortex.managers.MultiBotManager;
2020
import java.util.Collections;
2121
import java.util.HashMap;
2222
import java.util.List;

src/main/java/com/jagrosh/vortex/managers/BlockingSessionController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.jagrosh.vortex.utils;
16+
package com.jagrosh.vortex.managers;
1717

1818
import net.dv8tion.jda.api.JDA;
1919
import net.dv8tion.jda.api.utils.SessionControllerAdapter;

src/main/java/com/jagrosh/vortex/managers/ConditionalEventManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.jagrosh.vortex.utils;
16+
package com.jagrosh.vortex.managers;
1717

1818
import java.lang.reflect.InvocationTargetException;
1919
import java.util.List;

src/main/java/com/jagrosh/vortex/managers/MultiBotManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.jagrosh.vortex.utils;
16+
package com.jagrosh.vortex.managers;
1717

1818
import java.util.*;
1919
import java.util.stream.Collectors;

src/main/java/com/jagrosh/vortex/managers/SlowerConcurrentSessionController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.jagrosh.vortex.utils;
16+
package com.jagrosh.vortex.managers;
1717

1818
import net.dv8tion.jda.api.utils.ConcurrentSessionController;
1919

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright 2023 jagrosh.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.jagrosh.vortex.managers;
17+
18+
import club.minnced.discord.webhook.WebhookClient;
19+
import com.jagrosh.vortex.Constants;
20+
import com.jagrosh.vortex.database.Database;
21+
import java.util.concurrent.ScheduledExecutorService;
22+
import java.util.concurrent.TimeUnit;
23+
24+
/**
25+
*
26+
* @author jagrosh
27+
*/
28+
public class UptimeManager
29+
{
30+
private boolean started = false;
31+
private int failures = 0;
32+
private final int minPrem;
33+
private final ScheduledExecutorService threadpool;
34+
private final WebhookClient log;
35+
private final Database database;
36+
37+
public UptimeManager(WebhookClient log, Database database, ScheduledExecutorService threadpool, int minPrem)
38+
{
39+
this.log = log;
40+
this.database = database;
41+
this.threadpool = threadpool;
42+
this.minPrem = minPrem;
43+
}
44+
45+
public void start()
46+
{
47+
if(started)
48+
return;
49+
started = true;
50+
51+
threadpool.scheduleWithFixedDelay(()->check(), 2, 2, TimeUnit.MINUTES);
52+
}
53+
54+
private void check()
55+
{
56+
boolean valid = false;
57+
try
58+
{
59+
boolean closed = database.getConnection().isClosed();
60+
int prem = database.premium.getPremiumGuilds().size();
61+
valid = !closed && prem >= minPrem;
62+
}
63+
catch(Exception ignored){}
64+
65+
if(!valid)
66+
failures++;
67+
else
68+
failures = 0;
69+
70+
if(failures == 3)
71+
shutdownAll();
72+
}
73+
74+
private void shutdownAll()
75+
{
76+
try
77+
{
78+
log.send(Constants.ERROR+" Uptime failure, attempting restart...").get();
79+
Thread.sleep(1000);
80+
}
81+
catch(Exception ignored){}
82+
System.exit(1);
83+
}
84+
}

src/main/java/com/jagrosh/vortex/utils/LogUtil.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.jagrosh.vortex.utils;
1717

18+
import com.jagrosh.vortex.managers.MultiBotManager;
1819
import com.jagrosh.vortex.Action;
1920
import com.jagrosh.vortex.logging.MessageCache.CachedMessage;
2021
import java.time.OffsetDateTime;

0 commit comments

Comments
 (0)