Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
hs_err_pid*

# custom
.idea/
.idea/*
!.idea/icon.svg
src/test/
*.iml
target/
Expand Down
4 changes: 4 additions & 0 deletions .idea/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
163 changes: 59 additions & 104 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,66 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>RoboFlask</artifactId>
<version>1.0</version>
<name>RoboFlask</name>
<groupId>com.devflask</groupId>
<artifactId>roboflask</artifactId>
<version>3.4.2</version>
<packaging>jar</packaging>
<url>https://dehys.com/${project.name}</url>
<description>
RoboFlask is a discord bot made by the devflask community. It's a bot designed to do everything with the help of the existing features and future implementations from anyone. Want to contribute? Read CONTRIBUTE.md
</description>

<properties>
<kotlin.version>1.4.31</kotlin.version>
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
<java.version>17</java.version>
<mainClass>com.devflask.roboflask.Robo</mainClass>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${mainClass}</mainClass>
</transformer>
</transformers>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>com.jcraft</groupId>
Expand Down Expand Up @@ -42,19 +92,14 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.0</version>
<version>2.17.0</version>
</dependency>

<dependency>
<groupId>com.moandjiezana.toml</groupId>
<artifactId>toml4j</artifactId>
<version>0.7.2</version>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.9</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>

<repositories>
Expand All @@ -68,96 +113,6 @@
<name>maven-central</name>
<url>https://repo1.maven.org/maven2/</url>
</repository>

</repositories>

<build>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<goals> <goal>test-compile</goal> </goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/test/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
<executions>
<!-- Replacing default-compile as it is treated specially by maven -->
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<!-- Replacing default-testCompile as it is treated specially by maven -->
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.devflask.roboflask.Robo</mainClass>
</transformer>
</transformers>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
92 changes: 51 additions & 41 deletions src/main/java/com/devflask/roboflask/Bot.java
Original file line number Diff line number Diff line change
@@ -1,45 +1,62 @@
package com.devflask.roboflask;

import com.devflask.roboflask.command.CommandManager;
import com.devflask.roboflask.command.moderation.Ban;
import com.devflask.roboflask.command.moderation.Get;
import com.devflask.roboflask.command.moderation.Kick;
import com.devflask.roboflask.command.moderation.Unban;
import com.devflask.roboflask.command.util.Help;
import com.devflask.roboflask.command.util.Info;
import com.devflask.roboflask.command.Command;
import com.devflask.roboflask.command.CommandManager;
import com.devflask.roboflask.command.util.Ping;
import com.devflask.roboflask.command.moderation.Kick;
import com.devflask.roboflask.configuration.ConfigManager;
import com.devflask.roboflask.database.Database;
import com.devflask.roboflask.interfaces.Command;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.requests.GatewayIntent;

import javax.security.auth.login.LoginException;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class Bot {

public static Map<Bot, Integer> botMap = new HashMap<>();
public int id;

private static final CommandManager commandManager = new CommandManager();;
private ConfigManager configManager;
private static final CommandManager commandManager = new CommandManager();

private final String token;
private Database database;
private JDA jda;

public Bot(String token) throws LoginException, InterruptedException {
this.id = generateId();
botMap.put(this, this.id);
public Bot(String token) {
this.token = token;
setup();
}

public Bot(String token, Database database) {
this.token = token;
initJDA();
initializeCommands();
this.database = database.connect();
setup();
}

private void setup() {
this.id = Robo.generateId();
Robo.bots.add(this);

try {
initJDA();
initCommands();
} catch (LoginException | InterruptedException e) {
e.printStackTrace();
}
}

private void initJDA() throws LoginException, InterruptedException {
jda = setupJDA().build();
jda.awaitReady();
}

public void initializeCommands(){
public void initCommands() {
registerCommands(
new Help(),
new Ping(),
Expand All @@ -50,24 +67,15 @@ public void initializeCommands(){
new Get()
);
}

private void initJDA() throws LoginException, InterruptedException {
JDA bot = setupJDA().build();
bot.awaitReady();
}

private JDABuilder setupJDA(){
JDABuilder builder = JDABuilder.create(this.token == null ? System.getenv("RoboflaskToken") : this.token, getIntents());
private JDABuilder setupJDA() {
JDABuilder builder = JDABuilder.create(this.token == null ? System.getenv("RoboFlaskToken") : this.token, getIntents());
builder.setActivity(Activity.watching("running on cd"));
builder.addEventListeners(commandManager);
return builder;
}

private void setupDatabase(){

}

private EnumSet<GatewayIntent> getIntents(){
private EnumSet<GatewayIntent> getIntents() {
return EnumSet.of(
GatewayIntent.GUILD_MEMBERS,
GatewayIntent.GUILD_MESSAGES,
Expand All @@ -79,27 +87,29 @@ private EnumSet<GatewayIntent> getIntents(){
);
}

private void registerCommands(Command ... commands){
private void registerCommands(Command... commands) {
for (Command cmd : commands) commandManager.addCommand(cmd);
}

public static CommandManager getCommandManager(){
public static CommandManager getCommandManager() {
return commandManager;
}

private int generateId(){
//generate
int i = new Random().nextInt(10000000, 99999999);

//check availability
for (Bot bot : botMap.keySet()){
while (bot.id == i){
i = new Random().nextInt(10000000, 99999999);
}
}
//getters
public Database getDatabase() {
return this.database;
}

return i;
public JDA getJDA() {
return this.jda;
}

public int getId() {
return this.id;
}

//setters
public void setDatabase(Database database) {
this.database = database;
}
}
Loading