Getting messages just fine

This commit is contained in:
Norbi Peti 2018-06-04 02:22:21 +02:00
parent 7f78b8d81b
commit 716ce0d186
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
7 changed files with 130 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
target/
Token.txt

13
.idea/compiler.xml Normal file
View 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 Normal file
View 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 Normal file
View 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>

View file

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />

38
pom.xml Normal file
View 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>

View 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();
}
}