Skip to content

Commit

Permalink
Base discord bot
Browse files Browse the repository at this point in the history
  • Loading branch information
vulcandragi committed Jun 14, 2024
1 parent 7756d97 commit bcb15b0
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 81 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
Expand Down
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@

plugins {
id 'com.gtnewhorizons.gtnhconvention'
id 'org.jetbrains.kotlin.jvm'
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
}
5 changes: 4 additions & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@
* For more details, see https://docs.gradle.org/8.0.1/userguide/java_library_plugin.html#sec:java_library_configurations_graph
*/
dependencies {
runtimeOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.5.4-GTNH:dev")
runtimeOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.5.4-GTNH:dev")
shadowImplementation "net.dv8tion:JDA:5.0.0-beta.20"
shadowImplementation "club.minnced:jda-ktx:0.11.0-beta.20"
shadowImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3"
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ forceEnableMixins = false

# If enabled, you may use 'shadowCompile' for dependencies. They will be integrated into your jar. It is your
# responsibility to check the license and request permission for distribution if required.
usesShadowedDependencies = false
usesShadowedDependencies = true

# If disabled, won't remove unused classes from shadowed dependencies. Some libraries use reflection to access
# their own classes, making the minimization unreliable.
Expand Down
2 changes: 1 addition & 1 deletion repositories.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Add any additional repositories for your dependencies here.

repositories {

mavenCentral()
}
4 changes: 4 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ pluginManagement {
mavenCentral()
mavenLocal()
}
plugins {
id 'org.jetbrains.kotlin.jvm' version '2.0.0'
}
}

plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.21'
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0'
}
42 changes: 21 additions & 21 deletions src/main/kotlin/com/fardragi/gregoriette/CommonProxy.kt
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
package com.fardragi.gregoriette;
package com.fardragi.gregoriette

import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import com.fardragi.gregoriette.Config.synchronizeConfiguration
import cpw.mods.fml.common.event.FMLInitializationEvent
import cpw.mods.fml.common.event.FMLPostInitializationEvent
import cpw.mods.fml.common.event.FMLPreInitializationEvent
import cpw.mods.fml.common.event.FMLServerStartingEvent

public class CommonProxy {
class CommonProxy {
// preInit "Run before anything else. Read your config, create blocks, items, etc, and register
// them with the
// GameRegistry." (Remove if not needed)
fun preInit(event: FMLPreInitializationEvent) {
synchronizeConfiguration(event.suggestedConfigurationFile)
}

// preInit "Run before anything else. Read your config, create blocks, items, etc, and register them with the
// GameRegistry." (Remove if not needed)
public void preInit(FMLPreInitializationEvent event) {
Config.synchronizeConfiguration(event.getSuggestedConfigurationFile());
// load "Do your mod setup. Build whatever data structures you care about. Register recipes."
// (Remove if not needed)
fun init(event: FMLInitializationEvent?) {}

Gregoriette.LOG.info(Config.greeting);
Gregoriette.LOG.info("I am MyMod at version " + Tags.VERSION);
}
// postInit "Handle interaction with other mods, complete your setup based on this." (Remove if
// not needed)
fun postInit(event: FMLPostInitializationEvent?) {}

// load "Do your mod setup. Build whatever data structures you care about. Register recipes." (Remove if not needed)
public void init(FMLInitializationEvent event) {}

// postInit "Handle interaction with other mods, complete your setup based on this." (Remove if not needed)
public void postInit(FMLPostInitializationEvent event) {}

// register server commands in this event handler (Remove if not needed)
public void serverStarting(FMLServerStartingEvent event) {}
// register server commands in this event handler (Remove if not needed)
fun serverStarting(event: FMLServerStartingEvent?) {}
}
27 changes: 14 additions & 13 deletions src/main/kotlin/com/fardragi/gregoriette/Config.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package com.fardragi.gregoriette;
package com.fardragi.gregoriette

import java.io.File;
import java.io.File
import net.minecraftforge.common.config.Configuration

import net.minecraftforge.common.config.Configuration;
object Config {
var botToken: String = ""

public class Config {
@JvmStatic
fun synchronizeConfiguration(configFile: File?) {
val configuration = Configuration(configFile)

public static String greeting = "Hello World";
botToken =
configuration.getString(
"bot_token", Configuration.CATEGORY_GENERAL, botToken, "Discord bot token")

public static void synchronizeConfiguration(File configFile) {
Configuration configuration = new Configuration(configFile);

greeting = configuration.getString("greeting", Configuration.CATEGORY_GENERAL, greeting, "How shall I greet?");

if (configuration.hasChanged()) {
configuration.save();
}
if (configuration.hasChanged()) {
configuration.save()
}
}
}
92 changes: 49 additions & 43 deletions src/main/kotlin/com/fardragi/gregoriette/Gregoriette.kt
Original file line number Diff line number Diff line change
@@ -1,51 +1,57 @@
package com.fardragi.gregoriette;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
package com.fardragi.gregoriette

import com.fardragi.gregoriette.discord.DiscordBot
import cpw.mods.fml.common.Mod
import cpw.mods.fml.common.SidedProxy
import cpw.mods.fml.common.event.FMLInitializationEvent
import cpw.mods.fml.common.event.FMLPostInitializationEvent
import cpw.mods.fml.common.event.FMLPreInitializationEvent
import cpw.mods.fml.common.event.FMLServerStartingEvent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger

@Mod(
modid = Gregoriette.MODID,
version = Tags.VERSION,
name = "Gregoriette",
acceptedMinecraftVersions = "[1.7.10]",
acceptableRemoteVersions = "*")
public class Gregoriette {

public static final String MODID = "gregoriette";
public static final Logger LOG = LogManager.getLogger(MODID);

@SidedProxy(serverSide = "com.fardragi.gregoriette.CommonProxy")
public static CommonProxy proxy;

@Mod.EventHandler
// preInit "Run before anything else. Read your config, create blocks, items, etc, and register them with the
// GameRegistry." (Remove if not needed)
public void preInit(FMLPreInitializationEvent event) {
proxy.preInit(event);
}

@Mod.EventHandler
// load "Do your mod setup. Build whatever data structures you care about. Register recipes." (Remove if not needed)
public void init(FMLInitializationEvent event) {
proxy.init(event);
}

@Mod.EventHandler
// postInit "Handle interaction with other mods, complete your setup based on this." (Remove if not needed)
public void postInit(FMLPostInitializationEvent event) {
proxy.postInit(event);
}

@Mod.EventHandler
// register server commands in this event handler (Remove if not needed)
public void serverStarting(FMLServerStartingEvent event) {
proxy.serverStarting(event);
}
class Gregoriette {
private var bot: DiscordBot? = null

@Mod.EventHandler // preInit "Run before anything else. Read your config, create blocks, items,
// etc, and register them with the
// GameRegistry." (Remove if not needed)
fun preInit(event: FMLPreInitializationEvent) {
proxy!!.preInit(event)
}

@Mod.EventHandler // load "Do your mod setup. Build whatever data structures you care about.
// Register recipes." (Remove if not needed)
fun init(event: FMLInitializationEvent?) {
proxy!!.init(event)

CoroutineScope(Dispatchers.IO).launch { bot = DiscordBot() }
}

@Mod.EventHandler // postInit "Handle interaction with other mods, complete your setup based on
// this." (Remove if not needed)
fun postInit(event: FMLPostInitializationEvent?) {
proxy!!.postInit(event)
}

@Mod.EventHandler // register server commands in this event handler (Remove if not needed)
fun serverStarting(event: FMLServerStartingEvent?) {
proxy!!.serverStarting(event)
}

companion object {
const val MODID: String = "gregoriette"
@JvmField val LOG: Logger = LogManager.getLogger(MODID)

@SidedProxy(serverSide = "com.fardragi.gregoriette.CommonProxy") var proxy: CommonProxy? = null
}
}
19 changes: 19 additions & 0 deletions src/main/kotlin/com/fardragi/gregoriette/discord/DiscordBot.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.fardragi.gregoriette.discord

import com.fardragi.gregoriette.Config
import com.fardragi.gregoriette.Gregoriette
import dev.minn.jda.ktx.events.onCommand
import dev.minn.jda.ktx.interactions.commands.restrict
import dev.minn.jda.ktx.interactions.commands.upsertCommand
import dev.minn.jda.ktx.jdabuilder.light

class DiscordBot {
private val client = light(Config.botToken, true)

init {
Gregoriette.LOG.info("Bot starting")

client.upsertCommand("test", "Test command") { restrict(true) }.queue()
client.onCommand("test") { event -> event.reply("${event.user.asMention} ola").queue() }
}
}

0 comments on commit bcb15b0

Please sign in to comment.