Compare commits
6 Commits
d78c4ec9fd
...
3473657fbb
Author | SHA1 | Date | |
---|---|---|---|
3473657fbb | |||
373a6b4279 | |||
942719d19c | |||
fd7fa1e078 | |||
5532dc1769 | |||
879ee55ac4 |
2
.env.example
Normal file
2
.env.example
Normal file
@ -0,0 +1,2 @@
|
||||
ENVIRONMENT=Production
|
||||
TOKEN=<YOUR BOT TOKEN>
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -3,3 +3,5 @@
|
||||
|
||||
# Ignore Gradle build output directory
|
||||
build
|
||||
.vscode
|
||||
.env
|
||||
|
@ -1,3 +1,3 @@
|
||||
# TomatenMusic3
|
||||
|
||||
A simple Discord Music Bot written in Java with Discord4J
|
||||
A simple Discord Music Bot written in Java with Javacord
|
@ -8,6 +8,7 @@
|
||||
plugins {
|
||||
// Apply the application plugin to add support for building a CLI application in Java.
|
||||
application
|
||||
id("com.gradleup.shadow") version "8.3.3"
|
||||
}
|
||||
|
||||
repositories {
|
||||
@ -23,6 +24,9 @@ dependencies {
|
||||
|
||||
// This dependency is used by the application.
|
||||
implementation(libs.guava)
|
||||
implementation(libs.javacord)
|
||||
implementation(libs.dotenv)
|
||||
implementation(libs.log4j)
|
||||
}
|
||||
|
||||
// Apply a specific Java toolchain to ease working on different environments.
|
||||
@ -37,6 +41,13 @@ application {
|
||||
mainClass = "net.tomatentum.tomatenmusic3.App"
|
||||
}
|
||||
|
||||
|
||||
tasks.withType<Jar> {
|
||||
manifest {
|
||||
attributes["Main-Class"] = application.mainClass
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named<Test>("test") {
|
||||
// Use JUnit Platform for unit tests.
|
||||
useJUnitPlatform()
|
||||
|
@ -1,10 +1,64 @@
|
||||
/*
|
||||
* This source file was generated by the Gradle 'init' task
|
||||
*/
|
||||
package net.tomatentum.tomatenmusic3;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.core.config.Configurator;
|
||||
import org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder;
|
||||
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
|
||||
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
|
||||
import org.apache.logging.log4j.core.config.builder.api.RootLoggerComponentBuilder;
|
||||
import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
|
||||
import org.javacord.api.DiscordApi;
|
||||
import org.javacord.api.DiscordApiBuilder;
|
||||
import org.javacord.api.entity.intent.Intent;
|
||||
|
||||
import io.github.cdimascio.dotenv.Dotenv;
|
||||
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new App().connect();
|
||||
}
|
||||
|
||||
private static String LOGGERPATTERN = "%-22d{dd MMM yyyy HH:mm:ss} (%t) [%c{3}] %p: %m%n";
|
||||
|
||||
private Config config;
|
||||
private DiscordApi client;
|
||||
private Logger logger;
|
||||
|
||||
private App() {
|
||||
Dotenv env = Dotenv.configure().ignoreIfMissing().load();
|
||||
this.config = new Config(env);
|
||||
initLogger();
|
||||
}
|
||||
|
||||
private void initLogger() {
|
||||
ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();
|
||||
AppenderComponentBuilder cbuilder =
|
||||
builder.newAppender("Console", "Console")
|
||||
.add(builder
|
||||
.newLayout("PatternLayout")
|
||||
.addAttribute("pattern", LOGGERPATTERN)
|
||||
);
|
||||
RootLoggerComponentBuilder rlbuilder =
|
||||
builder.newRootLogger(config.isDevelopment() ? Level.DEBUG : Level.INFO)
|
||||
.add(builder.newAppenderRef("Console"));
|
||||
|
||||
BuiltConfiguration logconf = builder.add(cbuilder).add(rlbuilder).build();
|
||||
|
||||
Configurator.reconfigure(logconf);
|
||||
logger = LogManager.getLogger(this);
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
client = new DiscordApiBuilder()
|
||||
.setToken(config.token())
|
||||
.addIntents(Intent.GUILD_VOICE_STATES)
|
||||
.login().join();
|
||||
logger.log(Level.INFO, "connected as {}", client.getYourself().getName());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
20
app/src/main/java/net/tomatentum/tomatenmusic3/Config.java
Normal file
20
app/src/main/java/net/tomatentum/tomatenmusic3/Config.java
Normal file
@ -0,0 +1,20 @@
|
||||
package net.tomatentum.tomatenmusic3;
|
||||
|
||||
import io.github.cdimascio.dotenv.Dotenv;
|
||||
|
||||
public class Config {
|
||||
|
||||
private Dotenv env;
|
||||
|
||||
public Config(Dotenv env) {
|
||||
this.env = env;
|
||||
}
|
||||
|
||||
public String token() {
|
||||
return env.get("TOKEN");
|
||||
}
|
||||
|
||||
public boolean isDevelopment() {
|
||||
return env.get("ENVIRONMENT").equals("Development");
|
||||
}
|
||||
}
|
@ -4,7 +4,15 @@
|
||||
[versions]
|
||||
guava = "33.0.0-jre"
|
||||
junit-jupiter = "5.10.2"
|
||||
javacord = "3.8.0"
|
||||
dotenv = "3.0.0"
|
||||
log4j = "2.24.1"
|
||||
|
||||
[libraries]
|
||||
guava = { module = "com.google.guava:guava", version.ref = "guava" }
|
||||
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" }
|
||||
javacord = { module = "org.javacord:javacord", version.ref = "javacord" }
|
||||
dotenv = { module = "io.github.cdimascio:dotenv-java", version.ref = "dotenv"}
|
||||
log4j = { module = "org.apache.logging.log4j:log4j-core", version.ref = "log4j"}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user