Skip to content

Commit c8acb56

Browse files
committed
Initial Rewrite
1 parent b63bb79 commit c8acb56

21 files changed

+1579
-5
lines changed

build.gradle

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ buildscript {
2020
}
2121
}
2222

23+
plugins {
24+
id 'org.gradlex.extra-java-module-info' version '1.12'
25+
}
26+
2327
apply plugin: 'com.github.johnrengelman.shadow'
2428
apply plugin: 'java'
2529
apply plugin: 'MangoBotGradle'
@@ -30,6 +34,10 @@ version = GitVersion.getGitVersion().getVersionAsString()
3034

3135
println("Version: " + version)
3236

37+
extraJavaModuleInfo {
38+
setDeriveAutomaticModuleNamesFromFileNames(true)
39+
}
40+
3341
java {
3442
toolchain {
3543
languageVersion = JavaLanguageVersion.of(24)
@@ -44,6 +52,7 @@ tasks.withType(JavaExec).configureEach {
4452

4553
repositories {
4654
mavenCentral()
55+
mavenLocal()
4756
maven {
4857
url = 'https://maven.minecraftforge.net/'
4958
}
@@ -63,11 +72,9 @@ dependencies {
6372
testImplementation 'org.junit.jupiter:junit-jupiter'
6473

6574
installer('org.mangorage:installer:4.0.3')
66-
bot('org.mangorage:mangobot:11.0.75')
75+
bot('org.mangorage:mangobot:12.0.0')
6776

6877
library('org.luaj:luaj-jse:3.0.1')
69-
library('dev.arbjerg:lavaplayer:2.2.2')
70-
library('dev.lavalink.youtube:common:1.11.3')
7178
}
7279

7380
configurations.all {

src/main/java/module-info.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module org.mangorage.mangobotplugin {
2+
requires org.mangorage.mangobotcore;
3+
requires net.dv8tion.jda;
4+
requires com.google.gson;
5+
requires luaj.jse;
6+
7+
requires net.minecraftforge.eventbus;
8+
9+
opens org.mangorage.mangobotplugin to org.mangorage.mangobotcore;
10+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.mangorage.mangobotplugin;
2+
3+
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
4+
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
5+
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
6+
import net.dv8tion.jda.api.hooks.SubscribeEvent;
7+
import org.mangorage.mangobotcore.jda.event.DiscordButtonInteractEvent;
8+
import org.mangorage.mangobotcore.jda.event.DiscordModalInteractionEvent;
9+
10+
public final class BotEventListener {
11+
private final MangoBot mangoBot;
12+
13+
public BotEventListener(MangoBot mangoBot) {
14+
this.mangoBot = mangoBot;
15+
}
16+
17+
18+
@SubscribeEvent
19+
public void onModalInteract(ModalInteractionEvent event) {
20+
DiscordModalInteractionEvent.BUS.post(new DiscordModalInteractionEvent(event));
21+
}
22+
23+
@SubscribeEvent
24+
public void onModalInteract(ButtonInteractionEvent event) {
25+
MangoBot.ACTION_REGISTRY.post(event);
26+
DiscordButtonInteractEvent.BUS.post(new DiscordButtonInteractEvent(event));
27+
}
28+
29+
@SubscribeEvent
30+
public void onMessageReceived(MessageReceivedEvent event) {
31+
mangoBot.getCommandManager().handle(event.getMessage());
32+
}
33+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package org.mangorage.mangobotplugin;
2+
3+
import net.dv8tion.jda.api.JDA;
4+
import net.dv8tion.jda.api.JDABuilder;
5+
import net.dv8tion.jda.api.OnlineStatus;
6+
import net.dv8tion.jda.api.entities.Activity;
7+
import net.dv8tion.jda.api.hooks.AnnotatedEventManager;
8+
import net.dv8tion.jda.api.requests.GatewayIntent;
9+
import net.dv8tion.jda.api.utils.MemberCachePolicy;
10+
import net.dv8tion.jda.api.utils.cache.CacheFlag;
11+
import org.mangorage.commonutils.config.Config;
12+
import org.mangorage.commonutils.config.ConfigSetting;
13+
import org.mangorage.commonutils.config.ISetting;
14+
import org.mangorage.commonutils.jda.ButtonActionRegistry;
15+
import org.mangorage.commonutils.jda.MessageSettings;
16+
import org.mangorage.mangobotcore.jda.command.api.CommandManager;
17+
import org.mangorage.mangobotcore.plugin.api.MangoBotPlugin;
18+
import org.mangorage.mangobotcore.plugin.api.Plugin;
19+
import org.mangorage.mangobotplugin.actions.TrashButtonAction;
20+
import org.mangorage.mangobotplugin.commands.PingCommand;
21+
import org.mangorage.mangobotplugin.commands.trick.TrickCommand;
22+
23+
import java.nio.file.Path;
24+
import java.util.EnumSet;
25+
26+
@MangoBotPlugin(id = MangoBot.ID)
27+
public final class MangoBot implements Plugin {
28+
public static final String ID = "mangobot";
29+
30+
public static final ButtonActionRegistry ACTION_REGISTRY = new ButtonActionRegistry();
31+
32+
33+
// Where we create our "config"
34+
public final static Config CONFIG = new Config(Path.of("plugins/%s/.env".formatted(MangoBot.ID)));
35+
36+
// Where we create Settings for said Config
37+
public static final ISetting<String> BOT_TOKEN = ConfigSetting.create(CONFIG, "BOT_TOKEN", "empty");
38+
39+
private static final EnumSet<GatewayIntent> intents = EnumSet.of(
40+
// Enables MessageReceivedEvent for guild (also known as servers)
41+
GatewayIntent.GUILD_MESSAGES,
42+
// Enables the event for private channels (also known as direct messages)
43+
GatewayIntent.DIRECT_MESSAGES,
44+
// Enables access to message.getContentRaw()
45+
GatewayIntent.MESSAGE_CONTENT,
46+
// Enables MessageReactionAddEvent for guild
47+
GatewayIntent.GUILD_MESSAGE_REACTIONS,
48+
// Enables MessageReactionAddEvent for private channels
49+
GatewayIntent.DIRECT_MESSAGE_REACTIONS,
50+
GatewayIntent.GUILD_VOICE_STATES,
51+
GatewayIntent.GUILD_EMOJIS_AND_STICKERS,
52+
GatewayIntent.SCHEDULED_EVENTS,
53+
GatewayIntent.GUILD_MEMBERS,
54+
GatewayIntent.GUILD_PRESENCES
55+
);
56+
57+
private static final EnumSet<CacheFlag> cacheFlags = EnumSet.of(
58+
CacheFlag.EMOJI,
59+
CacheFlag.ROLE_TAGS,
60+
CacheFlag.VOICE_STATE,
61+
CacheFlag.ACTIVITY,
62+
CacheFlag.CLIENT_STATUS,
63+
CacheFlag.MEMBER_OVERRIDES,
64+
CacheFlag.STICKER,
65+
CacheFlag.SCHEDULED_EVENTS,
66+
CacheFlag.FORUM_TAGS
67+
);
68+
69+
private final CommandManager commandManager = CommandManager.create();
70+
71+
private JDA jda;
72+
73+
public MangoBot() {
74+
ACTION_REGISTRY.register(new TrashButtonAction());
75+
76+
commandManager.register(new PingCommand());
77+
commandManager.register(new TrickCommand(this));
78+
}
79+
80+
@Override
81+
public String getId() {
82+
return ID;
83+
}
84+
85+
public void load() {
86+
jda = JDABuilder.createDefault(BOT_TOKEN.get())
87+
.setEnabledIntents(intents)
88+
.enableCache(cacheFlags)
89+
.setActivity(
90+
Activity.of(
91+
Activity.ActivityType.WATCHING,
92+
"https://mangobot.mangorage.org/"
93+
)
94+
)
95+
.setStatus(OnlineStatus.ONLINE)
96+
.setMemberCachePolicy(MemberCachePolicy.ALL)
97+
.setEventManager(new AnnotatedEventManager())
98+
.setEnableShutdownHook(true)
99+
.setAutoReconnect(true)
100+
.build();
101+
102+
getJDA().addEventListener(new BotEventListener(this));
103+
}
104+
105+
public JDA getJDA() {
106+
return jda;
107+
}
108+
109+
public CommandManager getCommandManager() {
110+
return commandManager;
111+
}
112+
113+
public Path getPluginDirectory() {
114+
return Path.of("plugins").resolve(ID).toAbsolutePath();
115+
}
116+
117+
public MessageSettings getMessageSettings() {
118+
return MessageSettings.create().build();
119+
}
120+
121+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2024. MangoRage
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
20+
* OR OTHER DEALINGS IN THE SOFTWARE.
21+
*/
22+
23+
package org.mangorage.mangobotplugin.actions;
24+
25+
import net.dv8tion.jda.api.entities.User;
26+
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
27+
import net.dv8tion.jda.api.interactions.components.buttons.Button;
28+
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
29+
import org.mangorage.commonutils.jda.ButtonAction;
30+
31+
public class TrashButtonAction extends ButtonAction {
32+
33+
public TrashButtonAction() {
34+
super("trash", "Delete");
35+
}
36+
37+
public Button createForUser(User user) {
38+
return create(ButtonStyle.DANGER, user.getId());
39+
}
40+
41+
@Override
42+
public boolean onClick(ButtonInteractionEvent event) {
43+
if (event.getComponent().getId() == null) return false;
44+
45+
if (event.getComponent().getId().startsWith(getId() + ":")) {
46+
var list = event.getComponent().getId().split(":");
47+
var clicked = event.getUser().getId();
48+
var msg = event.getMessage();
49+
50+
if (list[1].equals(clicked)) {
51+
msg.delete().queue();
52+
event.deferReply(true).setContent("Deleted Message!").queue();
53+
} else {
54+
event.deferReply(true).setContent("No permission to delete message!").queue();
55+
}
56+
}
57+
return false;
58+
}
59+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.mangorage.mangobotplugin.commands;
2+
3+
import net.dv8tion.jda.api.entities.Message;
4+
import org.mangorage.commonutils.misc.Arguments;
5+
import org.mangorage.mangobotcore.jda.command.api.CommandResult;
6+
import org.mangorage.mangobotcore.jda.command.api.ICommand;
7+
8+
import java.util.List;
9+
10+
public class PingCommand implements ICommand {
11+
@Override
12+
public List<String> commands() {
13+
return List.of("ping");
14+
}
15+
16+
@Override
17+
public String usage() {
18+
return "";
19+
}
20+
21+
@Override
22+
public CommandResult execute(Message message, Arguments arguments) {
23+
message.reply("Pong!").queue();;
24+
return CommandResult.PASS;
25+
}
26+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.mangorage.mangobotplugin.commands.trick;
2+
3+
4+
import org.mangorage.mangobotplugin.commands.trick.lua.MemoryBank;
5+
6+
import java.util.HashMap;
7+
8+
public final class EmptyTrick extends Trick {
9+
public static final EmptyTrick INSTANCE = new EmptyTrick();
10+
11+
private EmptyTrick() {
12+
super(null, 0);
13+
}
14+
15+
@Override
16+
public MemoryBank getMemoryBank() {
17+
return new MemoryBank(new HashMap<>());
18+
}
19+
}

0 commit comments

Comments
 (0)