Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e2c08bf
Adding settings tot the database
RealYusufIsmail Jun 7, 2022
3ec2f2b
Add try and finally to Main Bot class
RealYusufIsmail Jun 7, 2022
e8f23db
Will implement jooq tomorrow
RealYusufIsmail Jun 7, 2022
99b6cab
Will test some setting tomorrow
RealYusufIsmail Jun 8, 2022
7dd3979
Update build.gradle
RealYusufIsmail Jun 9, 2022
a1bc53a
Reworking the database
RealYusufIsmail Jun 11, 2022
b7bc478
Merge branch 'main' into system/database
RealYusufIsmail Jun 11, 2022
a31f9f8
more changes.
RealYusufIsmail Jun 11, 2022
155abde
Fixed an issue with the handlers. Command works now
RealYusufIsmail Jun 12, 2022
46a1dcf
still having some issues
RealYusufIsmail Jun 12, 2022
0b2753d
I think i can use .env in gradle now
RealYusufIsmail Jun 12, 2022
71b892c
Jooq works
RealYusufIsmail Jun 12, 2022
524ffa4
removed the need for auth
RealYusufIsmail Jun 12, 2022
286a2e1
bug fixing. only generates required stuff
RealYusufIsmail Jun 12, 2022
b5e32fd
will deal with .env issue later
RealYusufIsmail Jun 12, 2022
feb7c0a
see if this works
RealYusufIsmail Jun 12, 2022
3fa80d7
Updated action
RealYusufIsmail Jun 13, 2022
6ce5894
Update README.md
RealYusufIsmail Jun 14, 2022
a2d137f
some bug fixing and figure the jooq part
RealYusufIsmail Jun 14, 2022
8248aff
trying this
RealYusufIsmail Jun 14, 2022
fa21ee3
hmm
RealYusufIsmail Jun 14, 2022
c932652
Update build.gradle
RealYusufIsmail Jun 14, 2022
515862d
work
RealYusufIsmail Jun 14, 2022
d50af8e
added jooq
RealYusufIsmail Jun 16, 2022
3dd073c
Updated some comments
RealYusufIsmail Jun 16, 2022
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ bin/
.DS_Store
codecov
*.log
gradle.properties
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Once you have added the bot to your server, you will need to create a .env file
TOKEN=
GUILD_ID=
OWNER_ID=
//for the excutor default is 1;
//for the excutor default is 1.
CORE_POOL_SIZE=
```

Expand Down
61 changes: 56 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import nu.studer.gradle.jooq.JooqEdition

buildscript {
dependencies {
classpath 'org.postgresql:postgresql:42.4.0'
}
}

plugins {
id 'java'
id "com.diffplug.spotless" version "6.6.1"
id "application"
id "nu.studer.jooq" version "6.0.1"
}


group 'io.github.org.programming'
version '1.0-SNAPSHOT'

Expand All @@ -24,16 +32,21 @@ dependencies {
implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.2.11'
//config
implementation group: 'io.github.yusufsdiscordbot', name: 'config', version: '1.0.4'
//Reflection
implementation group: 'org.reflections', name: 'reflections', version: '0.10.2'
//json
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.13.3'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.13.3'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.13.3'
//MongoDB
implementation group: 'org.mongodb', name: 'mongo-java-driver', version: '3.12.11'
//database
implementation group: 'com.zaxxer', name: 'HikariCP', version: '5.0.0'
implementation group: 'org.postgresql', name: 'postgresql', version: '42.4.0'
//jooq
implementation group: 'org.jooq', name: 'jooq', version: '3.15.5'
implementation group: 'org.jooq', name: 'jooq-codegen', version: '3.16.6'
implementation group: 'org.jooq', name: 'jooq-meta', version: '3.16.6'
//test
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2'
//jooq
jooqGenerator "org.postgresql:postgresql:42.4.0"
}

apply plugin: 'jacoco' // code coverage reports
Expand Down Expand Up @@ -131,4 +144,42 @@ task downloadDependencies {
}
}

//def props = new Properties()
//file(".env").withInputStream { props.load(it) }

jooq {
version = '3.15.2'
edition = JooqEdition.OSS
configurations {
main {
generateSchemaSourceOnCompilation = false
generationTool {
logging = org.jooq.meta.jaxb.Logging.WARN
jdbc {
driver = 'org.postgresql.Driver'
url = "jdbc:postgresql://localhost:5432/postgres"
}
generator {
name = 'org.jooq.codegen.JavaGenerator'
database {
name = 'org.jooq.meta.postgres.PostgresDatabase'
includes = '.*'
excludes = ''
}
generate {
records = true
immutablePojos = true
fluentSetters = true
}
target {
packageName = 'io.github.org.programming.db.generated'
directory = "build/generated/java"
}
strategy.name = "org.jooq.codegen.DefaultGeneratorStrategy"
}
}
}
}
}

check.dependsOn jacocoTestReport
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@

import javax.annotation.Nonnull;

public abstract class MessageCommandExtender extends MessageCommand {

public MessageCommandExtender(CommandData commandData) {
super(commandData);
}
public abstract class MessageCommandExtender {

public abstract void onMessageContextInteraction(@Nonnull MessageContextInteractionEvent event);

Expand All @@ -35,5 +31,5 @@ public void onSelectMenu(@Nonnull SelectMenuInteractionEvent event) {

}

protected abstract SlashCommand build();
public abstract MessageCommand build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@

import javax.annotation.Nonnull;

public abstract class SlashCommandExtender extends SlashCommand {

protected SlashCommandExtender(SlashCommandData commandData) {
super(commandData);
}
public abstract class SlashCommandExtender {

// This method is called when the command is executed.
public abstract void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event);
Expand All @@ -36,5 +32,5 @@ public void onSelectMenu(@Nonnull SelectMenuInteractionEvent event) {

}

protected abstract SlashCommand build();
public abstract SlashCommand build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@

import javax.annotation.Nonnull;

public abstract class UserCommandExtender extends UserCommand {
public UserCommandExtender(CommandData commandData) {
super(commandData);
}
public abstract class UserCommandExtender {

public abstract void onUserContextInteraction(@NotNull UserContextInteractionEvent event);

Expand All @@ -34,5 +31,5 @@ public void onSelectMenu(@Nonnull SelectMenuInteractionEvent event) {

}

protected abstract UserCommand build();
public abstract UserCommand build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import net.dv8tion.jda.api.hooks.ListenerAdapter;

import java.util.Objects;

public abstract class BaseHandler extends ListenerAdapter {
/**
*
Expand All @@ -10,4 +12,9 @@ public abstract class BaseHandler extends ListenerAdapter {
protected abstract long botOwnerId();


public static void checkIfBuildIsNull(Object build) {
if (Objects.isNull(build)) {
throw new IllegalArgumentException("Build is null");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,20 @@ protected MessageCommandHandler(@NotNull JDA jda, @NotNull Guild guild) {
* The Command class is an interface class which contains all the need methods for the
* making of the command. <br>
* <br>
* The boolean {@link MessageCommandExtender#isGuildOnly()} ()} ()} is used to determine
* The boolean {@link MessageCommandExtender#build#isGuildOnly()} is used to determine
* whether the command should be global or guild only. determines whether the command
* should be Global or Guild only.
*/
@SuppressWarnings("ResultOfMethodCallIgnored")
private void addMessageCommand(@NotNull MessageCommandExtender command) {
jda.addEventListener(command);
messageCommand.put(command.getCommandData().getName(), command);
if (command.isGuildOnly()) {
guildCommandsData.addCommands(command.getCommandData());

BaseHandler.checkIfBuildIsNull(command.build());

messageCommand.put(command.build().getCommandData().getName(), command);
if (command.build().isGuildOnly()) {
guildCommandsData.addCommands(command.build().getCommandData());
} else {
globalCommandsData.addCommands(command.getCommandData());
globalCommandsData.addCommands(command.build().getCommandData());
}
}

Expand Down Expand Up @@ -88,22 +90,27 @@ private void onFinishedRegistration() {
public void onMessageContextInteraction(@Nonnull MessageContextInteractionEvent event) {
final MessageCommandExtender cmd = messageCommand.get(event.getName());

if (cmd.isOwnerOnly() && event.getUser().getIdLong() != botOwnerId()) {
if (cmd.build().isOwnerOnly() && event.getUser().getIdLong() != botOwnerId()) {
event.reply("You do not have permission to use this command.")
.setEphemeral(true)
.queue();
return;
}

if (Objects.requireNonNull(event.getMember()).hasPermission(cmd.getUserPerms())
|| Objects.requireNonNull(event.getGuild())
.getSelfMember()
.hasPermission(cmd.getBotPerms())) {
cmd.onMessageContextInteraction(event);
} else {
if (cmd.build().getUserPerms() != null
&& event.getMember().hasPermission(cmd.build().getUserPerms())) {
event.reply("You do not have permission to use this command.")
.setEphemeral(true)
.queue();
} else {
cmd.onMessageContextInteraction(event);
}

if (cmd.build().getBotPerms() != null
&& event.getGuild().getSelfMember().hasPermission(cmd.build().getBotPerms())) {
event.reply("I do not have permission to use this command.").setEphemeral(true).queue();
} else {
cmd.onMessageContextInteraction(event);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,20 @@ protected SlashCommandHandler(@NotNull JDA jda, @NotNull Guild guild) {
* The Command class is an interface class which contains all the need methods for the
* making of the command. <br>
* <br>
* The boolean {@link SlashCommandExtender#isGuildOnly()} ()} ()} is used to determine
* The boolean {@link SlashCommandExtender#build()#isGuildOnly()} is used to determine
* whether the command should be global or guild only. determines whether the command
* should be Global or Guild only.
*/
@SuppressWarnings("ResultOfMethodCallIgnored")
private void addSlashCommand(@NotNull SlashCommandExtender command) {
jda.addEventListener(command);
slashCommand.put(command.getSlashCommandData().getName(), command);
if (command.isGuildOnly()) {
guildCommandsData.addCommands(command.getSlashCommandData());

BaseHandler.checkIfBuildIsNull(command.build());

slashCommand.put(command.build().getSlashCommandData().getName(), command);
if (command.build().isGuildOnly()) {
guildCommandsData.addCommands(command.build().getSlashCommandData());
} else {
globalCommandsData.addCommands(command.getSlashCommandData());
globalCommandsData.addCommands(command.build().getSlashCommandData());
}
}

Expand Down Expand Up @@ -110,22 +112,27 @@ private void onFinishedRegistration() {
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
final SlashCommandExtender cmd = slashCommand.get(event.getName());

if (cmd.isOwnerOnly() && event.getUser().getIdLong() != botOwnerId()) {
if (cmd.build().isOwnerOnly() && event.getUser().getIdLong() != botOwnerId()) {
event.reply("You do not have permission to use this command.")
.setEphemeral(true)
.queue();
return;
}

if (Objects.requireNonNull(event.getMember()).hasPermission(cmd.getUserPerms())
|| Objects.requireNonNull(event.getGuild())
.getSelfMember()
.hasPermission(cmd.getBotPerms())) {
cmd.onSlashCommandInteraction(event);
} else {
if (cmd.build().getUserPerms() != null
&& event.getMember().hasPermission(cmd.build().getUserPerms())) {
event.reply("You do not have permission to use this command.")
.setEphemeral(true)
.queue();
} else {
cmd.onSlashCommandInteraction(event);
}

if (cmd.build().getBotPerms() != null
&& event.getGuild().getSelfMember().hasPermission(cmd.build().getBotPerms())) {
event.reply("I do not have permission to use this command.").setEphemeral(true).queue();
} else {
cmd.onSlashCommandInteraction(event);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,20 @@ protected UserCommandHandler(@NotNull JDA jda, @NotNull Guild guild) {
* The Command class is an interface class which contains all the need methods for the
* making of the command. <br>
* <br>
* The boolean {@link UserCommandExtender#isGuildOnly()} ()} ()} is used to determine
* The boolean {@link UserCommandExtender#build#isGuildOnly()} is used to determine
* whether the command should be global or guild only. determines whether the command
* should be Global or Guild only.
*/
@SuppressWarnings("ResultOfMethodCallIgnored")
private void addUserCommand(@NotNull UserCommandExtender command) {
jda.addEventListener(command);
userCommand.put(command.getCommandData().getName(), command);
if (command.isGuildOnly()) {
guildCommandsData.addCommands(command.getCommandData());

BaseHandler.checkIfBuildIsNull(command.build());

userCommand.put(command.build().getCommandData().getName(), command);
if (command.build().isGuildOnly()) {
guildCommandsData.addCommands(command.build().getCommandData());
} else {
globalCommandsData.addCommands(command.getCommandData());
globalCommandsData.addCommands(command.build().getCommandData());
}
}

Expand Down Expand Up @@ -89,22 +91,27 @@ private void onFinishedRegistration() {
public void onUserContextInteraction(@NotNull UserContextInteractionEvent event) {
final UserCommandExtender cmd = userCommand.get(event.getName());

if (cmd.isOwnerOnly() && event.getUser().getIdLong() != botOwnerId()) {
if (cmd.build().isOwnerOnly() && event.getUser().getIdLong() != botOwnerId()) {
event.reply("You do not have permission to use this command.")
.setEphemeral(true)
.queue();
return;
}

if (Objects.requireNonNull(event.getMember()).hasPermission(cmd.getUserPerms())
|| Objects.requireNonNull(event.getGuild())
.getSelfMember()
.hasPermission(cmd.getBotPerms())) {
cmd.onUserContextInteraction(event);
} else {
if (cmd.build().getUserPerms() != null
&& event.getMember().hasPermission(cmd.build().getUserPerms())) {
event.reply("You do not have permission to use this command.")
.setEphemeral(true)
.queue();
} else {
cmd.onUserContextInteraction(event);
}

if (cmd.build().getBotPerms() != null
&& event.getGuild().getSelfMember().hasPermission(cmd.build().getBotPerms())) {
event.reply("I do not have permission to use this command.").setEphemeral(true).queue();
} else {
cmd.onUserContextInteraction(event);
}
}

Expand Down
Loading