Getting messages just fine
This commit is contained in:
parent
7f78b8d81b
commit
716ce0d186
7 changed files with 130 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
target/
|
||||
Token.txt
|
||||
|
13
.idea/compiler.xml
generated
Normal file
13
.idea/compiler.xml
generated
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="DiscordPlayerStatCollector" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
14
.idea/misc.xml
generated
Normal file
14
.idea/misc.xml
generated
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
2
DiscordPlayerStatCollector.iml
Normal file
2
DiscordPlayerStatCollector.iml
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4" />
|
38
pom.xml
Normal file
38
pom.xml
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>buttondevteam</groupId>
|
||||
<artifactId>DiscordPlayerStatCollector</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.austinv11</groupId>
|
||||
<artifactId>Discord4j</artifactId>
|
||||
<version>master-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
54
src/main/java/MainHeh.java
Normal file
54
src/main/java/MainHeh.java
Normal file
|
@ -0,0 +1,54 @@
|
|||
import sx.blah.discord.api.ClientBuilder;
|
||||
import sx.blah.discord.api.IDiscordClient;
|
||||
import sx.blah.discord.api.events.IListener;
|
||||
import sx.blah.discord.handle.impl.events.ReadyEvent;
|
||||
import sx.blah.discord.handle.obj.IChannel;
|
||||
import sx.blah.discord.handle.obj.IMessage;
|
||||
import sx.blah.discord.util.MessageHistory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.time.Instant;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class MainHeh {
|
||||
public static void main(String... args) throws IOException {
|
||||
IDiscordClient idc = new ClientBuilder().withToken(Files.readAllLines(new File("Token.txt").toPath()).get(0))
|
||||
.registerListener((IListener<ReadyEvent>) event -> {
|
||||
IChannel chan = event.getClient().getChannelByID(249663564057411596L);
|
||||
final AtomicInteger x = new AtomicInteger();
|
||||
/*while(true) {
|
||||
chan.getMessageHistory(100).stream()
|
||||
.filter(msg -> msg.getContent().matches(
|
||||
"(\\S+( \\(formerly.+\\))* joined the game)" +
|
||||
"|(\\S+ left the game)")
|
||||
|| (msg.getEmbeds().size()>0&&msg.getEmbeds().get(0).getTitle()!=null
|
||||
&&msg.getEmbeds().get(0).getTitle().matches(
|
||||
"(Server recovered from a crash - chat connected\\.)"
|
||||
)))
|
||||
.map(IMessage::getContent).forEach(System.out::println);
|
||||
//break;
|
||||
chan.getMessageHistoryFrom()
|
||||
}*/
|
||||
Consumer<MessageHistory> cmh = mh -> {
|
||||
mh.stream()
|
||||
.filter(msg -> msg.getContent().matches(
|
||||
"(\\S+( \\(formerly.+\\))* joined the game)" +
|
||||
"|(\\S+ left the game)")
|
||||
|| (msg.getEmbeds().size() > 0 && msg.getEmbeds().get(0).getTitle() != null
|
||||
&& msg.getEmbeds().get(0).getTitle().matches(
|
||||
"(Server recovered from a crash - chat connected\\.)"
|
||||
)))
|
||||
.map(IMessage::getContent).forEach(System.out::println);
|
||||
};
|
||||
MessageHistory mh = chan.getMessageHistoryFrom(Instant.now(), 100);
|
||||
cmh.accept(mh);
|
||||
while (mh.size() > 0) {
|
||||
mh = chan.getMessageHistoryFrom(mh.get(mh.size() - 1).getLongID(), 100);
|
||||
cmh.accept(mh);
|
||||
}
|
||||
}).login();
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue