Skip to content
This repository has been archived by the owner on Sep 24, 2022. It is now read-only.

🔍 Modlog #225

Closed
wants to merge 227 commits into from
Closed
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
227 commits
Select commit Hold shift + click to select a range
2e4ead9
Created the base enum for modlog actions
binaryoverload Dec 29, 2019
d79ded4
Format ModlogEvent
binaryoverload Dec 29, 2019
692e857
Push to the correct branch this time
weeryan17 May 14, 2020
efd5c23
Store messages in redis
weeryan17 May 14, 2020
4d9b563
Benchmarking
weeryan17 May 14, 2020
b6bf1cb
Put stuff in queue so we don't block the event thread
weeryan17 May 15, 2020
617c79f
Change all the crypt stuff
weeryan17 May 16, 2020
70e0791
Merge branch 'feature/message-modlog' into feature/modlog
weeryan17 May 17, 2020
a1ab9ca
Work on implementing modlog events parsing
weeryan17 May 18, 2020
a146216
Merge branch 'dev' into feature/modlog
weeryan17 May 18, 2020
797ebf8
Guild Update Events
weeryan17 May 18, 2020
bee5809
Channel Modlog Events
weeryan17 May 19, 2020
0090498
Role Events
weeryan17 May 19, 2020
3b93490
User events
weeryan17 May 19, 2020
52b3d43
Send webhook message
weeryan17 May 21, 2020
de08257
Store ChannelModlogEventsInfo in a map
weeryan17 May 21, 2020
52fc0a4
Start adding language to modlog
weeryan17 May 23, 2020
7a1a566
More events with proper language
weeryan17 May 23, 2020
c02b64d
Finish adding language to modlog events
weeryan17 May 25, 2020
02f2102
Minor fixes, and cleanup
weeryan17 May 25, 2020
532a6bc
Some utility functions
weeryan17 May 25, 2020
1a6e74d
Minor fixes and store events
weeryan17 May 25, 2020
7739248
Merge branch 'dev' into feature/modlog
weeryan17 May 25, 2020
34fb113
Enable and disable commands
weeryan17 May 28, 2020
5a189c2
Store most message metadata
weeryan17 Jun 1, 2020
925cd02
Modlog channel sub command
weeryan17 Jun 4, 2020
cb536df
Events language
weeryan17 Jun 4, 2020
3d84717
Fix some small issues
weeryan17 Jun 4, 2020
2dc98af
Clear and prune commands as well as fixes
weeryan17 Jun 6, 2020
701b27d
Remove iv from config
weeryan17 Jun 6, 2020
0e71f12
Don't store message id
weeryan17 Jun 7, 2020
e60c7c4
singleton
weeryan17 Jun 7, 2020
6ece557
Misc fixes
weeryan17 Jun 7, 2020
f0a1f12
log error if redis doesn't connect
weeryan17 Jun 7, 2020
a49d8fc
benchmark in submodule
weeryan17 Jun 7, 2020
19b5983
Convert events to kotlin
weeryan17 Jun 7, 2020
9e0a357
Rest of discord events
weeryan17 Jun 7, 2020
a49ae7c
Start work on cascade events
weeryan17 Jun 7, 2020
bf57d89
Revert "benchmark in submodule"
weeryan17 Jun 7, 2020
a71c997
More Cascade modlog events
weeryan17 Jun 7, 2020
1c32162
The rest of the currently doable cascade events
weeryan17 Jun 7, 2020
fb561d7
lombok (╯°□°)╯︵ ┻━┻
weeryan17 Jun 7, 2020
a5e831c
Final misc message stuff
weeryan17 Jun 9, 2020
8c8a282
Minor fixes
weeryan17 Jun 9, 2020
a2cace8
page fixes.
weeryan17 Jun 9, 2020
62b25a4
Merge branch 'dev' into feature/modlog
weeryan17 Jun 9, 2020
e805393
More fixes!
weeryan17 Jun 9, 2020
853b12d
More fixes, also more entry checks
weeryan17 Jun 9, 2020
0da7090
uggggggg
weeryan17 Jun 9, 2020
df83505
WHY DOES THIS EXIST
binaryoverload Jun 9, 2020
bf22464
Make sendModlogEvent functional, don't fuck it up
binaryoverload Jun 9, 2020
e763847
RYAN
binaryoverload Jun 9, 2020
fb6b939
Don't question it
binaryoverload Jun 9, 2020
32dc9be
Fix varargs
binaryoverload Jun 9, 2020
97c78bc
Minor fixes
weeryan17 Jun 9, 2020
1a0fb24
listen to the correct event
weeryan17 Jun 10, 2020
4a8e555
Fixed splitter?
binaryoverload Jun 10, 2020
ed3a48f
Audit log checking for voice
weeryan17 Jun 10, 2020
17c58be
Merge remote-tracking branch 'origin/feature/modlog' into feature/modlog
binaryoverload Jun 10, 2020
b1d6680
Merge branch 'dev' into feature/modlog
weeryan17 Jun 10, 2020
9cfaa01
Merge remote-tracking branch 'origin/feature/modlog' into feature/modlog
weeryan17 Jun 10, 2020
18338f3
register weight pair
weeryan17 Jun 10, 2020
ec10fa6
Merge branch 'dev' into feature/modlog
weeryan17 Jun 11, 2020
0c987c8
Merge branch 'dev' into feature/modlog
weeryan17 Jun 13, 2020
44692a8
Fix merge
weeryan17 Jun 13, 2020
798dc79
Start moving modlog to new system
weeryan17 Jun 15, 2020
41f5ed4
Merge branch 'dev' into feature/modlog
weeryan17 Aug 1, 2020
3f65719
New Display System
weeryan17 Aug 2, 2020
9ae52ad
We can actually save now. Wooo!
weeryan17 Aug 2, 2020
165d447
👀
binaryoverload Aug 2, 2020
7cf388e
Merge branch 'dev' into feature/modlog
weeryan17 Aug 23, 2020
6db1430
BEGONE THOT
weeryan17 Aug 23, 2020
58ac8f8
Revert "BEGONE THOT"
weeryan17 Aug 23, 2020
1928a11
BEGONE THOT (better)
weeryan17 Aug 23, 2020
eddcc22
Merge branch 'dev' into feature/modlog
weeryan17 Sep 20, 2020
4e2768e
Fix merge
weeryan17 Sep 20, 2020
043ba65
General event work to make them look nicer
weeryan17 Oct 11, 2020
da50127
Descriptions!
binaryoverload Oct 25, 2020
789d465
Lengthen time offset for audit log entry checking
binaryoverload Oct 25, 2020
47d4c6a
Add a default util
binaryoverload Oct 25, 2020
bee2bc1
Kotlinize
binaryoverload Oct 25, 2020
1280912
Add a display type :P
binaryoverload Oct 25, 2020
cdbbd7d
Shorten code
binaryoverload Oct 25, 2020
83856ac
Modlog Events!
binaryoverload Oct 25, 2020
65e4d5e
Update some event descriptions
binaryoverload Oct 25, 2020
1b52b88
Merge branch 'dev' into feature/modlog
binaryoverload Oct 26, 2020
eee0eed
Fix merge and warnings
binaryoverload Oct 26, 2020
4a796d4
Remove AFFECTED display type and do roles
binaryoverload Oct 26, 2020
ceb9c92
Typos!
binaryoverload Oct 26, 2020
6f622f1
Goodbye embed inline fields
binaryoverload Oct 26, 2020
3b70e89
Nickname audit log?
binaryoverload Oct 26, 2020
8d4a3ae
Lots of channel stuff, voice channel, text channel, text channel moves
binaryoverload Oct 26, 2020
92566be
TextChannel: Topic and NSFW
binaryoverload Oct 26, 2020
f96e1df
Reduce warnings in Modlog event listener
binaryoverload Oct 26, 2020
95faf39
Kotlinfy the event store and even listener
binaryoverload Oct 26, 2020
213a798
Add member updated to audit filter
weeryan17 Oct 26, 2020
91d76cf
Tidy up the JSON
binaryoverload Oct 27, 2020
07ba4fa
Pass base object into Affected so we can use it later on
binaryoverload Oct 27, 2020
cf9879b
Use the base object
binaryoverload Oct 27, 2020
34614e9
Ban hierarchy shouldn't be checked for unban
binaryoverload Oct 27, 2020
841d55f
Guild updates? Not sure
binaryoverload Oct 27, 2020
e95ecb7
Databasey stuff
binaryoverload Oct 27, 2020
e88619a
Merge branch 'dev' into feature/modlog
binaryoverload Oct 30, 2020
f9bba31
Add voice-channels's description items
binaryoverload Nov 22, 2020
79da4c5
Add indentation to Modlog event to make it easier to read
binaryoverload Nov 22, 2020
15006d7
Add support for different affected display types
binaryoverload Nov 22, 2020
7152705
Voice chat events: Muting and deadening
binaryoverload Nov 22, 2020
98a3b82
Guild modlog
binaryoverload Nov 22, 2020
8a00801
Use effective URL and the affected image url
binaryoverload Nov 23, 2020
76c178f
Make everything non-optional
binaryoverload Nov 23, 2020
b2f34a6
Set correct name and avatar URL when using webhooks
binaryoverload Nov 23, 2020
838ccce
Extract all modlog channel commands into methods
binaryoverload Nov 23, 2020
23e49d3
Modlog Usage
binaryoverload Nov 23, 2020
8fb21b0
7 Speedrun
binaryoverload Nov 23, 2020
fed1a5d
Speedrun v2 (See Desc)
binaryoverload Nov 24, 2020
ae9755d
Work on event collector
binaryoverload Nov 28, 2020
e0c5c4f
Missed a dodgy import
binaryoverload Mar 13, 2021
25845d7
Remove max members for now
binaryoverload Mar 13, 2021
36dff20
Channel stuff
binaryoverload Mar 13, 2021
a1d0d71
Remove command run error from events
binaryoverload Mar 13, 2021
04d7d0d
Parent and category changes
binaryoverload Mar 13, 2021
f31a7f1
ui ux
binaryoverload Mar 13, 2021
7694b61
Add group id
binaryoverload Mar 13, 2021
9b98d1f
Modlog module descriptions
binaryoverload Mar 13, 2021
de174e1
Add an group unlink
binaryoverload Mar 13, 2021
771630b
Descriptions for permissions
binaryoverload Mar 13, 2021
8afa52b
Tag content markdown santisation
binaryoverload Mar 13, 2021
adf9da1
System channel
binaryoverload Mar 13, 2021
5a8d5fc
✨ Language ✨
binaryoverload Mar 13, 2021
b20d2a5
Make it so null channel parents are handled
binaryoverload Mar 13, 2021
fd2ea39
Clean up role events a little bit
weeryan17 Mar 23, 2021
41f47ad
Channel possition calculations
weeryan17 Mar 23, 2021
d6e740c
Organise imports
binaryoverload Apr 3, 2021
aea60cc
Use the new position calculations
binaryoverload Apr 3, 2021
130b8fa
Simpler channel position type calculation
binaryoverload Apr 3, 2021
fd89d9b
Channel override improvements
weeryan17 Apr 17, 2021
e2be6dd
Merge branch 'dev' into feature/modlog
binaryoverload May 16, 2021
34a48fa
Move CollectionDiff into utility class
binaryoverload May 22, 2021
4518ae9
General cleanup
binaryoverload May 22, 2021
57e85f3
Improve collection diff algorithm to cope with dupes and add ✨unit te…
binaryoverload May 22, 2021
89d902d
Add separate message as per review
binaryoverload May 22, 2021
699082d
Rename ModlogEventStore to ModlogEventData
binaryoverload May 25, 2021
a284ba9
Format duration util
binaryoverload May 25, 2021
c8e0d9b
Moderation modlog stuff
binaryoverload May 25, 2021
8cbbbe9
More modlog mod stuff
binaryoverload May 25, 2021
54bf625
Fix softban!
binaryoverload May 27, 2021
943d1cc
Unmute modlog!
binaryoverload May 27, 2021
89cda9c
Purge modlog
binaryoverload May 27, 2021
3a541de
Convert modlog utils to Kotlin
binaryoverload May 27, 2021
ed8a4ee
Remove redundant data class
binaryoverload May 27, 2021
4a7dd7b
ModlogEmbedPart: Add language path validity checks
binaryoverload May 27, 2021
d7089a3
Language: Add a quick way to get the default language file
binaryoverload May 27, 2021
0e74320
ModlogEvent: Rename debug to dummy and update comment
binaryoverload May 28, 2021
ebf9b95
Don't find modlog event for restricted commands
binaryoverload May 28, 2021
713a856
Dummy modlog value
binaryoverload May 28, 2021
e268bfa
Split modlog event listener and convert to Kotlin
binaryoverload May 28, 2021
8b78435
Add proper gettings to Config to work with Kotlin
binaryoverload May 28, 2021
dbe6fed
Add emotes to channel perm overrides
binaryoverload May 28, 2021
4c129b1
Merge branch 'feature/modlog' into feature/guilddata
weeryan17 May 29, 2021
f06f7ce
Formatting and tidying up
binaryoverload May 29, 2021
392f89d
Refactor filter create command to fit with modlog
binaryoverload May 29, 2021
c024027
ModlogEvent: Add appropriate values for command filters
binaryoverload May 29, 2021
d1010cb
Find the difference between any arbitrary object
weeryan17 May 29, 2021
4c24807
More util stuff
binaryoverload May 29, 2021
d129e25
Modlog event for filter creation
binaryoverload May 29, 2021
73c475d
Merge branch 'feature/modlog' into feature/guilddata
weeryan17 May 29, 2021
8f2b3ac
Saving parts of guild data
weeryan17 May 29, 2021
d6847c4
Update guild in cache
weeryan17 May 29, 2021
2bc0200
If the item is replaced, don't save it!
binaryoverload May 29, 2021
1a42772
Change streams
weeryan17 May 29, 2021
58528c6
Remove save listener
weeryan17 May 29, 2021
00ca47d
Write mode, and start of implementing writing everywhere
weeryan17 May 29, 2021
44cf309
Handle update data without full document
weeryan17 May 30, 2021
8fafe1d
Add command filters to modlog
binaryoverload May 30, 2021
ba081ba
assertWriteMode
weeryan17 May 30, 2021
3c6cfb5
No thread for watching
weeryan17 May 30, 2021
4f9876a
Command filter modlog, operator and type updates
binaryoverload May 30, 2021
d500951
Copy old buttons and pages
weeryan17 May 30, 2021
892d38f
Wrap permission commands in write
weeryan17 May 30, 2021
1009abb
Wrap tag commands in write
weeryan17 May 30, 2021
d194597
Wrap todo commands in write
weeryan17 May 31, 2021
3ae0597
Wrap music commands in write
weeryan17 May 31, 2021
17293a9
Wrap persistent buttons in write
weeryan17 May 31, 2021
4dcca4b
Write mode on MDC (correct branch this time)
weeryan17 May 31, 2021
3583c65
Start trying to fix some bson to java conversions
weeryan17 May 31, 2021
7d5e898
Store the object class so we can decode it later
weeryan17 May 31, 2021
258a8c7
Send an error if we can't find class to use to decode
weeryan17 May 31, 2021
69f50f5
Cleanup and documentation
weeryan17 May 31, 2021
f1dc9d6
Test change
binaryoverload Jun 4, 2021
4cc7feb
Add functions for better Kotlin interop
binaryoverload Jun 4, 2021
1533193
Revert "Add functions for better Kotlin interop"
binaryoverload Jun 4, 2021
bbeb4fa
Merge pull request #258 from CascadeBot/feature/guilddata-pr
weeryan17 Jun 4, 2021
b794118
Use writeInline
binaryoverload Jun 5, 2021
1309af6
Move change stream setup into separate file for clarity
binaryoverload Jun 5, 2021
ecce74c
Revert "Move change stream setup into separate file for clarity"
binaryoverload Jun 5, 2021
5aa9405
Make sure ModlogEvents map is immutable and methods protected
binaryoverload Jun 12, 2021
bf39e0f
Get class for decoding from from field
weeryan17 Jun 13, 2021
9db5ce1
Remove object class as it is no longer needed
weeryan17 Jun 13, 2021
fe5faba
Merge branch 'dev' into feature/guilddata
weeryan17 Jul 20, 2021
6fdb56c
Minor fixes and clean up
weeryan17 Jul 20, 2021
06f209a
Merge pull request #254 from CascadeBot/feature/guilddata
weeryan17 Jul 22, 2021
a8bf163
Wrap modlog guild data calls in write
weeryan17 Jul 22, 2021
eb44603
Fix some data stuffs
weeryan17 Jul 29, 2021
7a88c3b
Attempts at fixing guild data stuffs
weeryan17 Jul 29, 2021
3d7b850
More stuff
binaryoverload Aug 8, 2021
da19ce5
I made a deep copy method that works!
weeryan17 Aug 12, 2021
cd9b604
Start work on better diff
weeryan17 Aug 13, 2021
7f13247
Allow custom comparator in CollectionDiff
weeryan17 Aug 13, 2021
45018da
More diff stuffs
weeryan17 Aug 13, 2021
372d4fe
Get change stream logic (mostly) worked out
weeryan17 Sep 1, 2021
aeb374d
Goodbye reflection
weeryan17 Sep 2, 2021
bf8a2c4
Remove legacy code
weeryan17 Sep 2, 2021
612df20
Bson decoding on guild data
weeryan17 Sep 2, 2021
f223b4d
Bson decoding of core settings
weeryan17 Sep 2, 2021
094960c
Fix oversight in guild data
weeryan17 Sep 2, 2021
a1907c5
Bson decoding of useful settings
weeryan17 Sep 2, 2021
a096143
Bson decoding of moderation settings
weeryan17 Sep 2, 2021
361c55f
Bson decoding of management settings
weeryan17 Sep 2, 2021
23ad109
Bson decoding of music settings
weeryan17 Sep 2, 2021
7700d79
Merge branch 'dev' into feature/modlog
weeryan17 Sep 2, 2021
27c49bf
Fix the merge
weeryan17 Sep 2, 2021
afde810
Handle removed data
weeryan17 Sep 3, 2021
0708006
Use new bson generator that actually supports everything
weeryan17 Sep 3, 2021
4b004f8
I pulled a binary
weeryan17 Sep 3, 2021
0232f0f
Fix some bugs in data handler
weeryan17 Sep 3, 2021
6412979
Fix guild data not being updated correctly
weeryan17 Sep 3, 2021
4766037
More attempts to get saving to work with the new system.
weeryan17 Sep 3, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,16 @@ haste:

web:
# The secret to use when authenticating with the site/wrapper
secret_key:
secret_key:

# The redis server to connect to. If you don't specify a redis server then the bot will not log messages for modlog
redis:
host: '127.0.0.1'
port: 6379
password: ''

# If this is specified all sub fields are required to have encryption
encryption_key:
key: 'AES key, 256 bit recommended'
iv: '64 bit iv key'
weeryan17 marked this conversation as resolved.
Show resolved Hide resolved
mac: '128 bit mac key'
26 changes: 25 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<properties>
<build.number>DEV</build.number>
<jda.version>4.0.0_39</jda.version>
<jda.version>4.1.1_154</jda.version>
<lavaplayer.version>1.3.47</lavaplayer.version>
<lavalink.client.version>f9ab37f</lavalink.client.version>
<kotlin.version>1.3.72</kotlin.version>
Expand Down Expand Up @@ -297,6 +297,11 @@
<artifactId>emoji-java</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.65</version>
</dependency>

<!-- Web -->
<dependency>
Expand Down Expand Up @@ -348,6 +353,13 @@
<artifactId>mongodb-driver-sync</artifactId>
<version>3.9.1</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.2.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
Expand Down Expand Up @@ -425,6 +437,18 @@
<version>64.2</version>
</dependency>

<!-- Benchmark -->
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.19</version>
</dependency>

weeryan17 marked this conversation as resolved.
Show resolved Hide resolved
</dependencies>

</project>
17 changes: 17 additions & 0 deletions src/benchmark/java/org/cascadebot/cascadebot/CascadeBenchmark.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.cascadebot.cascadebot;

import org.openjdk.jmh.runner.RunnerException;

import java.io.IOException;

public class CascadeBenchmark {

public static void main(String... args) {
try {
org.openjdk.jmh.Main.main(args);
} catch (RunnerException | IOException e) {
e.printStackTrace();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.cascadebot.cascadebot;

import org.cascadebot.cascadebot.utils.CryptUtils;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.ShortBufferException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;

@State(Scope.Benchmark)
public class CryptUtilsBenchmark {

int hmacI = 0;
int normalI = 0;

List<String> testStrings = new ArrayList<>();

@Setup
public void setup() {
Random random = new Random();
for (int i = 0; i < 400; i++) {
byte[] bytes = new byte[random.nextInt(2000)];
random.nextBytes(bytes);
testStrings.add(new String(bytes));
}
}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void runHmacBenchmark() throws NoSuchPaddingException, BadPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IllegalBlockSizeException, ShortBufferException, InvalidKeyException {
byte[] key = "eThWmZq4t7wbzbCbFbJbNcRfUjXn2r5u".getBytes();
byte[] hashKey = "bJaNdRfU".getBytes();
byte[] iv = "u8x/A?D*G-KaPdSg".getBytes();
String testString = testStrings.get(hmacI % 400);
CryptUtils.encryptString(key, iv, hashKey, testString);
hmacI++;
}

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void runNormalBenchmark() throws NoSuchPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, ShortBufferException {
byte[] key = "eThWmZq4t7wbzbCbFbJbNcRfUjXn2r5u".getBytes();
byte[] iv = "u8x/A?D*G-KaPdSg".getBytes();
String testString = testStrings.get(normalI % 400);
CryptUtils.encryptString(key, iv, testString);
normalI++;
}

}
39 changes: 39 additions & 0 deletions src/main/java/org/cascadebot/cascadebot/CascadeBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import ch.qos.logback.contrib.json.classic.JsonLayout;
import ch.qos.logback.core.ConsoleAppender;
import ch.qos.logback.core.encoder.LayoutWrappingEncoder;
import club.minnced.discord.webhook.WebhookClient;
import club.minnced.discord.webhook.WebhookClientBuilder;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.sedmelluq.discord.lavaplayer.jdaudp.NativeAudioSendFactory;
Expand All @@ -35,18 +37,23 @@
import org.cascadebot.cascadebot.events.CommandListener;
import org.cascadebot.cascadebot.events.GeneralEventListener;
import org.cascadebot.cascadebot.events.JDAEventMetricsListener;
import org.cascadebot.cascadebot.events.MessageEventListener;
import org.cascadebot.cascadebot.events.ModlogEventListener;
import org.cascadebot.cascadebot.events.VoiceEventListener;
import org.cascadebot.cascadebot.metrics.Metrics;
import org.cascadebot.cascadebot.moderation.ModerationManager;
import org.cascadebot.cascadebot.music.MusicHandler;
import org.cascadebot.cascadebot.permissions.PermissionsManager;
import org.cascadebot.cascadebot.runnables.MessageReceivedRunnable;
import org.cascadebot.cascadebot.tasks.Task;
import org.cascadebot.cascadebot.utils.EventWaiter;
import org.cascadebot.cascadebot.utils.LogbackUtils;
import org.cascadebot.shared.Version;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.exceptions.JedisConnectionException;

import javax.annotation.Nonnull;
import javax.security.auth.login.LoginException;
Expand Down Expand Up @@ -74,6 +81,9 @@ public class CascadeBot {
private OkHttpClient httpClient;
private MusicHandler musicHandler;
private EventWaiter eventWaiter;
private Jedis redisClient;

private MessageReceivedRunnable messageReceivedRunnable;

public static void main(String[] args) {
try (Scanner scanner = new Scanner(CascadeBot.class.getResourceAsStream("/version.txt"))) {
Expand Down Expand Up @@ -142,6 +152,20 @@ private void init() {
return;
}

if (Config.INS.getRedisHost() != null) {
redisClient = new Jedis(Config.INS.getRedisHost(), Config.INS.getRedisPort());
if (Config.INS.getRedisPassword() != null) {
redisClient.auth(Config.INS.getRedisPassword());
}
try {
redisClient.ping("Hello!");
LOGGER.info("Redis connected!");
} catch (JedisConnectionException e) {
LOGGER.warn("Failed to connect to redis", e);
weeryan17 marked this conversation as resolved.
Show resolved Hide resolved
redisClient = null;
}
}

// Sends a message to break up the status log flow to see what events apply to each bot run
Config.INS.getEventWebhook().send(
UnicodeConstants.ZERO_WIDTH_SPACE + "\n" +
Expand All @@ -158,6 +182,9 @@ private void init() {
builder.setPrettyPrinting();
}

messageReceivedRunnable = new MessageReceivedRunnable();
new Thread(messageReceivedRunnable, "messageHandleThread").start();

if (Config.INS.getConnectionString() != null) {
databaseManager = new DatabaseManager(Config.INS.getConnectionString());
} else {
Expand All @@ -182,6 +209,7 @@ private void init() {
.addEventListeners(new ButtonEventListener())
.addEventListeners(new VoiceEventListener())
.addEventListeners(new JDAEventMetricsListener())
.addEventListeners(new ModlogEventListener())
.addEventListeners(eventWaiter)
.setToken(Config.INS.getBotToken())
.setShardsTotal(-1)
Expand All @@ -202,6 +230,10 @@ private void init() {
defaultShardManagerBuilder.setAudioSendFactory(new NativeAudioSendFactory());
}

if (redisClient != null) {
defaultShardManagerBuilder.addEventListeners(new MessageEventListener());
}

shardManager = defaultShardManagerBuilder.build();
} catch (LoginException e) {
LOGGER.error("Error building JDA", e);
Expand Down Expand Up @@ -318,4 +350,11 @@ public long getUptime() {
return System.currentTimeMillis() - startupTime;
}

public Jedis getRedisClient() {
return redisClient;
}

public MessageReceivedRunnable getMessageReceivedRunnable() {
return messageReceivedRunnable;
}
weeryan17 marked this conversation as resolved.
Show resolved Hide resolved
}
Loading