Browse Source

Fixed Crashed and added PermissionCheck

master
Niklas H. 1 month ago
parent
commit
4f78914e6a
15 changed files with 371 additions and 138 deletions
  1. +1
    -1
      .idea/vcs.xml
  2. +3
    -2
      CountDownDiscordBot.iml
  3. +10
    -2
      dependency-reduced-pom.xml
  4. +11
    -5
      pom.xml
  5. +0
    -47
      src/main/java/de/moddylp/bot/Main.java
  6. +0
    -31
      src/main/java/de/moddylp/bot/commands/InfoCommand.java
  7. +75
    -0
      src/main/java/de/moddylp/wolftimerbot/Main.java
  8. +63
    -46
      src/main/java/de/moddylp/wolftimerbot/commands/CountDown.java
  9. +66
    -0
      src/main/java/de/moddylp/wolftimerbot/commands/InfoCommand.java
  10. +39
    -0
      src/main/java/de/moddylp/wolftimerbot/commands/RoleListener.java
  11. +30
    -0
      src/main/java/de/moddylp/wolftimerbot/extension/MonitorExtension.java
  12. +31
    -0
      src/main/java/de/moddylp/wolftimerbot/extension/MonitorHook.java
  13. +14
    -4
      src/main/java/de/moddylp/wolftimerbot/storage/JsonStorage.java
  14. +27
    -0
      src/main/resources/logback.xml
  15. +1
    -0
      start.bat

+ 1
- 1
.idea/vcs.xml View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="" vcs="Git" />
</component>
</project>

+ 3
- 2
CountDownDiscordBot.iml View File

@@ -6,7 +6,6 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
@@ -23,6 +22,8 @@
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-simple:1.7.30" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.2.3" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.2.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.18.12" level="project" />
</component>
</module>

+ 10
- 2
dependency-reduced-pom.xml View File

@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.moddylp</groupId>
<artifactId>CountDownDiscordBot</artifactId>
<version>2020032901</version>
<version>2020040701</version>
<build>
<plugins>
<plugin>
@@ -19,7 +19,7 @@
<configuration>
<archive>
<manifest>
<mainClass>de.moddylp.bot.Main</mainClass>
<mainClass>de.moddylp.wolftimerbot.Main</mainClass>
</manifest>
</archive>
</configuration>
@@ -45,4 +45,12 @@
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

+ 11
- 5
pom.xml View File

@@ -6,7 +6,7 @@

<groupId>de.moddylp</groupId>
<artifactId>CountDownDiscordBot</artifactId>
<version>2020032901</version>
<version>2020040701</version>
<build>
<plugins>
<plugin>
@@ -24,7 +24,7 @@
<configuration>
<archive>
<manifest>
<mainClass>de.moddylp.bot.Main</mainClass>
<mainClass>de.moddylp.wolftimerbot.Main</mainClass>
</manifest>
</archive>
</configuration>
@@ -68,9 +68,15 @@
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.30</version>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
</dependencies>


+ 0
- 47
src/main/java/de/moddylp/bot/Main.java View File

@@ -1,47 +0,0 @@
package de.moddylp.bot;

import com.mewna.catnip.Catnip;
import de.moddylp.bot.commands.CountDown;
import de.moddylp.bot.commands.InfoCommand;
import de.moddylp.bot.storage.JsonStorage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main {

private static Catnip catnip;
public static Logger logger;


public static void main(String[] args) {
logger = LoggerFactory.getLogger(Main.class);
logger.info("Errors?: "+logger.isErrorEnabled());
try {
JsonStorage storage = new JsonStorage();
String token = storage.getJsonObj().getOrDefault("token", "##").toString();
if (token == null || token.trim().isEmpty() || token.contains("#")) {
logger.error("Please provide a token");
System.exit(1);
} else {
Catnip.catnipAsync(token).subscribe(catnip -> {
Main.catnip = catnip;
new InfoCommand(catnip).init();
new CountDown(catnip).init();
catnip.connect();
logger.info("Started");
});
}
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
System.exit(1);
}
Runtime.getRuntime().addShutdownHook(new Thread()
{
public void run()
{
logger.info("Shutdown !");
catnip.shutdown();
}
});
}
}

+ 0
- 31
src/main/java/de/moddylp/bot/commands/InfoCommand.java View File

@@ -1,31 +0,0 @@
package de.moddylp.bot.commands;

import com.mewna.catnip.Catnip;
import com.mewna.catnip.entity.impl.message.EmbedImpl;
import com.mewna.catnip.shard.DiscordEvent;

public class InfoCommand {
private Catnip catnip;

public InfoCommand(Catnip catnip) {
this.catnip = catnip;
}

public void init() {
catnip.observable(DiscordEvent.MESSAGE_CREATE)
.filter(msg -> msg.content().startsWith(">ping"))
.subscribe(msg -> {
msg.channel().sendMessage(msg.content()+" <= Dont poke me").subscribe(res -> {
System.out.println("MSG edit");
});
msg.delete();
}, Throwable::printStackTrace);
catnip.observable(DiscordEvent.MESSAGE_CREATE)
.filter(msg -> msg.content().startsWith(">help"))
.subscribe(msg -> {
msg.author().createDM().subscribe(dm -> {
dm.sendMessage("Hilfe");
});
}, Throwable::printStackTrace);
}
}

+ 75
- 0
src/main/java/de/moddylp/wolftimerbot/Main.java View File

@@ -0,0 +1,75 @@
package de.moddylp.wolftimerbot;

import com.mewna.catnip.Catnip;
import com.mewna.catnip.CatnipOptions;
import com.mewna.catnip.entity.user.Presence;
import com.mewna.catnip.shard.DiscordEvent;
import com.mewna.catnip.shard.LifecycleEvent;
import de.moddylp.wolftimerbot.commands.CountDown;
import de.moddylp.wolftimerbot.commands.InfoCommand;
import de.moddylp.wolftimerbot.extension.MonitorExtension;
import de.moddylp.wolftimerbot.storage.JsonStorage;
import org.slf4j.LoggerFactory;

public class Main {

private static Catnip catnip;
public static org.slf4j.Logger logger;
public static JsonStorage storage;


public static void main(String[] args) {
logger = LoggerFactory.getLogger(Main.class);
logger.info("Errors?: " + logger.isErrorEnabled());
try {
storage = new JsonStorage(args);
String token = storage.getJsonObj().getOrDefault("token", "##").toString();
if (token == null || token.trim().isEmpty() || token.contains("#")) {
logger.error("Please provide a token");
System.exit(1);
} else {
catnip = Catnip.catnip(new CatnipOptions(token));
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
logger.info("Shutdown !");
catnip.shutdown();
}
});
logger.info("Initialized");
catnip.observable(DiscordEvent.GUILD_UNAVAILABLE).subscribe(guild -> {
logger.error("Guild is down: " + guild.toString());
});
catnip.observable(LifecycleEvent.CONNECTED).subscribe(guild -> {
logger.info("ONLINE");
catnip.presence(Presence.OnlineStatus.ONLINE, "Werwolf", Presence.ActivityType.PLAYING, "");
});
catnip.observable(LifecycleEvent.DISCONNECTED).subscribe(guild -> {
logger.info("OFFLINE");
});
catnip.observable(LifecycleEvent.WEBSOCKET_CONNECTION_FAILED).subscribe(websocket -> {
logger.info("WS Connection failed: " + websocket.error().getMessage());
logger.info("Reconnecting");
catnip.shardManager().shardIds().forEach(integer -> {
catnip.shardManager().addToConnectQueue(integer);
});

});
catnip.observable(LifecycleEvent.HIGH_WEBSOCKET_LATENCY).subscribe(websocket -> {
logger.info("WS Latency High: " + websocket.latency());
});
catnip.loadExtension(new MonitorExtension());
new InfoCommand(catnip).init();
new CountDown(catnip).init();
//new RoleListener(catnip).init(); TODO: Permission?
catnip.connect();

logger.info("Started");
}
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
System.exit(1);
}

}

}

src/main/java/de/moddylp/bot/commands/CountDown.java → src/main/java/de/moddylp/wolftimerbot/commands/CountDown.java View File

@@ -1,25 +1,27 @@
package de.moddylp.bot.commands;
package de.moddylp.wolftimerbot.commands;

import com.mewna.catnip.Catnip;
import com.mewna.catnip.entity.impl.guild.EmojiUpdateImpl;
import com.mewna.catnip.entity.impl.message.EmbedImpl;
import com.mewna.catnip.entity.impl.misc.UnicodeEmojiImpl;
import com.mewna.catnip.entity.message.Message;
import com.mewna.catnip.rest.guild.MemberData;
import com.mewna.catnip.shard.DiscordEvent;
import de.moddylp.bot.Main;
import de.moddylp.wolftimerbot.Main;

import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicReference;

public class CountDown {
private final ExecutorService executor;
private Catnip catnip;
private EmbedImpl emb;

;

public CountDown(Catnip catnip) {
this.catnip = catnip;
this.executor = Executors.newCachedThreadPool();
@@ -29,34 +31,42 @@ public class CountDown {
catnip.observable(DiscordEvent.MESSAGE_CREATE)
.filter(msg -> msg.content().startsWith(">startc"))
.subscribe(msg -> {
msg.delete("Command removed").doOnError(throwable -> {
Main.logger.error("Cant react: "+throwable.getMessage());
});
emb = new EmbedImpl().title("Wolf-Timer").description("Der Timer startet gleich").timestamp(OffsetDateTime.now().toString()).fields(new ArrayList<>());
String[] args = msg.content().split(" ");
if (args[1] != null && args[2] != null && msg.mentionedRoles().size() > 0) {
if (args[1] != null && args[2] != null && msg.mentionedRoles().size() > 0 && !msg.mentionsEveryone()) {
int time = Integer.parseInt(args[1]);
timeUnit unit = timeUnit.SECOND;
if (args[2].equalsIgnoreCase("m")) {
unit = timeUnit.MINUTE;
}
timeUnit finalUnit = unit;
try {
int time = Integer.parseInt(args[1]);
timeUnit unit = timeUnit.SECOND;
if (args[2].equalsIgnoreCase("m")) {
unit = timeUnit.MINUTE;
} else if (args[2].equalsIgnoreCase("s")) {
unit = timeUnit.SECOND;
}
timeUnit finalUnit = unit;
msg.channel().sendMessage(emb.description("Timer wurde gestartet")).subscribe(msgres -> {
startCounter(time, finalUnit, msg, msgres, emb);
}, error -> {
msg.channel().sendMessage("Can't edit Embed. " + error.getMessage());
});
} catch (Exception ex) {
msg.channel().sendMessage(emb.description("Etwas ist schief gelaufen"));
} catch (Throwable throwable) {
msg.channel().sendMessage("Can't edit Embed. " + throwable.getMessage());
}
} else {
msg.channel().sendMessage(emb.description("Du musst den Command so eingeben: >startc 10 s @role"));
msg.channel().sendMessage(emb.description("Du musst den Command so eingeben: >startc 10 s @role")).subscribe((res, error) -> {
msg.channel().sendMessage("Can't edit Embed. " + error.getMessage());
});
}
msg.delete();
}, throwable -> {
Main.logger.error("Cant start timer -> ", throwable);
Main.logger.error(throwable.getMessage());
});
catnip.observable(DiscordEvent.MESSAGE_CREATE)
.filter(msg -> msg.content().startsWith(">demute"))
.subscribe(msg -> {
msg.delete("Command removed").doOnError(throwable -> {
Main.logger.error("Cant react: "+throwable.getMessage());
});
emb = new EmbedImpl().title("Wolf-Timer").description("Der Timer startet gleich").timestamp(OffsetDateTime.now().toString()).fields(new ArrayList<>());
if (msg.mentionedRoles().size() > 0) {
try {
@@ -67,13 +77,11 @@ public class CountDown {
if (data.roles().contains(role.id()) && msg.guildId() != null) {
if (msg.guild().channel(data.channelId()).isVoice()) {
Main.logger.info("Muted Member: " + member.user().username());
catnip.rest().guild().modifyGuildMember(Objects.requireNonNull(msg.guildId()), member.id(), new MemberData().mute(false).channelId(data.channelId())).subscribe(() -> {
catnip.rest().guild().modifyGuildMember(Objects.requireNonNull(msg.guildId()), member.id(), data.mute(false), "Werwolf-Spiel").subscribe(() -> {
Main.logger.info(member.user().username() + " demutet");
}, throwable -> {
if (!throwable.getMessage().contains("204")) {
Main.logger.error("Cant demute: " + member.user().username() + " -> ", throwable);
} else {
Main.logger.info("supress");
Main.logger.error("Cant demute: " + member.user().username() + " -> "+throwable.getMessage());
}
});
}
@@ -81,13 +89,15 @@ public class CountDown {
});

});
msg.channel().sendMessage(emb.description("Alle wurden wieder entmutet")).doOnError(error -> {
msg.channel().sendMessage("Can't edit Embed. " + error.getMessage());
});
} catch (Exception ex) {
msg.channel().sendMessage(emb.description("Etwas ist schief gelaufen"));
}
} else {
msg.channel().sendMessage(emb.description("Du musst den Command so eingeben: >demute @role"));
}
msg.delete();
}, throwable -> {
Main.logger.error("Cant demute ", throwable);
});
@@ -120,37 +130,44 @@ public class CountDown {
public void run() {
try {
int z = 0;
emb.edit(embed.description("Timer: " + (end - z) + " s"));
emb.edit(embed.description("Timer läuft: " + (end - z) + " s")).doOnError(error -> {
emb.channel().sendMessage("Can't edit Embed. " + error.getMessage());
});
while (z < end) {
Thread.sleep(1000);
if ((end - z) % 2 == 0) {
emb.edit(embed.description(embed.description().replace((end - z) + " s", (end - (z + 2)) + " s")));
Main.logger.info("Running:" + (end - (z + 1)) + " s" + "Mod: " + (end - z) % 5);
if ((end - z) % 5 == 0) {
emb.edit(embed.description("Timer läuft: " + (end - z) + " s")).doOnError(error -> {
emb.channel().sendMessage("Can't edit Embed. " + error.getMessage());
});
}
Main.logger.info("Running:" + (end - (z + 1)) + " s"+ "Mod: "+(end - z) % 2);
z++;
}
msg.mentionedRoles().forEach(role -> {
Main.logger.info("Muted Role:" + role.name());
Objects.requireNonNull(msg.guild()).members().forEach(member -> {
MemberData data = MemberData.of(member);
if (data.roles().contains(role.id()) && msg.guildId() != null) {
if (msg.guild().channel(data.channelId()).isVoice()) {
Main.logger.info("Muted Member: " + member.user().username());
catnip.rest().guild().modifyGuildMember(Objects.requireNonNull(msg.guildId()), member.id(), new MemberData().mute(true).channelId(data.channelId())).subscribe(() -> {
Main.logger.info(member.user().username() + " gemutet");
}, throwable -> {
if (!throwable.getMessage().contains("204")) {
Main.logger.error("Cant demute: " + member.user().username() + " -> ", throwable);
} else {
Main.logger.info("supress");
}
});

if (msg.mentionedRoles().size() > 0) {
msg.mentionedRoles().forEach(role -> {
Main.logger.info("Muted Role:" + role.name());
Objects.requireNonNull(msg.guild()).members().forEach(member -> {
MemberData data = MemberData.of(member);
if (data.roles().contains(role.id()) && msg.guildId() != null) {
if (msg.guild() != null && data.channelId() != null && msg.guild().channel(data.channelId()).isVoice()) {
Main.logger.info("Muted Member: " + member.user().username());
catnip.rest().guild().modifyGuildMember(Objects.requireNonNull(msg.guildId()), member.id(), data.mute(true), "Werwolf-Spiel").subscribe(() -> {
Main.logger.info(member.user().username() + " gemutet");
}, throwable -> {
if (!throwable.getMessage().contains("204")) {
Main.logger.error("Cant mute: " + member.user().username()+" "+throwable.getMessage());
}
});
}
}
}
});
});

});
}
emb.edit(embed.description("Die Zeit ist rum!! Alle wurden gemutet")).doOnError(error -> {
emb.channel().sendMessage("Can't edit Embed. " + error.getMessage());
});
emb.edit(embed.description("Die Zeit ist rum!! Alle wurden gemutet"));
} catch (Exception ex) {
Main.logger.error("Interrupt ", ex);
}

+ 66
- 0
src/main/java/de/moddylp/wolftimerbot/commands/InfoCommand.java View File

@@ -0,0 +1,66 @@
package de.moddylp.wolftimerbot.commands;

import com.mewna.catnip.Catnip;
import com.mewna.catnip.entity.guild.Role;
import com.mewna.catnip.entity.util.Permission;
import com.mewna.catnip.rest.guild.MemberData;
import com.mewna.catnip.shard.DiscordEvent;
import com.mewna.catnip.util.PermissionUtil;
import de.moddylp.wolftimerbot.Main;

public class InfoCommand {
private Catnip catnip;

public InfoCommand(Catnip catnip) {
this.catnip = catnip;
}

public void init() {
catnip.observable(DiscordEvent.MESSAGE_CREATE)
.filter(msg -> msg.content().startsWith(">ping"))
.subscribe(msg -> {
long start = System.currentTimeMillis();
msg.channel().sendMessage("Dont poke me. Calculating time").subscribe(pong -> {
long end = System.currentTimeMillis();
pong.edit(pong.content().replace("Calculating time"," Took: "+(end-start)+" ms"));
}, error -> msg.channel().sendMessage("!!Missing Edit Permission!!"));
msg.delete();
}, thro -> Main.logger.error("Error: ", thro));
catnip.observable(DiscordEvent.MESSAGE_CREATE)
.filter(msg -> msg.content().startsWith(">help"))
.subscribe(msg -> {
msg.delete("Command remove").doOnError(error -> {
msg.channel().sendMessage("Cant delete command: "+error.getMessage());
});
msg.author().createDM().subscribe(dm -> {
String missingpermisisons = "Alle Anforderungen erfüllt";
try {
MemberData data = MemberData.of(msg.member());
if (msg.guildId() != null) {
if (msg.guild().channel(data.channelId()).isVoice()) {
PermissionUtil.checkPermissions(catnip, msg.guildId(), data.channelId(),
Permission.MUTE_MEMBERS, Permission.VIEW_CHANNEL);
}
}
PermissionUtil.checkPermissions(catnip, msg.guildId(), msg.channelId(),
Permission.ADMINISTRATOR,
Permission.ADD_REACTIONS,
Permission.SEND_MESSAGES,
Permission.VIEW_CHANNEL,
Permission.READ_MESSAGE_HISTORY,
Permission.EMBED_LINKS,
Permission.MANAGE_MESSAGES);
/*PermissionUtil.checkHierarchy(msg.member(), msg.guild());
if (msg.mentionedRoles().size() > 0) {
for (Role mentionedRole : msg.mentionedRoles()) {
PermissionUtil.checkHierarchy(mentionedRole, msg.guild());
}
}*/
} catch (Throwable throwable) {
missingpermisisons = throwable.getMessage();
}
dm.sendMessage("Überprüft alle Anforderungen: \n"+missingpermisisons);
});
}, thro -> Main.logger.error("Error: ", thro));
}
}

+ 39
- 0
src/main/java/de/moddylp/wolftimerbot/commands/RoleListener.java View File

@@ -0,0 +1,39 @@
package de.moddylp.wolftimerbot.commands;

import com.mewna.catnip.Catnip;
import com.mewna.catnip.entity.guild.Role;
import com.mewna.catnip.rest.guild.MemberData;
import com.mewna.catnip.shard.DiscordEvent;
import de.moddylp.wolftimerbot.Main;

public class RoleListener {
private Catnip catnip;

public RoleListener(Catnip catnip) {
this.catnip = catnip;
}

public void init() {
catnip.on(DiscordEvent.GUILD_MEMBER_UPDATE, (member, partialMember) -> {
MemberData data = MemberData.of(member);
for (String id : partialMember.roleIds()) {
Role role = catnip.cache().role(partialMember.guildId(), id);
Main.logger.debug(String.format("%s",role));
String nick = data.nickname();
if ( role != null && role.name().contains(Main.storage.getJsonObj().getOrDefault("geistrole", "Geister").toString())) {
catnip.rest().guild().modifyGuildMember(
member.guildId(),
member.id(),
data.nickname((nick != null ? nick: member.user().username() + " [TOD]")
)).subscribe(() -> Main.logger.info("Updated Nick"), error -> Main.logger.error(error.getMessage()));
} else if (nick != null && nick.contains("[TOD]")) {
catnip.rest().guild().modifyGuildMember(
member.guildId(),
member.id(),
data.nickname(nick.replace("[TOD]", "").trim())
).subscribe(() -> Main.logger.info("Updated Nick"), error -> Main.logger.error(error.getMessage()));;
}
}
});
}
}

+ 30
- 0
src/main/java/de/moddylp/wolftimerbot/extension/MonitorExtension.java View File

@@ -0,0 +1,30 @@
package de.moddylp.wolftimerbot.extension;

import com.mewna.catnip.Catnip;
import com.mewna.catnip.extension.AbstractExtension;
import com.mewna.catnip.extension.Extension;
import com.mewna.catnip.extension.hook.CatnipHook;
import com.mewna.catnip.shard.event.DoubleEventType;
import com.mewna.catnip.shard.event.EventType;
import com.mewna.catnip.shard.event.MessageConsumer;
import io.reactivex.Flowable;
import io.reactivex.Observable;
import org.apache.commons.lang3.tuple.Pair;

import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

public class MonitorExtension extends AbstractExtension {

public MonitorExtension() {
super("Monitoring Extension");
start();
}
public void start() {
//registerHook(new MonitorHook());
}
}

+ 31
- 0
src/main/java/de/moddylp/wolftimerbot/extension/MonitorHook.java View File

@@ -0,0 +1,31 @@
package de.moddylp.wolftimerbot.extension;

import com.grack.nanojson.JsonObject;
import com.mewna.catnip.extension.hook.CatnipHook;
import com.mewna.catnip.shard.ShardInfo;
import de.moddylp.wolftimerbot.Main;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Arrays;

public class MonitorHook implements CatnipHook {

private ArrayList<String> ignore = new ArrayList<>(Arrays.asList("PRESENCE_UPDATE", "GUILD_CREATE"));

@Override
public JsonObject rawGatewayReceiveHook(@Nonnull ShardInfo shardInfo, @Nonnull JsonObject json) {
if (!ignore.contains(json.getString("t", "NO"))) {
Main.logger.debug("RECEIVE: " + shardInfo.toString() + ": " + json.toString());
}
return json;
}

@Override
public JsonObject rawGatewaySendHook(@Nonnull ShardInfo shardInfo, @Nonnull JsonObject json) {
if (!ignore.contains(json.getString("t", "NO"))) {
Main.logger.debug("SEND: " + shardInfo.toString() + ": " + json.toString());
}
return json;
}
}

src/main/java/de/moddylp/bot/storage/JsonStorage.java → src/main/java/de/moddylp/wolftimerbot/storage/JsonStorage.java View File

@@ -1,5 +1,6 @@
package de.moddylp.bot.storage;
package de.moddylp.wolftimerbot.storage;

import de.moddylp.wolftimerbot.Main;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
@@ -11,11 +12,20 @@ public class JsonStorage {
private File json;
private JSONObject jsonObj = new JSONObject();

public JsonStorage() throws IOException, ParseException {
json = new File("../settings.json");
public JsonStorage(String[] args) throws IOException, ParseException {
json = new File("settings.json");
if (args.length > 0 && args[0].startsWith("--settings=")) {
String path = args[0].split("=")[1];
File temp = new File(path);
if (temp.canRead() && temp.canWrite()) {
json = temp;
}
}
Main.logger.info("Using Settings: "+json.getAbsolutePath());

if (!json.exists() && json.createNewFile()) {
BufferedWriter writer = new BufferedWriter(new FileWriter(json));
writer.write("{\"token\": \"##\"}");
writer.write("{\"token\": \"##\", \"geistrole\": \"Geister\"}");
writer.close();
}
readFile();

+ 27
- 0
src/main/resources/logback.xml View File

@@ -0,0 +1,27 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss} %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="rollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>log-%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>7</maxHistory>
<totalSizeCap>200MB</totalSizeCap>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>3MB</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%d{HH:mm:ss} %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<root level="info">
<appender-ref ref="STDOUT" />
</root>
<logger name="rollingFile" level="trace">
<appender-ref ref="rollingFile" />
</logger>
</configuration>

+ 1
- 0
start.bat View File

@@ -0,0 +1 @@
C:\Users\Niklas\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\193.5233.102\jbr\bin\java -jar target/CountDownDiscordBot-2020033101.jar --settings=settings.json

Loading…
Cancel
Save