Skip to content

Commit dbf0e6a

Browse files
authored
Merge pull request #132 from Matyrobbrt/script-tricks
3.9: Scripting
2 parents 0229610 + 73e4795 commit dbf0e6a

35 files changed

+1728
-40
lines changed

build.gradle

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ plugins {
1515
id 'pmd'
1616
id 'org.flywaydb.flyway' version "${flywaydb}"
1717
id 'org.cadixdev.licenser' version "${licenser}"
18+
id 'org.jetbrains.kotlin.jvm' version '1.6.10'
1819
}
1920

2021
mainClassName = 'com.mcmoddev.mmdbot.MMDBot'
@@ -76,6 +77,8 @@ dependencies {
7677
implementation supportDependencies.nightConfig
7778
implementation supportDependencies.sqliteJdbc
7879
implementation supportDependencies.flywayCore
80+
implementation supportDependencies.graal
81+
implementation supportDependencies.graalScriptEngine
7982
compileOnly supportDependencies.jetbrainsAnnotations
8083

8184
implementation group: 'org.jdbi', name: 'jdbi3-core', version: "${project.jdbi_version}"
@@ -248,3 +251,13 @@ pmd {
248251
toolVersion = '6.38.0'
249252
incrementalAnalysis = true
250253
}
254+
compileKotlin {
255+
kotlinOptions {
256+
jvmTarget = "1.8"
257+
}
258+
}
259+
compileTestKotlin {
260+
kotlinOptions {
261+
jvmTarget = "1.8"
262+
}
263+
}

dependencies.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ ext {
1616
sqliteJdbcVersion = "3.36.0.3"
1717
flywayCoreVersion = "8.4.1"
1818
jetbrainsAnnotationsVersion = "23.0.0"
19+
graalVersion = "22.0.0"
1920
//-- DEPENDENCIES
2021
supportDependencies = [
2122
jda : "net.dv8tion:JDA:$jdaVersion",
@@ -26,7 +27,9 @@ ext {
2627
nightConfig : "com.electronwill.night-config:toml:$tomlVersion",
2728
sqliteJdbc : "org.xerial:sqlite-jdbc:$sqliteJdbcVersion",
2829
flywayCore : "org.flywaydb:flyway-core:$flywayCoreVersion",
29-
jetbrainsAnnotations : "org.jetbrains:annotations:$jetbrainsAnnotationsVersion"
30+
jetbrainsAnnotations : "org.jetbrains:annotations:$jetbrainsAnnotationsVersion",
31+
graal : "org.graalvm.js:js:$graalVersion",
32+
graalScriptEngine : "org.graalvm.js:js-scriptengine:$graalVersion"
3033
]
3134
}
3235

src/main/java/com/mcmoddev/mmdbot/MMDBot.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import net.dv8tion.jda.api.JDABuilder;
3434
import net.dv8tion.jda.api.entities.Activity;
3535
import net.dv8tion.jda.api.requests.GatewayIntent;
36+
import net.dv8tion.jda.api.utils.AllowedMentions;
3637
import net.dv8tion.jda.api.utils.cache.CacheFlag;
3738
import org.jdbi.v3.core.Jdbi;
3839
import org.slf4j.Logger;
@@ -73,6 +74,10 @@ public final class MMDBot {
7374
GatewayIntent.GUILD_MESSAGES,
7475
GatewayIntent.GUILD_MEMBERS);
7576

77+
static {
78+
AllowedMentions.setDefaultMentionRepliedUser(false);
79+
}
80+
7681
/**
7782
* The config.
7883
*/

src/main/java/com/mcmoddev/mmdbot/core/BotConfig.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,13 @@ public boolean isEnabled(final String commandName) {
215215
return config.<Boolean>getOrElse(References.COMMANDS + commandName + ".enabled", true);
216216
}
217217

218+
/**
219+
* @return If tricks should be run using prefix commands
220+
*/
221+
public boolean prefixTricksEnabled() {
222+
return config.getOrElse("commands.prefix_tricks_enabled", false);
223+
}
224+
218225
/**
219226
* Returns whether the given command is enabled for the given guild.
220227
* <p>

src/main/java/com/mcmoddev/mmdbot/modules/commands/CommandModule.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.mcmoddev.mmdbot.modules.commands.bot.management.CmdRename;
3333
import com.mcmoddev.mmdbot.modules.commands.bot.management.CmdRestart;
3434
import com.mcmoddev.mmdbot.modules.commands.bot.management.CmdShutdown;
35+
import com.mcmoddev.mmdbot.modules.commands.community.CmdEvaluate;
3536
import com.mcmoddev.mmdbot.modules.commands.community.contextmenu.GuildOnlyMenu;
3637
import com.mcmoddev.mmdbot.modules.commands.community.contextmenu.message.ContextMenuAddQuote;
3738
import com.mcmoddev.mmdbot.modules.commands.community.contextmenu.message.ContextMenuGist;
@@ -54,6 +55,8 @@
5455
import com.mcmoddev.mmdbot.modules.commands.community.server.tricks.CmdAddTrick;
5556
import com.mcmoddev.mmdbot.modules.commands.community.server.tricks.CmdEditTrick;
5657
import com.mcmoddev.mmdbot.modules.commands.community.server.tricks.CmdListTricks;
58+
import com.mcmoddev.mmdbot.modules.commands.community.server.tricks.CmdRawTrick;
59+
import com.mcmoddev.mmdbot.modules.commands.community.server.tricks.CmdRunTrick;
5760
import com.mcmoddev.mmdbot.modules.commands.community.server.tricks.CmdTrick;
5861
import com.mcmoddev.mmdbot.modules.commands.moderation.CmdCommunityChannel;
5962
import com.mcmoddev.mmdbot.modules.commands.moderation.CmdMute;
@@ -64,6 +67,7 @@
6467
import com.mcmoddev.mmdbot.modules.commands.moderation.CmdWarning;
6568
import com.mcmoddev.mmdbot.utilities.ThreadedEventListener;
6669
import com.mcmoddev.mmdbot.utilities.Utils;
70+
import com.mcmoddev.mmdbot.utilities.tricks.Tricks;
6771
import net.dv8tion.jda.api.hooks.EventListener;
6872
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
6973

@@ -138,13 +142,16 @@ public static void setupCommandModule() {
138142
new CmdWarning(),
139143
new CmdTrick(),
140144
new CmdInvite(),
141-
new CmdDictionary());
145+
new CmdDictionary(),
146+
new CmdEvaluate(),
147+
new CmdRawTrick());
142148

143149
// addSlashCommand(Tricks.getTricks().stream().map(CmdRunTrickSeparated::new).toArray(SlashCommand[]::new));
144150

145151
commandClient.addCommand(new CmdRefreshScamLinks());
146152
commandClient.addCommand(new CmdReact());
147153
commandClient.addCommand(new CmdGist());
154+
commandClient.addCommand(new CmdEvaluate());
148155

149156
commandClient.addCommand(new CmdAddTrick.Prefix());
150157
commandClient.addCommand(new CmdEditTrick.Prefix());
@@ -153,6 +160,10 @@ public static void setupCommandModule() {
153160
addContextMenu(new ContextMenuAddQuote());
154161
addContextMenu(new ContextMenuUserInfo());
155162

163+
if (MMDBot.getConfig().prefixTricksEnabled()) {
164+
Tricks.getTricks().stream().map(CmdRunTrick.Prefix::new).forEach(commandClient::addCommand);
165+
}
166+
156167
if (MMDBot.getConfig().isCommandModuleEnabled()) {
157168
// Wrap the command and button listener in another thread, so that if a runtime exception
158169
// occurs while executing a command, the event thread will not be stopped

src/main/java/com/mcmoddev/mmdbot/modules/commands/DismissListener.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ public void onButtonInteraction(@javax.annotation.Nonnull final ButtonInteractio
5050

5151
if (buttonOwner == event.getUser().getIdLong() && !event.getMessage().isEphemeral()) {
5252
event.getMessage().delete().reason("User dismissed the message").queue();
53+
} else {
54+
event.deferReply(true).setContent("You cannot dismiss this message!").queue();
5355
}
5456

5557
}
5658

5759
public static Button createDismissButton(final long buttonOwner) {
58-
return Button.danger("dismiss-" + buttonOwner, " Dismiss");
60+
return Button.secondary("dismiss-" + buttonOwner, " Dismiss");
5961
}
6062

6163
public static Button createDismissButton(final Member buttonOwner) {

0 commit comments

Comments
 (0)