Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4d35dec
Scripting start
Matyrobbrt Feb 3, 2022
5ba9eaa
Some more stuff
Matyrobbrt Feb 4, 2022
d44530c
More scripting
Matyrobbrt Feb 4, 2022
22d236a
More scripting
Matyrobbrt Feb 4, 2022
7df3a59
Some Math Helpers
Matyrobbrt Feb 4, 2022
39769ec
Some more channel-related functions to the context
Matyrobbrt Feb 4, 2022
5d7ffeb
Fixed a mistake in the guild context
Matyrobbrt Feb 4, 2022
296a5bb
Fix scripting output
Matyrobbrt Feb 4, 2022
4085679
Update ScriptingUtils.java
Matyrobbrt Feb 4, 2022
f8c4a8e
Add emotes to scripting
Matyrobbrt Feb 4, 2022
e2cd30f
Add region support to scripts
Matyrobbrt Feb 4, 2022
cd94691
Forgot about ID on guilds
Matyrobbrt Feb 4, 2022
dca18c8
Add a helper for mentionable entities in scripts
Matyrobbrt Feb 4, 2022
8256e03
More stuff and finally fix instantiation
Matyrobbrt Feb 4, 2022
7041ca8
Added a format util function
Matyrobbrt Feb 4, 2022
797a6a0
Make all of the created `Context`s use the same shared `Engine`
Matyrobbrt Feb 4, 2022
ae91638
Allow map acces
Matyrobbrt Feb 5, 2022
b5384a7
Fix dependency
Matyrobbrt Feb 5, 2022
1376973
Add a config for prefixed tricks to be enabled
Matyrobbrt Feb 5, 2022
80fb15b
Expose some getters to scripting
Matyrobbrt Feb 5, 2022
a689677
More stuff
Matyrobbrt Feb 5, 2022
3790236
Stuff
Matyrobbrt Feb 6, 2022
bea34b5
Fix
Matyrobbrt Feb 6, 2022
76e7013
Add timeout for evaluation commands
Matyrobbrt Feb 6, 2022
d445699
Fixes the quotes being parsed in the context
Matyrobbrt Feb 6, 2022
73e4795
A fix
Matyrobbrt Feb 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ plugins {
id 'pmd'
id 'org.flywaydb.flyway' version "${flywaydb}"
id 'org.cadixdev.licenser' version "${licenser}"
id 'org.jetbrains.kotlin.jvm' version '1.6.10'
}

mainClassName = 'com.mcmoddev.mmdbot.MMDBot'
Expand Down Expand Up @@ -76,6 +77,8 @@ dependencies {
implementation supportDependencies.nightConfig
implementation supportDependencies.sqliteJdbc
implementation supportDependencies.flywayCore
implementation supportDependencies.graal
implementation supportDependencies.graalScriptEngine
compileOnly supportDependencies.jetbrainsAnnotations

implementation group: 'org.jdbi', name: 'jdbi3-core', version: "${project.jdbi_version}"
Expand Down Expand Up @@ -248,3 +251,13 @@ pmd {
toolVersion = '6.38.0'
incrementalAnalysis = true
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
5 changes: 4 additions & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ext {
sqliteJdbcVersion = "3.36.0.3"
flywayCoreVersion = "8.4.1"
jetbrainsAnnotationsVersion = "23.0.0"
graalVersion = "22.0.0"
//-- DEPENDENCIES
supportDependencies = [
jda : "net.dv8tion:JDA:$jdaVersion",
Expand All @@ -26,7 +27,9 @@ ext {
nightConfig : "com.electronwill.night-config:toml:$tomlVersion",
sqliteJdbc : "org.xerial:sqlite-jdbc:$sqliteJdbcVersion",
flywayCore : "org.flywaydb:flyway-core:$flywayCoreVersion",
jetbrainsAnnotations : "org.jetbrains:annotations:$jetbrainsAnnotationsVersion"
jetbrainsAnnotations : "org.jetbrains:annotations:$jetbrainsAnnotationsVersion",
graal : "org.graalvm.js:js:$graalVersion",
graalScriptEngine : "org.graalvm.js:js-scriptengine:$graalVersion"
]
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/mcmoddev/mmdbot/MMDBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.utils.AllowedMentions;
import net.dv8tion.jda.api.utils.cache.CacheFlag;
import org.jdbi.v3.core.Jdbi;
import org.slf4j.Logger;
Expand Down Expand Up @@ -73,6 +74,10 @@ public final class MMDBot {
GatewayIntent.GUILD_MESSAGES,
GatewayIntent.GUILD_MEMBERS);

static {
AllowedMentions.setDefaultMentionRepliedUser(false);
}

/**
* The config.
*/
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/mcmoddev/mmdbot/core/BotConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ public boolean isEnabled(final String commandName) {
return config.<Boolean>getOrElse(References.COMMANDS + commandName + ".enabled", true);
}

/**
* @return If tricks should be run using prefix commands
*/
public boolean prefixTricksEnabled() {
return config.getOrElse("commands.prefix_tricks_enabled", false);
}

/**
* Returns whether the given command is enabled for the given guild.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.mcmoddev.mmdbot.modules.commands.bot.management.CmdRename;
import com.mcmoddev.mmdbot.modules.commands.bot.management.CmdRestart;
import com.mcmoddev.mmdbot.modules.commands.bot.management.CmdShutdown;
import com.mcmoddev.mmdbot.modules.commands.community.CmdEvaluate;
import com.mcmoddev.mmdbot.modules.commands.community.contextmenu.GuildOnlyMenu;
import com.mcmoddev.mmdbot.modules.commands.community.contextmenu.message.ContextMenuAddQuote;
import com.mcmoddev.mmdbot.modules.commands.community.contextmenu.message.ContextMenuGist;
Expand All @@ -54,6 +55,8 @@
import com.mcmoddev.mmdbot.modules.commands.community.server.tricks.CmdAddTrick;
import com.mcmoddev.mmdbot.modules.commands.community.server.tricks.CmdEditTrick;
import com.mcmoddev.mmdbot.modules.commands.community.server.tricks.CmdListTricks;
import com.mcmoddev.mmdbot.modules.commands.community.server.tricks.CmdRawTrick;
import com.mcmoddev.mmdbot.modules.commands.community.server.tricks.CmdRunTrick;
import com.mcmoddev.mmdbot.modules.commands.community.server.tricks.CmdTrick;
import com.mcmoddev.mmdbot.modules.commands.moderation.CmdCommunityChannel;
import com.mcmoddev.mmdbot.modules.commands.moderation.CmdMute;
Expand All @@ -64,6 +67,7 @@
import com.mcmoddev.mmdbot.modules.commands.moderation.CmdWarning;
import com.mcmoddev.mmdbot.utilities.ThreadedEventListener;
import com.mcmoddev.mmdbot.utilities.Utils;
import com.mcmoddev.mmdbot.utilities.tricks.Tricks;
import net.dv8tion.jda.api.hooks.EventListener;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;

Expand Down Expand Up @@ -138,13 +142,16 @@ public static void setupCommandModule() {
new CmdWarning(),
new CmdTrick(),
new CmdInvite(),
new CmdDictionary());
new CmdDictionary(),
new CmdEvaluate(),
new CmdRawTrick());

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

commandClient.addCommand(new CmdRefreshScamLinks());
commandClient.addCommand(new CmdReact());
commandClient.addCommand(new CmdGist());
commandClient.addCommand(new CmdEvaluate());

commandClient.addCommand(new CmdAddTrick.Prefix());
commandClient.addCommand(new CmdEditTrick.Prefix());
Expand All @@ -153,6 +160,10 @@ public static void setupCommandModule() {
addContextMenu(new ContextMenuAddQuote());
addContextMenu(new ContextMenuUserInfo());

if (MMDBot.getConfig().prefixTricksEnabled()) {
Tricks.getTricks().stream().map(CmdRunTrick.Prefix::new).forEach(commandClient::addCommand);
}

if (MMDBot.getConfig().isCommandModuleEnabled()) {
// Wrap the command and button listener in another thread, so that if a runtime exception
// occurs while executing a command, the event thread will not be stopped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ public void onButtonInteraction(@javax.annotation.Nonnull final ButtonInteractio

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

}

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

public static Button createDismissButton(final Member buttonOwner) {
Expand Down
Loading