-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6abf50e
commit 147d488
Showing
15 changed files
with
274 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
src/main/java/org/mangorage/mangobot/modules/tricks/lua/ILuaAction.java
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
src/main/java/org/mangorage/mangobot/modules/tricks/lua/LuaActions.java
This file was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
src/main/java/org/mangorage/mangobot/modules/tricks/lua/LuaJDA.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.mangorage.mangobot.modules.tricks.lua; | ||
|
||
import net.dv8tion.jda.api.entities.Message; | ||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; | ||
import org.mangorage.mangobot.modules.tricks.Trick; | ||
import org.mangorage.mangobot.modules.tricks.TrickCommand; | ||
import org.mangorage.mangobot.modules.tricks.lua.builders.LuaEmbedBuilder; | ||
import org.mangorage.mangobot.modules.tricks.lua.builders.LuaMessageResponseBuilder; | ||
import org.mangorage.mangobot.modules.tricks.lua.helpers.LuaInfoHelper; | ||
import org.mangorage.mangobot.modules.tricks.lua.helpers.LuaObjectHelper; | ||
import org.mangorage.mangobotapi.core.plugin.api.CorePlugin; | ||
|
||
|
||
public final class LuaJDA { | ||
private final CorePlugin corePlugin; | ||
private final Message message; | ||
private final MessageChannel messageChannel; | ||
private final Trick trick; | ||
|
||
|
||
public LuaJDA(CorePlugin plugin, Trick trick, Message message, MessageChannel channel) { | ||
this.corePlugin = plugin; | ||
this.message = message; | ||
this.messageChannel = channel; | ||
this.trick = trick; | ||
} | ||
|
||
public Object getStored(String key) { | ||
return trick.getMemoryBank().bank().get(key); | ||
} | ||
|
||
public Object getStoredOrSetAndGet(String key, Object value) { | ||
var result = getStored(key); | ||
if (result == null) { | ||
storeValue(key, value); | ||
return value; | ||
} | ||
return result; | ||
} | ||
|
||
public void storeValue(String key, Object o) { | ||
trick.getMemoryBank().bank().put(key, o); | ||
TrickCommand.TRICK_DATA_HANDLER.save(corePlugin.getPluginDirectory(), trick); | ||
} | ||
|
||
public LuaEmbedBuilder createEmbed() { | ||
return new LuaEmbedBuilder(); | ||
} | ||
|
||
public LuaMessageResponseBuilder respond() { | ||
return new LuaMessageResponseBuilder(message.reply("")); | ||
} | ||
|
||
public LuaInfoHelper getInfoHelper() { | ||
return new LuaInfoHelper(message, messageChannel); | ||
} | ||
|
||
public LuaObjectHelper getObjectHelper() { | ||
return new LuaObjectHelper(); | ||
} | ||
} |
17 changes: 0 additions & 17 deletions
17
src/main/java/org/mangorage/mangobot/modules/tricks/lua/LuaPrimitiveStringArray.java
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
src/main/java/org/mangorage/mangobot/modules/tricks/lua/MemoryBank.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.mangorage.mangobot.modules.tricks.lua; | ||
|
||
import java.util.Map; | ||
|
||
public record MemoryBank(Map<String, Object> bank) { } |
28 changes: 0 additions & 28 deletions
28
src/main/java/org/mangorage/mangobot/modules/tricks/lua/MessageAction.java
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
src/main/java/org/mangorage/mangobot/modules/tricks/lua/builders/LuaEmbedBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.mangorage.mangobot.modules.tricks.lua.builders; | ||
|
||
import net.dv8tion.jda.api.EmbedBuilder; | ||
import net.dv8tion.jda.api.entities.MessageEmbed; | ||
|
||
public class LuaEmbedBuilder { | ||
private final EmbedBuilder builder = new EmbedBuilder(); | ||
|
||
public LuaEmbedBuilder setTitle(String title) { | ||
builder.setTitle(title); | ||
return this; | ||
} | ||
|
||
public LuaEmbedBuilder setTitle(String title, String url) { | ||
builder.setTitle(title, url); | ||
return this; | ||
} | ||
|
||
public LuaEmbedBuilder setDescription(String description) { | ||
builder.setDescription(description); | ||
return this; | ||
} | ||
|
||
public EmbedBuilder getBuilder() { | ||
return builder; | ||
} | ||
|
||
public MessageEmbed build() { | ||
return builder.build(); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...in/java/org/mangorage/mangobot/modules/tricks/lua/builders/LuaMessageResponseBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.mangorage.mangobot.modules.tricks.lua.builders; | ||
|
||
import net.dv8tion.jda.api.entities.Message; | ||
import net.dv8tion.jda.api.entities.MessageEmbed; | ||
import net.dv8tion.jda.api.requests.restaction.MessageCreateAction; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class LuaMessageResponseBuilder { | ||
private final MessageCreateAction message; | ||
public LuaMessageResponseBuilder(MessageCreateAction message) { | ||
this.message = message; | ||
} | ||
|
||
public LuaMessageResponseBuilder reply(String content) { | ||
message.setContent(content); | ||
return this; | ||
} | ||
|
||
public LuaMessageResponseBuilder setMentions(String name) { | ||
String[] names = name.split(":"); | ||
if (names.length == 0 || names[0].isEmpty()) { | ||
message.setAllowedMentions(List.of()); | ||
} else { | ||
message.setAllowedMentions( | ||
Arrays.stream(names) | ||
.map(Message.MentionType::valueOf) | ||
.filter(t -> { | ||
if (t == Message.MentionType.EVERYONE) return false; | ||
if (t == Message.MentionType.HERE) return false; | ||
return true; | ||
}) | ||
.toList() | ||
); | ||
} | ||
return this; | ||
} | ||
|
||
public LuaMessageResponseBuilder setSuppressedNotifications(boolean value) { | ||
message.setSuppressedNotifications(value); | ||
return this; | ||
} | ||
|
||
public LuaMessageResponseBuilder setMentionsUser(boolean mentionsUser) { | ||
message.mentionRepliedUser(mentionsUser); | ||
return this; | ||
} | ||
|
||
public LuaMessageResponseBuilder setMention(String user) { | ||
String[] users = user.split(":"); | ||
message.mentionUsers(users); | ||
return this; | ||
} | ||
|
||
public LuaMessageResponseBuilder setEmbed(MessageEmbed embed) { | ||
message.setEmbeds(embed); | ||
return this; | ||
} | ||
|
||
public void queue() { | ||
message.setAllowedMentions( | ||
message.getAllowedMentions() | ||
.stream() | ||
.filter(t -> { | ||
if (t == Message.MentionType.EVERYONE) return false; | ||
if (t == Message.MentionType.HERE) return false; | ||
return true; | ||
}) | ||
.toList() | ||
).queue(); | ||
} | ||
} |
Oops, something went wrong.