Saving it to CSV just like that
This commit is contained in:
parent
716ce0d186
commit
16508000a7
1 changed files with 37 additions and 29 deletions
|
@ -3,37 +3,32 @@ import sx.blah.discord.api.IDiscordClient;
|
||||||
import sx.blah.discord.api.events.IListener;
|
import sx.blah.discord.api.events.IListener;
|
||||||
import sx.blah.discord.handle.impl.events.ReadyEvent;
|
import sx.blah.discord.handle.impl.events.ReadyEvent;
|
||||||
import sx.blah.discord.handle.obj.IChannel;
|
import sx.blah.discord.handle.obj.IChannel;
|
||||||
import sx.blah.discord.handle.obj.IMessage;
|
|
||||||
import sx.blah.discord.util.MessageHistory;
|
import sx.blah.discord.util.MessageHistory;
|
||||||
|
import sx.blah.discord.util.RequestBuffer;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.StandardOpenOption;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Consumer;
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class MainHeh {
|
public class MainHeh {
|
||||||
public static void main(String... args) throws IOException {
|
public static void main(String... args) throws IOException {
|
||||||
IDiscordClient idc = new ClientBuilder().withToken(Files.readAllLines(new File("Token.txt").toPath()).get(0))
|
IDiscordClient idc = new ClientBuilder().withToken(Files.readAllLines(new File("Token.txt").toPath()).get(0))
|
||||||
.registerListener((IListener<ReadyEvent>) event -> {
|
.registerListener((IListener<ReadyEvent>) event -> {
|
||||||
IChannel chan = event.getClient().getChannelByID(249663564057411596L);
|
IChannel chan = event.getClient().getChannelByID(249663564057411596L);
|
||||||
final AtomicInteger x = new AtomicInteger();
|
Pattern patplayer = Pattern.compile("(\\S+).*");
|
||||||
/*while(true) {
|
File f = new File("data.csv");
|
||||||
chan.getMessageHistory(100).stream()
|
f.delete();
|
||||||
.filter(msg -> msg.getContent().matches(
|
long mc = 0;
|
||||||
"(\\S+( \\(formerly.+\\))* joined the game)" +
|
BiConsumer<MessageHistory, Boolean> cmh = (mh, skip) -> {
|
||||||
"|(\\S+ left the game)")
|
RequestBuffer.request(() -> { //? eh
|
||||||
|| (msg.getEmbeds().size()>0&&msg.getEmbeds().get(0).getTitle()!=null
|
try {
|
||||||
&&msg.getEmbeds().get(0).getTitle().matches(
|
Files.write(f.toPath(),
|
||||||
"(Server recovered from a crash - chat connected\\.)"
|
(Iterable<String>) mh.stream().skip(skip ? 1 : 0) //Skip 'from' message to avoid double processing
|
||||||
)))
|
|
||||||
.map(IMessage::getContent).forEach(System.out::println);
|
|
||||||
//break;
|
|
||||||
chan.getMessageHistoryFrom()
|
|
||||||
}*/
|
|
||||||
Consumer<MessageHistory> cmh = mh -> {
|
|
||||||
mh.stream()
|
|
||||||
.filter(msg -> msg.getContent().matches(
|
.filter(msg -> msg.getContent().matches(
|
||||||
"(\\S+( \\(formerly.+\\))* joined the game)" +
|
"(\\S+( \\(formerly.+\\))* joined the game)" +
|
||||||
"|(\\S+ left the game)")
|
"|(\\S+ left the game)")
|
||||||
|
@ -41,14 +36,27 @@ public class MainHeh {
|
||||||
&& msg.getEmbeds().get(0).getTitle().matches(
|
&& msg.getEmbeds().get(0).getTitle().matches(
|
||||||
"(Server recovered from a crash - chat connected\\.)"
|
"(Server recovered from a crash - chat connected\\.)"
|
||||||
)))
|
)))
|
||||||
.map(IMessage::getContent).forEach(System.out::println);
|
.map(msg -> {
|
||||||
|
Matcher m = patplayer.matcher(msg.getContent());
|
||||||
|
return (m.matches()
|
||||||
|
? m.group(1) + (msg.getContent().contains("joined") ? "\tjoin" : "\tleave")
|
||||||
|
: "EVERYBODY\tLEFT")
|
||||||
|
+ "\t" + msg.getTimestamp().toString();
|
||||||
|
})::iterator, StandardOpenOption.CREATE, StandardOpenOption.APPEND);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}).get(); //Wait for completion
|
||||||
};
|
};
|
||||||
MessageHistory mh = chan.getMessageHistoryFrom(Instant.now(), 100);
|
MessageHistory mh = chan.getMessageHistoryFrom(Instant.now(), 100);
|
||||||
cmh.accept(mh);
|
cmh.accept(mh, false);
|
||||||
|
System.out.println("Processed " + (mc += mh.size()) + " messages.");
|
||||||
while (mh.size() > 0) {
|
while (mh.size() > 0) {
|
||||||
|
cmh.accept(mh, true);
|
||||||
mh = chan.getMessageHistoryFrom(mh.get(mh.size() - 1).getLongID(), 100);
|
mh = chan.getMessageHistoryFrom(mh.get(mh.size() - 1).getLongID(), 100);
|
||||||
cmh.accept(mh);
|
System.out.println("Processed " + (mc += mh.size()) + " messages.");
|
||||||
}
|
}
|
||||||
|
System.out.println("DONE!");
|
||||||
}).login();
|
}).login();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue