added few more easter egg stuff, then added archive system
This commit is contained in:
parent
518185d9c0
commit
3e860cc90c
2
zer10hdbot/.settings/org.eclipse.core.resources.prefs
Executable file
2
zer10hdbot/.settings/org.eclipse.core.resources.prefs
Executable file
@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/main/java/zer01hd/zer10hdbot/listeners/MessageListener.java=UTF-8
|
31
zer10hdbot/archives/2017/11/18.txt
Executable file
31
zer10hdbot/archives/2017/11/18.txt
Executable file
@ -0,0 +1,31 @@
|
||||
Archive of: 2017-11-18T00:00
|
||||
Archive of: 2017-11-18T00:00
|
||||
†2017-11-18T23:55:39.831† 243501084876865536:Zer01HD™: so this is a test
|
||||
Archive of: 2017-11-18T00:00
|
||||
†2017-11-18T23:55:44.395† 243501084876865536:Zer01HD™: everthing should now be archived
|
||||
Archive of: 2017-11-18T00:00
|
||||
†2017-11-18T23:55:46.887† 243501084876865536:Zer01HD™: from this point on
|
||||
Archive of: 2017-11-18T00:00
|
||||
†2017-11-18T23:56:15.662† 243501084876865536:Zer01HD™: heheheh
|
||||
Archive of: 2017-11-18T00:00
|
||||
†2017-11-18T23:56:20.557† 243501084876865536:Zer01HD™: nothing can escape anymore...
|
||||
Archive of: 2017-11-18T00:00
|
||||
†2017-11-18T23:56:23.954† 243501084876865536:Zer01HD™: you can delete
|
||||
Archive of: 2017-11-18T00:00
|
||||
†2017-11-18T23:56:36.335† 243501084876865536:Zer01HD™: you can cry
|
||||
Archive of: 2017-11-18T00:00
|
||||
†2017-11-18T23:56:40.661† 243501084876865536:Zer01HD™: but you can't hide
|
||||
Archive of: 2017-11-18T00:00
|
||||
†2017-11-18T23:56:49.088† 243501084876865536:Zer01HD™: whatever you typed... probably.
|
||||
Archive of: 2017-11-18T00:00
|
||||
†2017-11-18T23:56:53.160† 243501084876865536:Zer01HD™: now the question is
|
||||
Archive of: 2017-11-18T00:00
|
||||
†2017-11-18T23:56:59.994† 243501084876865536:Zer01HD™: how accessible should i make this archive
|
||||
Archive of: 2017-11-18T00:00
|
||||
†2017-11-18T23:59:48.762† 243501084876865536:Zer01HD™: test
|
||||
†2017-11-18T23:59:48.762† 243501084876865536:Zer01HD™: okay
|
||||
†2017-11-18T23:59:48.762† 243501084876865536:Zer01HD™: and now we wait
|
||||
†2017-11-18T23:59:48.762† 243501084876865536:Zer01HD™: to see if the archive properly organizes dates...
|
||||
†2017-11-18T23:59:48.762† 243501084876865536:Zer01HD™: oh hey look
|
||||
†2017-11-18T23:59:48.762† 243501084876865536:Zer01HD™: its 12
|
||||
†2017-11-18T23:59:48.762† 243501084876865536:Zer01HD™: meaning, its the next dayh
|
122
zer10hdbot/archives/2017/11/19.txt
Executable file
122
zer10hdbot/archives/2017/11/19.txt
Executable file
@ -0,0 +1,122 @@
|
||||
Archive of: 2017-11-19T00:00
|
||||
†2017-11-19T00:01:24.270† 243501084876865536:Zer01HD™: uhh
|
||||
†2017-11-19T00:01:27.719† 243501084876865536:Zer01HD™: things should be updating...
|
||||
†2017-11-19T00:01:29.693† 243501084876865536:Zer01HD™: uh oh.
|
||||
†2017-11-19T00:01:43.072† 243501084876865536:Zer01HD™: nvm
|
||||
†2017-11-19T00:01:44.172† 243501084876865536:Zer01HD™: it worked
|
||||
†2017-11-19T00:01:46.418† 243501084876865536:Zer01HD™: cause im a boss
|
||||
†2017-11-19T00:04:59.413† 243501084876865536:Zer01HD™: hmmm
|
||||
†2017-11-19T00:05:10.773† 243501084876865536:Zer01HD™: seems a bit... ?
|
||||
†2017-11-19T00:05:16.647† 243501084876865536:Zer01HD™: these are all filler messages
|
||||
†2017-11-19T00:06:32.742† 243501084876865536:Zer01HD™: okay for the most part, its working
|
||||
†2017-11-19T00:07:34.238† 243501084876865536:Zer01HD™: bots log and commands not being archived...
|
||||
†2017-11-19T00:08:51.635† 243501084876865536:Zer01HD™: now absolutely everthing has to be archived?
|
||||
†2017-11-19T00:08:59.812† 243501084876865536:Zer01HD™: `archive date values
|
||||
†2017-11-19T00:08:59.901† 347642826777165824:Zer10HD-Bot: Compared archive date values (current date vs archive initiation date):
|
||||
`2017-11-19T00:08:59.812 vs 2017-11-19T00:00`
|
||||
†2017-11-19T00:09:20.842† 243501084876865536:Zer01HD™: that command seems a bit long...
|
||||
†2017-11-19T00:09:25.420† 243501084876865536:Zer01HD™: `archive dates
|
||||
†2017-11-19T00:09:25.514† 347642826777165824:Zer10HD-Bot: Compared archive date values (current date vs archive initiation date):
|
||||
`2017-11-19T00:09:25.420 vs 2017-11-19T00:00`
|
||||
†2017-11-19T00:09:27.757† 243501084876865536:Zer01HD™: there
|
||||
†2017-11-19T00:09:37.931† 243501084876865536:Zer01HD™: okay... more filler text
|
||||
†2017-11-19T00:09:40.674† 243501084876865536:Zer01HD™: random
|
||||
†2017-11-19T00:09:41.853† 243501084876865536:Zer01HD™: words
|
||||
†2017-11-19T00:09:42.393† 243501084876865536:Zer01HD™: goes
|
||||
†2017-11-19T00:09:43.117† 243501084876865536:Zer01HD™: here
|
||||
†2017-11-19T00:09:44.657† 243501084876865536:Zer01HD™: please
|
||||
†2017-11-19T00:09:45.878† 243501084876865536:Zer01HD™: don't
|
||||
†2017-11-19T00:09:46.645† 243501084876865536:Zer01HD™: bother
|
||||
†2017-11-19T00:09:47.558† 243501084876865536:Zer01HD™: reading
|
||||
†2017-11-19T00:09:48.089† 243501084876865536:Zer01HD™: this
|
||||
†2017-11-19T00:11:01.445† 243501084876865536:Zer01HD™: auto flushing?
|
||||
†2017-11-19T00:11:02.195† 243501084876865536:Zer01HD™: now
|
||||
†2017-11-19T00:11:03.003† 243501084876865536:Zer01HD™: ?
|
||||
†2017-11-19T00:11:12.667† 243501084876865536:Zer01HD™: `archive flush
|
||||
Archive of: 2017-11-19T00:00
|
||||
†2017-11-19T00:11:36.416† 243501084876865536:Zer01HD™: another
|
||||
†2017-11-19T00:11:41.028† 243501084876865536:Zer01HD™: long
|
||||
†2017-11-19T00:11:43.544† 243501084876865536:Zer01HD™: string
|
||||
†2017-11-19T00:11:45.616† 243501084876865536:Zer01HD™: of
|
||||
†2017-11-19T00:11:47.223† 243501084876865536:Zer01HD™: messages
|
||||
†2017-11-19T00:12:01.138† 243501084876865536:Zer01HD™: not exactly auto flushing....
|
||||
†2017-11-19T00:12:04.481† 243501084876865536:Zer01HD™: this is bothersome...
|
||||
†2017-11-19T00:14:16.528† 243501084876865536:Zer01HD™: `archive flush
|
||||
†2017-11-19T00:14:16.658† 347642826777165824:Zer10HD-Bot: the archive volatile files have been written to.
|
||||
†2017-11-19T00:14:25.144† 243501084876865536:Zer01HD™: so
|
||||
†2017-11-19T00:14:27.507† 243501084876865536:Zer01HD™: `archive flush
|
||||
Archive of: 2017-11-19T00:00
|
||||
†2017-11-19T00:15:58.454† 243501084876865536:Zer01HD™: okay
|
||||
†2017-11-19T00:15:59.273† 243501084876865536:Zer01HD™: so now
|
||||
†2017-11-19T00:16:02.173† 243501084876865536:Zer01HD™: every 16 messages
|
||||
†2017-11-19T00:16:05.932† 243501084876865536:Zer01HD™: an auto flush occurs
|
||||
†2017-11-19T00:16:14.084† 243501084876865536:Zer01HD™: `archive flush
|
||||
†2017-11-19T00:16:14.200† 347642826777165824:Zer10HD-Bot: the archive volatile files have been written to.
|
||||
†2017-11-19T00:16:16.298† 243501084876865536:Zer01HD™: starting
|
||||
†2017-11-19T00:16:16.771† 243501084876865536:Zer01HD™: now
|
||||
†2017-11-19T00:16:20.344† 243501084876865536:Zer01HD™: we
|
||||
†2017-11-19T00:16:22.099† 243501084876865536:Zer01HD™: are
|
||||
†2017-11-19T00:16:22.592† 243501084876865536:Zer01HD™: at
|
||||
†2017-11-19T00:16:24.894† 243501084876865536:Zer01HD™: 5
|
||||
†2017-11-19T00:16:26.099† 243501084876865536:Zer01HD™: lines
|
||||
†2017-11-19T00:16:28.711† 243501084876865536:Zer01HD™: 7
|
||||
†2017-11-19T00:16:29.910† 243501084876865536:Zer01HD™: 8
|
||||
†2017-11-19T00:16:30.430† 243501084876865536:Zer01HD™: 9
|
||||
†2017-11-19T00:16:31.379† 243501084876865536:Zer01HD™: 10
|
||||
†2017-11-19T00:16:32.054† 243501084876865536:Zer01HD™: 11
|
||||
†2017-11-19T00:16:32.400† 243501084876865536:Zer01HD™: 12
|
||||
†2017-11-19T00:16:32.710† 243501084876865536:Zer01HD™: 13
|
||||
†2017-11-19T00:16:32.982† 243501084876865536:Zer01HD™: 14
|
||||
†2017-11-19T00:16:34.935† 243501084876865536:Zer01HD™: 15
|
||||
Archive of: 2017-11-19T00:00
|
||||
†2017-11-19T00:55:08.435† 243501084876865536:Zer01HD™: `archive flush
|
||||
†2017-11-19T00:55:08.536† 347642826777165824:Zer10HD-Bot: the archive volatile files have been written to.
|
||||
†2017-11-19T00:55:10.384† 243501084876865536:Zer01HD™: test
|
||||
†2017-11-19T00:55:12.275† 243501084876865536:Zer01HD™: test
|
||||
†2017-11-19T00:55:12.754† 243501084876865536:Zer01HD™: test
|
||||
†2017-11-19T00:55:13.130† 243501084876865536:Zer01HD™: test
|
||||
†2017-11-19T00:55:15.231† 243501084876865536:Zer01HD™: `archive flush
|
||||
†2017-11-19T00:55:15.322† 347642826777165824:Zer10HD-Bot: the archive volatile files have been written to.
|
||||
†2017-11-19T00:55:23.907† 243501084876865536:Zer01HD™: 1
|
||||
†2017-11-19T00:55:24.183† 243501084876865536:Zer01HD™: 2
|
||||
†2017-11-19T00:55:24.376† 243501084876865536:Zer01HD™: 3
|
||||
†2017-11-19T00:55:24.609† 243501084876865536:Zer01HD™: 4
|
||||
†2017-11-19T00:55:24.811† 243501084876865536:Zer01HD™: 5
|
||||
†2017-11-19T00:55:25.046† 243501084876865536:Zer01HD™: 6
|
||||
†2017-11-19T00:55:25.239† 243501084876865536:Zer01HD™: 7
|
||||
†2017-11-19T00:55:25.480† 243501084876865536:Zer01HD™: 8
|
||||
†2017-11-19T00:55:27.278† 243501084876865536:Zer01HD™: 9
|
||||
†2017-11-19T00:55:28.156† 243501084876865536:Zer01HD™: 19
|
||||
†2017-11-19T00:55:33.981† 243501084876865536:Zer01HD™: 1929
|
||||
†2017-11-19T00:55:34.069† 243501084876865536:Zer01HD™: 19231923
|
||||
†2017-11-19T00:55:34.176† 243501084876865536:Zer01HD™: 12312312933129312931293129
|
||||
†2017-11-19T00:55:34.277† 243501084876865536:Zer01HD™: 123912391239123932193291921339213912
|
||||
†2017-11-19T00:55:40.656† 243501084876865536:Zer01HD™: 1
|
||||
†2017-11-19T00:55:41.076† 243501084876865536:Zer01HD™: 1
|
||||
Archive of: 2017-11-19T00:00
|
||||
†2017-11-19T01:08:45.950† 243501084876865536:Zer01HD™: there we go
|
||||
†2017-11-19T01:08:52.243† 243501084876865536:Zer01HD™: `archive batch size
|
||||
†2017-11-19T01:08:52.346† 347642826777165824:Zer10HD-Bot: current message batch size (unflushed messages): 3
|
||||
Auto flushing every 16 messages in batch. Run `archive flush` to force flush immediately. Recommended before retrieving currently active archive.
|
||||
†2017-11-19T01:09:00.764† 243501084876865536:Zer01HD™: and now
|
||||
†2017-11-19T01:09:06.696† 243501084876865536:Zer01HD™: if the bot ever crashes for some reason
|
||||
†2017-11-19T01:09:18.611† 243501084876865536:Zer01HD™: the time when the archive stopped logging is logged.
|
||||
†2017-11-19T01:09:21.100† 243501084876865536:Zer01HD™: freakin great
|
||||
†2017-11-19T01:09:23.701† 243501084876865536:Zer01HD™: `batch size
|
||||
†2017-11-19T01:09:29.265† 243501084876865536:Zer01HD™: `archive batch size
|
||||
†2017-11-19T01:09:29.345† 347642826777165824:Zer10HD-Bot: current message batch size (unflushed messages): 10
|
||||
Auto flushing every 16 messages in batch. Run `archive flush` to force flush immediately. Recommended before retrieving currently active archive.
|
||||
†2017-11-19T01:10:58.210† 243501084876865536:Zer01HD™: 1
|
||||
†2017-11-19T01:10:58.553† 243501084876865536:Zer01HD™: 2
|
||||
†2017-11-19T01:10:58.823† 243501084876865536:Zer01HD™: 3
|
||||
†2017-11-19T01:10:59.099† 243501084876865536:Zer01HD™: 4
|
||||
†2017-11-19T01:10:59.312† 243501084876865536:Zer01HD™: 5
|
||||
†2017-11-19T01:11:05.585† 243501084876865536:Zer01HD™: `archive batch
|
||||
Archive begin logging at: 2017-11-19T00:00
|
||||
Archive begin logging at: 2017-11-19T00:00
|
||||
†2017-11-19T01:12:10.766† 243501084876865536:Zer01HD™: test
|
||||
†2017-11-19T01:12:12.800† 243501084876865536:Zer01HD™: `archive flush
|
||||
Archive began logging at: 2017-11-19T00:00
|
||||
Archive began logging at: 2017-11-19T00:00
|
||||
Archive began logging at: 2017-11-19T00:00
|
||||
Archive began logging at: 2017-11-19T00:00
|
@ -6,6 +6,7 @@ import javax.security.auth.login.LoginException;
|
||||
|
||||
import net.dv8tion.jda.core.AccountType;
|
||||
import net.dv8tion.jda.core.JDABuilder;
|
||||
import net.dv8tion.jda.core.entities.Game;
|
||||
import net.dv8tion.jda.core.exceptions.RateLimitedException;
|
||||
|
||||
public class Main {
|
||||
@ -28,6 +29,7 @@ public class Main {
|
||||
JDABuilder jdab;
|
||||
if (!ninja) {
|
||||
jdab = new JDABuilder(AccountType.BOT);
|
||||
jdab.setGame(Game.of("with your soul"));
|
||||
} else {
|
||||
jdab = new JDABuilder(AccountType.CLIENT);
|
||||
}
|
||||
@ -64,6 +66,16 @@ public class Main {
|
||||
|
||||
z10b.cmdPrefix = in.nextLine();
|
||||
System.out.println("command prefix set: " + z10b.cmdPrefix);
|
||||
} else if (command.equals("run hotswap script")) {
|
||||
System.out.println("running hotswap script...");
|
||||
z10b.tempScript();
|
||||
} else if (command.equals("tttw")) {
|
||||
System.out.println("What would you like to send to the weebs?");
|
||||
if (z10b.jda.getGuildById(348161059175006208l) != null) {
|
||||
z10b.jda.getGuildById(348161059175006208l).getTextChannels().get(0).sendMessage(in.nextLine()).queue();
|
||||
} else {
|
||||
System.out.println("error sending to channel. Null channel.");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
@ -8,6 +8,7 @@ import javax.security.auth.login.LoginException;
|
||||
import net.dv8tion.jda.core.JDA;
|
||||
import net.dv8tion.jda.core.JDABuilder;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.Member;
|
||||
import net.dv8tion.jda.core.events.Event;
|
||||
import net.dv8tion.jda.core.events.ReadyEvent;
|
||||
import net.dv8tion.jda.core.exceptions.RateLimitedException;
|
||||
@ -17,7 +18,7 @@ import zer01hd.zer10hdbot.listeners.SelfEventListener;
|
||||
|
||||
public class Zer10HDBot {
|
||||
public JDA jda;
|
||||
public String cmdPrefix = ".";
|
||||
public String cmdPrefix = "`";
|
||||
|
||||
public Zer10HDBot(JDABuilder jdab) throws LoginException, IllegalArgumentException, RateLimitedException {
|
||||
jdab.addEventListener(new EventListener() {
|
||||
@ -49,4 +50,15 @@ public class Zer10HDBot {
|
||||
System.out.println("JDA didn't finish building the bot yet...");
|
||||
}
|
||||
}
|
||||
|
||||
public void tempScript() {
|
||||
Guild guild = jda.getGuildsByName("Weeabism", true).get(0);
|
||||
if (guild != null) {
|
||||
Member member = guild.getMembersByEffectiveName("Poi!?", true).get(0);
|
||||
if (member != null) {
|
||||
System.out.println(member.getUser().getId());
|
||||
}
|
||||
}
|
||||
System.out.println("heh");
|
||||
}
|
||||
}
|
||||
|
80
zer10hdbot/src/main/java/zer01hd/zer10hdbot/archive/ArchiveManager.java
Executable file
80
zer10hdbot/src/main/java/zer01hd/zer10hdbot/archive/ArchiveManager.java
Executable file
@ -0,0 +1,80 @@
|
||||
package zer01hd.zer10hdbot.archive;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
|
||||
public class ArchiveManager {
|
||||
private Path rootArchives;
|
||||
private File monthDir;
|
||||
private TextFile archive;
|
||||
private LocalDateTime textInitDate;
|
||||
private LocalDateTime currentDate;
|
||||
private DateTimeFormatter dirDateFormat = DateTimeFormatter.ofPattern("yyyy/MM/dd");
|
||||
private DateTimeFormatter dirMonthFormat = DateTimeFormatter.ofPattern("yyyy/MM");
|
||||
|
||||
public ArchiveManager() {
|
||||
rootArchives = Paths.get("archives");
|
||||
setupArchive();
|
||||
validateArchive();
|
||||
}
|
||||
|
||||
public boolean validateArchive() {
|
||||
currentDate = LocalDateTime.now();
|
||||
if (!dirDateFormat.format(currentDate).equals(dirDateFormat.format(textInitDate))) {
|
||||
setupArchive();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public TextFile getArchive() {
|
||||
return archive;
|
||||
}
|
||||
|
||||
public void writeToArchive(String string) {
|
||||
validateArchive();
|
||||
archive.write("†" + currentDate.toString()+ "† " + string);
|
||||
}
|
||||
|
||||
public LocalDateTime getCurrentDate() {
|
||||
return currentDate;
|
||||
}
|
||||
|
||||
public LocalDateTime getTextInitDate() {
|
||||
return textInitDate;
|
||||
}
|
||||
|
||||
public void setupArchive() {
|
||||
currentDate = LocalDateTime.now();
|
||||
monthDir = new File(rootArchives.toFile(), dirMonthFormat.format(currentDate));
|
||||
monthDir.mkdirs();
|
||||
if (archive != null) {
|
||||
archive.closeFile();
|
||||
}
|
||||
archive = new TextFile(monthDir.toPath(), String.valueOf(currentDate.getDayOfMonth()));
|
||||
textInitDate = LocalDateTime.of(Integer.valueOf(monthDir.getParentFile().getName()), Integer.valueOf(monthDir.getName()), Integer.valueOf(archive.getFile().getName().substring(0, archive.getFile().getName().length() - ".txt".length())), 0, 0);
|
||||
archive.write("Archive began logging at: " + textInitDate.toString() + "\n");
|
||||
archive.flush();
|
||||
}
|
||||
|
||||
public File obtainArchive(String date) {
|
||||
date = date.replace('/', '-');
|
||||
date = date.concat("T00:00:00");
|
||||
LocalDateTime givenDate;
|
||||
try {
|
||||
givenDate = LocalDateTime.parse(date);
|
||||
} catch (DateTimeParseException e) {
|
||||
System.out.println("Error with date. Couldn't retrieve archive.");
|
||||
return null;
|
||||
}
|
||||
File archivedFile = new File(rootArchives.toFile(), dirDateFormat.format(givenDate) + ".txt");
|
||||
if (archivedFile.exists()) {
|
||||
return archivedFile;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package zer01hd.zer10hdbot.archive;
|
||||
|
||||
import net.dv8tion.jda.core.entities.MessageChannel;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
|
||||
public class ArchiveUserController implements Runnable {
|
||||
private User user;
|
||||
private MessageChannel channel;
|
||||
|
||||
public ArchiveUserController(User user, MessageChannel channel) {
|
||||
this.user = user;
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
private boolean enabled;
|
||||
@Override
|
||||
public void run() {
|
||||
while (enabled) {
|
||||
channel.sendMessage(user.getAsMention() + " what is the date of the archive file you would like to see? Please organize date in the following format: yyyy/MM/dd").queue();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
80
zer10hdbot/src/main/java/zer01hd/zer10hdbot/archive/TextFile.java
Executable file
80
zer10hdbot/src/main/java/zer01hd/zer10hdbot/archive/TextFile.java
Executable file
@ -0,0 +1,80 @@
|
||||
package zer01hd.zer10hdbot.archive;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class TextFile {
|
||||
private FileWriter fileWriter;
|
||||
private PrintWriter printWriter;
|
||||
private File file;
|
||||
private boolean append = true;
|
||||
private int messageInBatchCount;
|
||||
|
||||
/**
|
||||
* Default append is true
|
||||
* A standard object to help write text files.
|
||||
* @param file
|
||||
*/
|
||||
public TextFile(Path path, String textFileName) {
|
||||
this.file = new File(path.toString(), textFileName + ".txt");
|
||||
|
||||
try {
|
||||
this.fileWriter = new FileWriter(file, append);
|
||||
this.printWriter = new PrintWriter(fileWriter);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void write(String string) {
|
||||
messageInBatchCount++;
|
||||
printWriter.println(string);
|
||||
|
||||
if (messageInBatchCount > 16) {
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
public void setAppend(boolean append) {
|
||||
closeFile();
|
||||
|
||||
try {
|
||||
this.fileWriter = new FileWriter(file, append);
|
||||
this.printWriter = new PrintWriter(fileWriter, true);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.append = append;
|
||||
}
|
||||
|
||||
public void closeFile() {
|
||||
try {
|
||||
flush();
|
||||
printWriter.close();
|
||||
fileWriter.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
try {
|
||||
fileWriter.flush();
|
||||
messageInBatchCount = 0;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public int getMessageInBatchCount() {
|
||||
return messageInBatchCount;
|
||||
}
|
||||
}
|
@ -1,38 +1,48 @@
|
||||
package zer01hd.zer10hdbot.listeners;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Calendar;
|
||||
import java.util.Random;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.dv8tion.jda.core.entities.Message;
|
||||
import net.dv8tion.jda.core.entities.MessageChannel;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.core.hooks.ListenerAdapter;
|
||||
import zer01hd.zer10hdbot.Zer10HDBot;
|
||||
import zer01hd.zer10hdbot.archive.ArchiveManager;
|
||||
|
||||
public class MessageListener extends ListenerAdapter {
|
||||
Zer10HDBot z10b;
|
||||
ArchiveManager am;
|
||||
|
||||
Random rand = new Random();
|
||||
|
||||
public MessageListener(Zer10HDBot z10b) {
|
||||
this.z10b = z10b;
|
||||
am = new ArchiveManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(MessageReceivedEvent event) {
|
||||
// User user = event.getAuthor();
|
||||
User user = event.getAuthor();
|
||||
Message message = event.getMessage();
|
||||
MessageChannel channel = event.getChannel();
|
||||
|
||||
String msg = message.getContent();
|
||||
|
||||
if (event.getGuild().getId().equals("348161059175006208")) {
|
||||
am.writeToArchive(user.getId() + ":" + user.getName() + ": " + msg);
|
||||
|
||||
}
|
||||
|
||||
if (msg.equals(z10b.cmdPrefix)) {
|
||||
channel.sendMessage("Fool! Your doing it all wrong. You need an actual command after that.").queue();
|
||||
} else if (msg.equalsIgnoreCase("ping") || msg.substring(z10b.cmdPrefix.length()).equalsIgnoreCase("ping")) {
|
||||
channel.sendMessage("pong").queue();
|
||||
|
||||
} else if (msg.startsWith(z10b.cmdPrefix)) {
|
||||
msg = msg.substring(z10b.cmdPrefix.length());
|
||||
|
||||
if (msg.equalsIgnoreCase("ping")) {
|
||||
if (msg.equalsIgnoreCase("roll")) {
|
||||
|
||||
int roll = rand.nextInt(6) + 1;
|
||||
channel.sendMessage("Your roll: " + roll).queue(sentMessage -> {
|
||||
@ -47,6 +57,80 @@ public class MessageListener extends ListenerAdapter {
|
||||
break;
|
||||
}
|
||||
});
|
||||
} else if (msg.equalsIgnoreCase("plan-c")) {
|
||||
channel.sendMessage("lets not do that yet...").queue();
|
||||
} else if (msg.equalsIgnoreCase("ping")) {
|
||||
channel.sendMessage("pong").queue(sentMessage -> {
|
||||
channel.sendMessage("Actual ping: " + event.getJDA().getPing()).queue();
|
||||
});
|
||||
} else if (msg.equalsIgnoreCase("tableflip")) {
|
||||
channel.sendMessage("(╯°□°)╯︵ ┻━┻").queue();
|
||||
} else if (msg.equals("self-destruct")) {
|
||||
channel.sendMessage("doesn't sound like a good idea.").queue();
|
||||
} else if (msg.equals("guess")) {
|
||||
channel.sendMessage("no").queue();
|
||||
} else if (msg.contains(" delete chain") || msg.contains(" chain delete") || msg.contains(" omae wa shindeiru")) {
|
||||
if (user.getId().equals("243501084876865536")) {
|
||||
int toDelete = 4;
|
||||
try {
|
||||
toDelete = Integer.valueOf(msg.substring(0, 2).trim());
|
||||
} catch (NumberFormatException nfe) {
|
||||
}
|
||||
int counter = 0;
|
||||
for (Message delete : channel.getIterableHistory()) {
|
||||
delete.delete().queue();
|
||||
counter++;
|
||||
try {
|
||||
Thread.sleep(1000l);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (counter > toDelete) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
channel.sendMessage("You don't have enough _dark energy_!").queue();
|
||||
}
|
||||
} else if (event.getGuild().getId().equals("348161059175006208")) {
|
||||
|
||||
if (msg.equalsIgnoreCase("archive validity check")) {
|
||||
channel.sendMessage("archive will be tested.").queue();
|
||||
channel.sendMessage(!am.validateArchive() ? "archive has been corrected." : "archive is valid.").queue();
|
||||
}
|
||||
if (msg.equalsIgnoreCase("archive info")) {
|
||||
channel.sendMessage("Compared archive date values (current date vs archive initiation date): \n`" + am.getCurrentDate() + " vs " + am.getTextInitDate() + "`").queue();
|
||||
}
|
||||
|
||||
if (msg.equalsIgnoreCase("archive name")) {
|
||||
channel.sendMessage("Current archives name: `" + am.getArchive().getFile().getName() + "`").queue();
|
||||
}
|
||||
if (msg.equalsIgnoreCase("archive month")) {
|
||||
channel.sendMessage("Current archives month: `" + am.getArchive().getFile().getParentFile().getName() + "`").queue();
|
||||
}
|
||||
|
||||
if (msg.equalsIgnoreCase("archive flush")) {
|
||||
am.getArchive().flush();
|
||||
channel.sendMessage("the archive volatile files have been written to.").queue();
|
||||
}
|
||||
|
||||
if (msg.startsWith("archive retrieve")) {
|
||||
String date = msg.substring(16).trim();
|
||||
File archivedFile = am.obtainArchive(date);
|
||||
System.out.println();
|
||||
if (!date.isEmpty() && archivedFile != null) {
|
||||
channel.sendFile(archivedFile, null).queue();
|
||||
channel.sendMessage("Your archive has been uploaded.").queue();
|
||||
} else {
|
||||
channel.sendMessage("Error, either could not find archive for that date, or please verify the date of the archive file you would like to retrieve in the following format: yyyy/MM/dd").queue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (msg.equalsIgnoreCase("archive batch size")) {
|
||||
channel.sendMessage("current message batch size (unflushed messages): " + am.getArchive().getMessageInBatchCount() + "\n"
|
||||
+ "Auto flushing every 16 messages in batch. Run `archive flush` (with prefix) to force flush immediately. Recommended before retrieving currently active archive.").queue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -64,14 +148,14 @@ public class MessageListener extends ListenerAdapter {
|
||||
break;
|
||||
case 2:
|
||||
Calendar dueCal = Calendar.getInstance();
|
||||
dueCal.set(2017, 8, 17, 20, 55);
|
||||
dueCal.set(2017, 7, 27, 20, 55);
|
||||
Calendar current = Calendar.getInstance();
|
||||
|
||||
float minutes = dueCal.getTimeInMillis() - current.getTimeInMillis();
|
||||
minutes /= 1000;
|
||||
minutes /= 60;
|
||||
|
||||
preNotedMsg = "ya ya if you stop talking about *that* ill release it in:" + minutes + " minutes";
|
||||
preNotedMsg = "ya ya if you stop talking about *that* ill release it in: " + minutes + " minutes";
|
||||
break;
|
||||
case 3:
|
||||
preNotedMsg = "STOP IT.";
|
||||
@ -82,6 +166,75 @@ public class MessageListener extends ListenerAdapter {
|
||||
}
|
||||
channel.sendMessage("Prenoted message from Zer01HD: \"" + preNotedMsg + "\"").queue();
|
||||
});
|
||||
} else if (!user.isBot()) {
|
||||
if (event.getGuild().getId().equals("348161059175006208")) {
|
||||
int chance = rand.nextInt(16)+1;
|
||||
if (chance == 1) {
|
||||
message.addReaction(event.getGuild().getEmotesByName("Poi", false).get(0)).queue();
|
||||
}
|
||||
if (msg.toLowerCase().contains("@zer01hd")) {
|
||||
// channel.sendMessage("gone fishing :thumbsup:").queue();
|
||||
}
|
||||
if (msg.toLowerCase().contains("demon")) {
|
||||
channel.sendMessage("_cringe_").queue();
|
||||
}
|
||||
|
||||
if (msg.toLowerCase().equals("nyanpasu")) {
|
||||
channel.sendMessage("nyanpasu!").queue();
|
||||
}
|
||||
|
||||
if (msg.toLowerCase().contains("loli")) {
|
||||
Pattern p = Pattern.compile(".*\\b(loli|lolis|lolicon|lolicons|loliconics)\\b.*");
|
||||
Matcher m = p.matcher(msg.toLowerCase());
|
||||
if (m.matches()) {
|
||||
channel.sendMessage("https://i.imgur.com/z2DyGWj.gif").queue();
|
||||
}
|
||||
}
|
||||
|
||||
if (msg.toLowerCase().contains("guilty") && (msg.toLowerCase().contains("rekai") || msg.toLowerCase().contains("paoda"))) {
|
||||
channel.sendMessage("indeed.").queue();
|
||||
channel.sendMessage("https://drive.google.com/file/d/1kYFs6MuyeavKF4oZ0-qjWVr3luSVzwvj/view?usp=sharing").queue();
|
||||
}
|
||||
}
|
||||
if (msg.contains("YUNYANG")) {
|
||||
int rng = rand.nextInt(2);
|
||||
switch (rng) {
|
||||
case 0:
|
||||
if (user.getId().equals("242768094773248000")) {
|
||||
channel.sendMessage("Yep, it is my duty to call you a lolicon Nichol. My programmer told me so.").queue();
|
||||
channel.sendMessage("https://i.imgur.com/z2DyGWj.gif").queue();
|
||||
} else if (user.getId().equals("139546076955803648")) {
|
||||
channel.sendMessage(". Closet lolicon. Rekai.").queue();
|
||||
} else if (user.getId().equals("243501084876865536")) {
|
||||
channel.sendMessage("Uhhh...");
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
channel.sendMessage("SIR YES SIR!").queue();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
if (msg.toLowerCase().contains("facepalm*")) {
|
||||
int rng = rand.nextInt(5);
|
||||
switch (rng) {
|
||||
case 0:
|
||||
channel.sendMessage("https://i.pinimg.com/originals/df/2d/a3/df2da37278e0270d873015fb5613e57a.jpg").queue();
|
||||
break;
|
||||
case 1:
|
||||
channel.sendMessage("http://i0.kym-cdn.com/photos/images/newsfeed/000/173/877/Facepalm.gif").queue();
|
||||
break;
|
||||
case 2:
|
||||
channel.sendMessage("http://animediet.net/wp-content/uploads/2010/05/kyonfacepalm.jpg").queue();
|
||||
break;
|
||||
case 3:
|
||||
channel.sendMessage("http://images5.fanpop.com/image/photos/30900000/Dawn-facepalm-a-misty-dawn-of-may-30913860-640-480.png").queue();
|
||||
break;
|
||||
case 4:
|
||||
channel.sendMessage("https://s-media-cache-ak0.pinimg.com/originals/df/2d/a3/df2da37278e0270d873015fb5613e57a.jpg").queue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
super.onMessageReceived(event);
|
||||
}
|
||||
|
@ -8,6 +8,9 @@ public class SelfEventListener extends ListenerAdapter {
|
||||
@Override
|
||||
public void onGuildJoin(GuildJoinEvent event) {
|
||||
TextChannel channel = event.getGuild().getPublicChannel();
|
||||
if (channel == null) {
|
||||
channel = event.getGuild().getTextChannels().get(0);
|
||||
}
|
||||
if (channel.canTalk()) {
|
||||
channel.sendMessage("YHD's doppelgänger is here! Sort of. Limited functionality for now.").queue();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user