Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
Add emoji prefix for different alerts
Browse files Browse the repository at this point in the history
Signed-off-by: applenick <[email protected]>
  • Loading branch information
applenick committed Apr 4, 2021
1 parent 4a89028 commit 4ecae85
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 38 deletions.
29 changes: 0 additions & 29 deletions .github/workflows/main.yml

This file was deleted.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>tc.oc.occ</groupId>
<artifactId>Bolty</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.2-SNAPSHOT</version>
<name>Bolty</name>
<description>A minecraft to discord java plugin for Bolt</description>

Expand Down
26 changes: 26 additions & 0 deletions src/main/java/tc/oc/occ/bolt/BotConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public class BotConfig {
private String reportFormat;
private String relayFormat;

private String reportPrefix;
private String autoKillPrefix;
private String matrixPrefix;
private String commandPrefix;

public BotConfig(Configuration config) {
reload(config);
}
Expand All @@ -35,6 +40,11 @@ public void reload(Configuration config) {

this.reportFormat = config.getString("report-format");
this.relayFormat = config.getString("relay-format");

this.reportPrefix = config.getString("prefix.report");
this.autoKillPrefix = config.getString("prefix.autokill");
this.matrixPrefix = config.getString("prefix.matrix");
this.commandPrefix = config.getString("prefix.command");
}

public boolean isEnabled() {
Expand Down Expand Up @@ -76,4 +86,20 @@ public String getRelayFormat() {
private String replaceServerName(String format) {
return format.replace("%server%", getServerName());
}

public String getReportPrefix() {
return reportPrefix;
}

public String getAutoKillPrefix() {
return autoKillPrefix;
}

public String getMatrixPrefix() {
return matrixPrefix;
}

public String getCommandPrefix() {
return commandPrefix;
}
}
6 changes: 4 additions & 2 deletions src/main/java/tc/oc/occ/bolt/BotListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

import net.climaxmc.autokiller.events.AutoKillCheatEvent;
import tc.oc.morpheus.NotifyCommandEvent;
import tc.oc.occ.bolt.DiscordBot.RelayType;
import tc.oc.pgm.community.events.PlayerReportEvent;

public class BotListener implements Listener {

private final DiscordBot bot;

public BotListener(DiscordBot bot) {
this.bot = bot;
}
Expand All @@ -21,12 +23,12 @@ public void onPlayerReport(PlayerReportEvent event) {

@EventHandler
public void onAutoKillerViolation(AutoKillCheatEvent event) {
bot.sendRelay(event.getAlert());
bot.sendRelay(event.getAlert(), RelayType.AUTOKILL);
}

@EventHandler
public void onMorpheusNotify(NotifyCommandEvent event) {
bot.sendRelay(event.getCommand());
bot.sendRelay(event.getCommand(), RelayType.MATRIX);
}

}
27 changes: 24 additions & 3 deletions src/main/java/tc/oc/occ/bolt/DiscordBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public DiscordBot(BotConfig config, Logger logger) {
this.logger = logger;
reload();
}

public BotConfig getConfig() {
return config;
}

public void enable() {
if(config.isEnabled()) {
Expand Down Expand Up @@ -70,13 +74,13 @@ public void sendReport(PlayerReportEvent event) {
.replace("%reporter%", reporter)
.replace("%reported%", reported)
.replace("%reason%", reason);
sendMessage(formatted);
sendMessage(config.getReportPrefix() + formatted);
}

public void sendRelay(String message) {
public void sendRelay(String message, RelayType type) {
if(!config.isRelayCommand()) return;
String formatted = config.getRelayFormat().replace("%message%", message);
sendMessage(formatted);
sendMessage(getPrefix(type) + formatted);
}

public void reload() {
Expand All @@ -92,5 +96,22 @@ private String format(String text) {
text = ChatColor.stripColor(text);
return text;
}

public String getPrefix(RelayType type) {
switch(type) {
case AUTOKILL:
return config.getAutoKillPrefix();
case MATRIX:
return config.getMatrixPrefix();
default:
return config.getCommandPrefix();
}
}

public static enum RelayType {
AUTOKILL,
MATRIX,
COMMAND;
}

}
3 changes: 2 additions & 1 deletion src/main/java/tc/oc/occ/bolt/commands/BotCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import co.aikar.commands.annotation.Dependency;
import co.aikar.commands.annotation.Syntax;
import tc.oc.occ.bolt.DiscordBot;
import tc.oc.occ.bolt.DiscordBot.RelayType;

public class BotCommands extends BaseCommand {

Expand All @@ -17,7 +18,7 @@ public class BotCommands extends BaseCommand {
@Syntax("[message] - Message to relay to discord")
@CommandPermission("bolt.bot")
public void relay(CommandSender sender, String message) {
bot.sendRelay(message);
bot.sendRelay(message, RelayType.COMMAND);
}

}
11 changes: 9 additions & 2 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ types:
# %reporter% - Player who issued report
# %reported% - Player who has been reported
# %reason% - Reason for report
report-format: "[%server%] %reporter% reported %reported%: %reason%"
report-format: "[%server%] **%reporter% reported %reported%: %reason%**"

# Relay - Command based (Used for AutoKiller and via /relay)
#
# Variables
# %server% - Server Name
# %message% - Message provided
relay-format: "[%server%] %message%"
relay-format: "[%server%] %message%"

# Prefix - Emojis used as a prefix for different message types
prefix:
report: ":loudspeaker: "
autokill: ":mouse_three_button: "
matrix: ":warning: "
command: ""

0 comments on commit 4ecae85

Please sign in to comment.