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

Commit

Permalink
Integrations: add /me, /try, /dice, /ball support for DiscordSRV
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFaser committed Nov 13, 2023
1 parent a266342 commit 796b1ca
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.flectone.chat.module.FCommand;
import net.flectone.chat.module.FModule;
import net.flectone.chat.module.integrations.IntegrationsModule;
import net.flectone.chat.util.MessageUtil;
import net.flectone.chat.util.RandomUtil;
import org.bukkit.command.Command;
Expand Down Expand Up @@ -54,14 +55,18 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command
if (answers.isEmpty()) return true;

int randomPer = RandomUtil.nextInt(0, answers.size());
String answer = answers.get(randomPer);

String formatString = locale.getVaultString(commandSender, this + ".message");
formatString = MessageUtil.formatPlayerString(commandSender, formatString)
.replace("<answer>", answers.get(randomPer));
.replace("<answer>", answer);

String message = String.join(" ", args);

sendGlobalMessage(cmdSettings.getSender(), cmdSettings.getItemStack(), formatString, message, true);

IntegrationsModule.sendDiscordBall(cmdSettings.getSender(), message, answer);

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.flectone.chat.module.FCommand;
import net.flectone.chat.module.FModule;
import net.flectone.chat.module.integrations.IntegrationsModule;
import net.flectone.chat.util.MessageUtil;
import net.flectone.chat.util.RandomUtil;
import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -79,15 +80,19 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command
.append(locale.getVaultString(commandSender, this + ".format." + cubeType))
.append(" ");
}
String type = (sum >= Integer.parseInt(args[0]) * winCoef) + "-message";

String formatString = locale.getVaultString(commandSender, this + "." + (sum >= Integer.parseInt(args[0]) * winCoef) + "-message")
String formatString = locale.getVaultString(commandSender, this + "." + type)
.replace("<cube>", stringBuilder.toString());

formatString = MessageUtil.formatPlayerString(commandSender, formatString);

String message = MessageUtil.joinArray(args, 1, " ");

sendGlobalMessage(cmdSettings.getSender(), cmdSettings.getItemStack(), formatString, message, true);

IntegrationsModule.sendDiscordDice(cmdSettings.getSender(), stringBuilder.toString(), type);

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.flectone.chat.module.FCommand;
import net.flectone.chat.module.FModule;
import net.flectone.chat.module.integrations.IntegrationsModule;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -51,6 +52,8 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command

sendGlobalMessage(cmdSettings.getSender(), cmdSettings.getItemStack(), formatString, message, true);

IntegrationsModule.sendDiscordMe(cmdSettings.getSender(), message);

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.flectone.chat.module.FCommand;
import net.flectone.chat.module.FModule;
import net.flectone.chat.module.integrations.IntegrationsModule;
import net.flectone.chat.util.MessageUtil;
import net.flectone.chat.util.RandomUtil;
import org.bukkit.command.Command;
Expand Down Expand Up @@ -55,15 +56,19 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command
int good = commands.getInt(getName() + ".good-%");

int randomPer = RandomUtil.nextInt(min, max);
String type = (randomPer >= good) + "-message";

String formatString = locale.getVaultString(cmdSettings.getSender(), this + "." + (randomPer >= good) + "-message")
String formatString = locale.getVaultString(cmdSettings.getSender(), this + "." + type)
.replace("<percent>", String.valueOf(randomPer));

formatString = MessageUtil.formatPlayerString(commandSender, formatString);

String message = MessageUtil.joinArray(args, 0, " ");

sendGlobalMessage(cmdSettings.getSender(), cmdSettings.getItemStack(), formatString, message, true);

IntegrationsModule.sendDiscordTry(cmdSettings.getSender(), message, String.valueOf(randomPer), type);

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,54 @@ public void sendPollMessage(@Nullable OfflinePlayer sender, @NotNull String mess
sendMessage(sender, "poll", replacements);
}

public void sendMeMessage(@Nullable OfflinePlayer sender, @NotNull String message) {
String senderName = sender == null ? "CONSOLE" : sender.getName();

HashMap<String, String> replacements = new HashMap<>();
replacements.put("<player>", senderName);
replacements.put("<message>", message);
sendMessage(sender, "me", replacements);
}

public void sendTryMessage(@Nullable OfflinePlayer sender, @NotNull String message, @NotNull String percent, @NotNull String type) {
String senderName = sender == null ? "CONSOLE" : sender.getName();

assert senderName != null;
String messageConfig = integrations.getString("DiscordSRV.message.try.type." + type)
.replace("<player>", senderName)
.replace("<message>", message)
.replace("<percent>", percent);

HashMap<String, String> replacements = new HashMap<>();
replacements.put("<player>", senderName);
replacements.put("<type>", messageConfig);
sendMessage(sender, "try", replacements);
}

public void sendDiceMessage(@Nullable OfflinePlayer sender, @NotNull String cube, @NotNull String type) {
String senderName = sender == null ? "CONSOLE" : sender.getName();

assert senderName != null;
String messageConfig = integrations.getString("DiscordSRV.message.dice.type." + type)
.replace("<player>", senderName)
.replace("<cube>", cube);

HashMap<String, String> replacements = new HashMap<>();
replacements.put("<player>", senderName);
replacements.put("<type>", messageConfig);
sendMessage(sender, "dice", replacements);
}

public void sendBallMessage(@Nullable OfflinePlayer sender, @NotNull String message, @NotNull String answer) {
String senderName = sender == null ? "CONSOLE" : sender.getName();

HashMap<String, String> replacements = new HashMap<>();
replacements.put("<player>", senderName);
replacements.put("<message>", message);
replacements.put("<answer>", answer);
sendMessage(sender, "ball", replacements);
}

public void sendMessage(@Nullable OfflinePlayer sender, @NotNull String typeMessage, Map<String, String> replacements) {
String path = "DiscordSRV.message." + typeMessage;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,28 @@ public static void sendDiscordPoll(@Nullable OfflinePlayer sender, @NotNull Stri
if (fIntegration == null) return;
((FDiscordSRV) fIntegration).sendPollMessage(sender, message, id);
}

public static void sendDiscordMe(@Nullable OfflinePlayer sender, @NotNull String message) {
FIntegration fIntegration = get("DiscordSRV");
if (fIntegration == null) return;
((FDiscordSRV) fIntegration).sendMeMessage(sender, message);
}

public static void sendDiscordTry(@Nullable OfflinePlayer sender, @NotNull String message, @NotNull String percent, @NotNull String type) {
FIntegration fIntegration = get("DiscordSRV");
if (fIntegration == null) return;
((FDiscordSRV) fIntegration).sendTryMessage(sender, message, percent, type);
}

public static void sendDiscordDice(@Nullable OfflinePlayer sender, @NotNull String cube, @NotNull String type) {
FIntegration fIntegration = get("DiscordSRV");
if (fIntegration == null) return;
((FDiscordSRV) fIntegration).sendDiceMessage(sender, cube, type);
}

public static void sendDiscordBall(@Nullable OfflinePlayer sender, @NotNull String message, @NotNull String answer) {
FIntegration fIntegration = get("DiscordSRV");
if (fIntegration == null) return;
((FDiscordSRV) fIntegration).sendBallMessage(sender, message, answer);
}
}
168 changes: 168 additions & 0 deletions src/main/resources/settings/integrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,174 @@ DiscordSRV:
text: "🗐 There's a poll #<id> going on right now \n❓ <message>"
icon: true

footer:
enable: false
text: ""
icon:
enable: true
url: ""

me:
enable: false

channel-id: ""

content:
enable: false
text: ""

embed:
enable: true
color: "#42aaf5"

image:
enable: false
url: ""

title:
enable: false
text: ""
icon:
enable: true
url: ""

description:
enable: false
text: ""

author:
enable: true
text: "✎ <player> <message>"
icon: true

footer:
enable: false
text: ""
icon:
enable: true
url: ""

try:
enable: false

channel-id: ""

type:
true-message: "☺ <player> <message> <percent>%"
false-message: "☹ <player> <message> <percent>%"

content:
enable: false
text: ""

embed:
enable: true
color: "#42aaf5"

image:
enable: false
url: ""

title:
enable: false
text: ""
icon:
enable: true
url: ""

description:
enable: false
text: ""

author:
enable: true
text: "<type>"
icon: true

footer:
enable: false
text: ""
icon:
enable: true
url: ""

dice:
enable: false

channel-id: ""

type:
true-message: "☺ <player> successfully rolled <cube>"
false-message: "☹ <player> failed to roll <cube>"

content:
enable: false
text: ""

embed:
enable: true
color: "#42aaf5"

image:
enable: false
url: ""

title:
enable: false
text: ""
icon:
enable: true
url: ""

description:
enable: false
text: ""

author:
enable: true
text: "<type>"
icon: true

footer:
enable: false
text: ""
icon:
enable: true
url: ""

ball:
enable: false

channel-id: ""

content:
enable: false
text: ""

embed:
enable: true
color: "#bb63f2"

image:
enable: false
url: ""

title:
enable: false
text: ""
icon:
enable: true
url: ""

description:
enable: false
text: ""

author:
enable: true
text: "❓ <player> asked: <message> \n🔮 Ball answered: <answer>"
icon: true

footer:
enable: false
text: ""
Expand Down

0 comments on commit 796b1ca

Please sign in to comment.