Skip to content

Commit

Permalink
Upload source
Browse files Browse the repository at this point in the history
  • Loading branch information
MEFRREEX committed Dec 11, 2024
0 parents commit ff1c89b
Show file tree
Hide file tree
Showing 92 changed files with 3,807 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Compiled class file
*.class
.gradle
build/
bin/
target/
.idea/
.vscode/

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Luminia Discord Bot

This Discord bot written for Minecraft server Luminia

> [!IMPORTANT]
> This bot is written for the Luminia server Discord in Java + Kotlin and is currently no longer supported
## 🛠 Building the JAR File
To build the project from source:
1. Clone the repository:
```bash
git clone https://github.com/MEFRREEX/Luminia-Discord-Bot.git
```
2. Navigate to the project directory:
```bash
cd Luminia-Discord-Bot
```
3. Build the JAR file using Gradle:
```bash
gradle build
```
The compiled artifact will be located in the `bot/build/libs` directory
19 changes: 19 additions & 0 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
plugins {
kotlin("jvm") version "1.9.21"
}

kotlin {
jvmToolchain(21)
}

tasks.withType<Jar> {
archiveFileName.set("Luminia-Discord-Bot-API-${project.version}.jar")
}

sourceSets {
main {
java {
srcDirs("src/main/kotlin")
}
}
}
13 changes: 13 additions & 0 deletions api/src/main/kotlin/com/luminia/discord/api/command/Command.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.luminia.discord.api.command

import com.luminia.discord.api.command.data.CommandData
import net.dv8tion.jda.api.events.Event

abstract class Command<T : Event> {

abstract fun getCommandData(): CommandData

abstract fun getCommandType(): CommandType

abstract fun execute(event: T)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.luminia.discord.api.command;

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.events.interaction.command.GenericCommandInteractionEvent;

import java.util.Collections;
import java.util.Map;

public interface CommandManager {

JDA getJDA();

Map<CommandType, Map<String, Command<?>>> getCommands();

default Command<?> getCommand(CommandType type, String name) {
return this.getCommands().getOrDefault(type, Collections.emptyMap()).get(name);
}

void register(Command<?>... command);

void execute(Command<?> command, GenericCommandInteractionEvent event);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.luminia.discord.api.command;

public enum CommandType {
SLASH,
MESSAGE,
USER
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.luminia.discord.api.command

import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent

abstract class MessageCommand : Command<MessageContextInteractionEvent>() {

override fun getCommandType(): CommandType {
return CommandType.MESSAGE
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.luminia.discord.api.command

import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent

abstract class SlashCommand : Command<SlashCommandInteractionEvent>() {

override fun getCommandType(): CommandType {
return CommandType.SLASH
}
}
10 changes: 10 additions & 0 deletions api/src/main/kotlin/com/luminia/discord/api/command/UserCommand.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.luminia.discord.api.command

import net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent

abstract class UserCommand : Command<UserContextInteractionEvent>() {

override fun getCommandType(): CommandType {
return CommandType.USER
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.luminia.discord.api.command.data

import com.luminia.discord.api.command.permission.CommandPermission
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions
import net.dv8tion.jda.api.interactions.commands.build.Commands
import net.dv8tion.jda.api.interactions.commands.build.CommandData as JDACommandData

interface CommandData {

fun getJDACommandData(): JDACommandData

fun getPermission(): CommandPermission

fun setName(name: String): CommandData

fun setDefaultPermissions(permission: DefaultMemberPermissions): CommandData

fun setPermission(permission: CommandPermission): CommandData

fun setGuildOnly(guildOnly: Boolean): CommandData

fun setNSFW(nsfw: Boolean): CommandData

companion object {

fun slash(name: String, description: String): SlashCommandDataBuilder = SlashCommandDataBuilder(Commands.slash(name, description))

fun message(name: String): CommandDataBuilder = CommandDataBuilder(Commands.message(name))

fun context(name: String): CommandDataBuilder = CommandDataBuilder(Commands.user(name))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.luminia.discord.api.command.data

import com.luminia.discord.api.command.permission.CommandPermission
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions
import net.dv8tion.jda.api.interactions.commands.build.CommandData as JDACommandData

open class CommandDataBuilder(private val jdaCommandData: JDACommandData) : CommandData {

private var permission: CommandPermission = CommandPermission.DEFAULT

override fun getJDACommandData(): JDACommandData = jdaCommandData

override fun getPermission(): CommandPermission = permission

override fun setName(name: String): CommandDataBuilder {
jdaCommandData.setName(name)
return this
}

override fun setDefaultPermissions(permission: DefaultMemberPermissions): CommandDataBuilder {
jdaCommandData.setDefaultPermissions(permission)
return this
}

override fun setPermission(permission: CommandPermission): CommandDataBuilder {
this.permission = permission
return this
}

override fun setGuildOnly(guildOnly: Boolean): CommandDataBuilder {
jdaCommandData.setGuildOnly(guildOnly)
return this
}

override fun setNSFW(nsfw: Boolean): CommandDataBuilder {
jdaCommandData.setNSFW(nsfw)
return this
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.luminia.discord.api.command.data

import net.dv8tion.jda.api.interactions.commands.OptionType
import net.dv8tion.jda.api.interactions.commands.build.OptionData
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData
import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData

interface SlashCommandData : CommandData {

fun setDescription(description: String): SlashCommandData

fun addOptions(vararg options: OptionData): SlashCommandData

fun addOptions(options: Collection<OptionData>): SlashCommandData

fun addOption(type: OptionType, name: String, description: String, required: Boolean, autoComplete: Boolean): SlashCommandData

fun addOption(type: OptionType, name: String, description: String, required: Boolean): SlashCommandData

fun addOption(type: OptionType, name: String, description: String): SlashCommandData

fun addSubcommands(vararg subcommands: SubcommandData): SlashCommandData

fun addSubcommands(subcommands: Collection<SubcommandData>): SlashCommandData

fun addSubcommandGroups(vararg groups: SubcommandGroupData): SlashCommandData

fun addSubcommandGroups(groups: Collection<SubcommandGroupData>): SlashCommandData
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.luminia.discord.api.command.data

import net.dv8tion.jda.api.interactions.commands.OptionType
import net.dv8tion.jda.api.interactions.commands.build.OptionData
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData
import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData as JDASlashCommandData

class SlashCommandDataBuilder(private val jdaCommandData: JDASlashCommandData) : CommandDataBuilder(jdaCommandData), SlashCommandData {

override fun setDescription(description: String): SlashCommandDataBuilder {
jdaCommandData.setDescription(description)
return this
}

override fun addOptions(vararg options: OptionData): SlashCommandDataBuilder {
jdaCommandData.addOptions(*options)
return this
}

override fun addOptions(options: Collection<OptionData>): SlashCommandDataBuilder {
jdaCommandData.addOptions(options)
return this
}

override fun addOption(
type: OptionType,
name: String,
description: String,
required: Boolean,
autoComplete: Boolean
): SlashCommandDataBuilder {
jdaCommandData.addOption(type, name, description, required, autoComplete)
return this
}

override fun addOption(type: OptionType, name: String, description: String, required: Boolean): SlashCommandDataBuilder {
jdaCommandData.addOption(type, name, description, required)
return this
}

override fun addOption(type: OptionType, name: String, description: String): SlashCommandDataBuilder {
jdaCommandData.addOption(type, name, description)
return this
}

override fun addSubcommands(vararg subcommands: SubcommandData): SlashCommandDataBuilder {
jdaCommandData.addSubcommands(*subcommands)
return this
}

override fun addSubcommands(subcommands: Collection<SubcommandData>): SlashCommandDataBuilder {
jdaCommandData.addSubcommands(subcommands)
return this
}

override fun addSubcommandGroups(vararg groups: SubcommandGroupData): SlashCommandDataBuilder {
jdaCommandData.addSubcommandGroups(*groups)
return this
}

override fun addSubcommandGroups(groups: Collection<SubcommandGroupData>): SlashCommandDataBuilder {
jdaCommandData.addSubcommandGroups(groups)
return this
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.luminia.discord.api.command.permission

import net.dv8tion.jda.api.Permission
import net.dv8tion.jda.api.entities.Member
import net.dv8tion.jda.api.entities.Role

interface CommandPermission {

fun defaultValue(): Boolean {
return false
}

fun test(member: Member): Boolean

companion object {

fun role(roleId: Long): CommandPermission {
return object : CommandPermission {
override fun test(member: Member): Boolean {
return member.roles.stream().anyMatch { role: Role -> role.idLong == roleId }
}
}
}

fun permission(permission: Permission?): CommandPermission {
return object : CommandPermission {
override fun test(member: Member): Boolean {
return member.hasPermission(permission)
}
}
}

val DEFAULT: CommandPermission = object : CommandPermission {

override fun defaultValue(): Boolean {
return true;
}

override fun test(member: Member): Boolean {
return true
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.luminia.discord.api.handler;

import net.dv8tion.jda.api.events.GenericEvent;

import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;

public interface EventManager {

Map<Class<? extends GenericEvent>, Set<Consumer<GenericEvent>>> getHandlers();

void register(Object... listeners);

void handle(GenericEvent event);
}
Loading

0 comments on commit ff1c89b

Please sign in to comment.