Compare commits
No commits in common. "448f98ba354ba62b3a1057081f5b5a74ca161cfc" and "f8f0bb493b24bdc0ced86ce1b5232efc1de8c23b" have entirely different histories.
448f98ba35
...
f8f0bb493b
13 changed files with 25 additions and 43 deletions
|
@ -1,7 +0,0 @@
|
||||||
<component name="InspectionProjectProfileManager">
|
|
||||||
<profile version="1.0">
|
|
||||||
<option name="myName" value="Project Default" />
|
|
||||||
<inspection_tool class="InstantiationOfUtilityClass" enabled="false" level="WARNING" enabled_by_default="false" />
|
|
||||||
<inspection_tool class="XmlHighlighting" enabled="false" level="ERROR" enabled_by_default="false" />
|
|
||||||
</profile>
|
|
||||||
</component>
|
|
|
@ -1,11 +1,10 @@
|
||||||
<img src="https://git.frzn.dev/fwoppydwisk/doki/raw/branch/master/assets/logo.svg" alt="" height="100"/>
|
<img src="https://git.frzn.dev/fwoppydwisk/doki/raw/branch/master/assets/logo.svg" alt="" height="100" align="center"/>
|
||||||
<hr>
|
<hr>
|
||||||
A multipurpose Discord bot written in Java.
|
A multi-purpose Discord bot written in Java.
|
||||||
|
|
||||||
## Tested Environments
|
## Requirements
|
||||||
- Java 21+ (May work on older versions but untested)
|
- Java 22 (May work on older versions but only tested on 22)
|
||||||
- Maven
|
- Maven
|
||||||
|
|
||||||
### Tested Operating Systems
|
### Tested Operating Systems
|
||||||
- macOS 14.4.1
|
- macOS 14.4.1
|
||||||
- Windows 10 (22H2)
|
|
|
@ -1,6 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||||
<!--suppress ALL -->
|
|
||||||
<svg width="100%" height="100%" viewBox="0 0 916 343" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
|
<svg width="100%" height="100%" viewBox="0 0 916 343" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
|
||||||
<g id="Artboard1" transform="matrix(0.966913,0,0,0.97623,-273.569,-463.226)">
|
<g id="Artboard1" transform="matrix(0.966913,0,0,0.97623,-273.569,-463.226)">
|
||||||
<rect x="282.93" y="474.505" width="946.66" height="350.874" style="fill:none;"/>
|
<rect x="282.93" y="474.505" width="946.66" height="350.874" style="fill:none;"/>
|
||||||
|
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
|
@ -4,6 +4,7 @@ import com.google.gson.Gson;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
//You can add more fields in this class, if your input json matches the structure
|
//You can add more fields in this class, if your input json matches the structure
|
||||||
//You will need a valid config.json in the package com.freya02.bot for this to work
|
//You will need a valid config.json in the package com.freya02.bot for this to work
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class Doki {
|
||||||
public static String getPrefix() { return config.getPrefix(); }
|
public static String getPrefix() { return config.getPrefix(); }
|
||||||
public static BasicDataSource getDataSource() { return dataSource; }
|
public static BasicDataSource getDataSource() { return dataSource; }
|
||||||
|
|
||||||
public static void start() throws IOException, InterruptedException {
|
public static Doki start() throws IOException, InterruptedException {
|
||||||
config = Config.readConfig();
|
config = Config.readConfig();
|
||||||
Config.DBConfig dbConfig = config.getDbConfig();
|
Config.DBConfig dbConfig = config.getDbConfig();
|
||||||
|
|
||||||
|
@ -56,13 +56,12 @@ public class Doki {
|
||||||
LOGGER.info("\t- {} ({})", guild.getName(), guild.getId());
|
LOGGER.info("\t- {} ({})", guild.getName(), guild.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
new Doki(jda, config);
|
return new Doki(jda, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
start();
|
jda = start().getJDA();
|
||||||
jda = getJDA();
|
|
||||||
CommandsBuilder.newBuilder(437970062922612737L)
|
CommandsBuilder.newBuilder(437970062922612737L)
|
||||||
.textCommandBuilder(textCommandsBuilder -> textCommandsBuilder.addPrefix(getPrefix()))
|
.textCommandBuilder(textCommandsBuilder -> textCommandsBuilder.addPrefix(getPrefix()))
|
||||||
.build(jda, "net.hypr.doki.commands"); //Registering listeners is taken care of by the lib
|
.build(jda, "net.hypr.doki.commands"); //Registering listeners is taken care of by the lib
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package net.hypr.doki.commands.utils;
|
package net.hypr.doki.commands;
|
||||||
|
|
||||||
import com.freya02.botcommands.api.annotations.CommandMarker;
|
import com.freya02.botcommands.api.annotations.CommandMarker;
|
||||||
import com.freya02.botcommands.api.prefixed.CommandEvent;
|
import com.freya02.botcommands.api.prefixed.CommandEvent;
|
|
@ -1,4 +1,4 @@
|
||||||
package net.hypr.doki.commands.levelling;
|
package net.hypr.doki.commands;
|
||||||
|
|
||||||
import com.freya02.botcommands.api.annotations.CommandMarker;
|
import com.freya02.botcommands.api.annotations.CommandMarker;
|
||||||
import com.freya02.botcommands.api.prefixed.CommandEvent;
|
import com.freya02.botcommands.api.prefixed.CommandEvent;
|
|
@ -1,4 +1,4 @@
|
||||||
package net.hypr.doki.commands.utils;
|
package net.hypr.doki.commands;
|
||||||
|
|
||||||
import com.freya02.botcommands.api.annotations.CommandMarker;
|
import com.freya02.botcommands.api.annotations.CommandMarker;
|
||||||
import com.freya02.botcommands.api.prefixed.CommandEvent;
|
import com.freya02.botcommands.api.prefixed.CommandEvent;
|
|
@ -1,4 +1,4 @@
|
||||||
package net.hypr.doki.commands.levelling;
|
package net.hypr.doki.commands;
|
||||||
|
|
||||||
import com.freya02.botcommands.api.annotations.CommandMarker;
|
import com.freya02.botcommands.api.annotations.CommandMarker;
|
||||||
import com.freya02.botcommands.api.prefixed.BaseCommandEvent;
|
import com.freya02.botcommands.api.prefixed.BaseCommandEvent;
|
|
@ -1,4 +1,4 @@
|
||||||
package net.hypr.doki.commands.utils;
|
package net.hypr.doki.commands;
|
||||||
|
|
||||||
import com.freya02.botcommands.api.annotations.CommandMarker;
|
import com.freya02.botcommands.api.annotations.CommandMarker;
|
||||||
import com.freya02.botcommands.api.prefixed.BaseCommandEvent;
|
import com.freya02.botcommands.api.prefixed.BaseCommandEvent;
|
|
@ -19,26 +19,17 @@ public class LevellingListener extends ListenerAdapter {
|
||||||
@Override
|
@Override
|
||||||
public void onMessageReceived(MessageReceivedEvent event) {
|
public void onMessageReceived(MessageReceivedEvent event) {
|
||||||
Logger log = Logging.getLogger();
|
Logger log = Logging.getLogger();
|
||||||
|
|
||||||
/* Ignore the message if one of the following conditions is met:
|
/* Ignore the message if one of the following conditions is met:
|
||||||
- Message is from self user
|
- Message is from self user
|
||||||
- Message is from a bot
|
- Message is from bot
|
||||||
- Message is command (starts with bot prefix)
|
- Message is command (starts with bot prefix)
|
||||||
- Message is a Direct Message to the bot
|
|
||||||
*/
|
*/
|
||||||
try {
|
|
||||||
event.getGuild();
|
|
||||||
} catch (IllegalStateException ex) {
|
|
||||||
log.debug("Ignoring direct message with ID {}", event.getMessageId());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
Doki.getJDA().getSelfUser().getId().equals(event.getAuthor().getId()) ||
|
Doki.getJDA().getSelfUser().getId().equals(event.getAuthor().getId()) ||
|
||||||
event.getAuthor().isBot() ||
|
event.getAuthor().isBot() ||
|
||||||
event.getMessage().getContentStripped().startsWith(Doki.getPrefix())
|
event.getMessage().getContentStripped().startsWith(Doki.getPrefix())
|
||||||
) {
|
) {
|
||||||
log.debug("Ignoring self/bot message with ID {}", event.getMessageId());
|
log.debug("Ignoring self/bot message with ID " + event.getMessageId());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,13 +47,13 @@ public class LevellingListener extends ListenerAdapter {
|
||||||
// it has been over an hour since the user last sent a message that affected XP
|
// it has been over an hour since the user last sent a message that affected XP
|
||||||
LevellingUtils.incrementXp(log, rec);
|
LevellingUtils.incrementXp(log, rec);
|
||||||
} else {
|
} else {
|
||||||
log.debug("Ignoring message ID {} as not enough time has passed", event.getMessageId());
|
log.debug("Ignoring message ID " + event.getMessageId() + " as not enough time has passed");
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.info("No record of user ID {} in server {}, creating blank record", user.getId(), guild.getId());
|
log.info("No record of user ID " + user.getId() + " in server " + guild.getId() + ", creating blank record");
|
||||||
try {
|
try {
|
||||||
DBUtils.createUserRecord(user.getIdLong(), guild.getIdLong(), user.getName());
|
DBUtils.createUserRecord(user.getIdLong(), guild.getIdLong(), user.getName());
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|
|
@ -36,9 +36,9 @@ public class DBUtils {
|
||||||
|
|
||||||
// Find out if the user is already in the DB
|
// Find out if the user is already in the DB
|
||||||
try {
|
try {
|
||||||
log.debug("Searching DB for (usr{},srv:{})", user_id, server_id);
|
log.debug("Searching DB for (usr" + user_id + ",srv:" + server_id + ")");
|
||||||
Set<BigInteger> foundIds = qr.query("SELECT user_id FROM users WHERE user_id = " + user_id + " AND server_id = " + server_id, resultSetHandler);
|
Set<BigInteger> foundIds = qr.query("SELECT user_id FROM users WHERE user_id = " + user_id + " AND server_id = " + server_id, resultSetHandler);
|
||||||
log.debug("Matching records: {}", foundIds.size());
|
log.debug("Matching records: " + foundIds.size());
|
||||||
return !foundIds.isEmpty();
|
return !foundIds.isEmpty();
|
||||||
} catch (SQLException ignored) {
|
} catch (SQLException ignored) {
|
||||||
log.debug("An SQL error occurred");
|
log.debug("An SQL error occurred");
|
||||||
|
@ -55,7 +55,7 @@ public class DBUtils {
|
||||||
*/
|
*/
|
||||||
public static void createUserRecord(long user_id, long server_id, String username) throws SQLException {
|
public static void createUserRecord(long user_id, long server_id, String username) throws SQLException {
|
||||||
Logger log = Logging.getLogger();
|
Logger log = Logging.getLogger();
|
||||||
log.info("Creating record (usr:{},srv:{},unm:{})", user_id, server_id, username);
|
log.info("Creating record (usr:" + user_id + ",srv:" + server_id + ",unm:" + username + ")");
|
||||||
BasicDataSource dataSource = Doki.getDataSource();
|
BasicDataSource dataSource = Doki.getDataSource();
|
||||||
Connection conn = dataSource.getConnection();
|
Connection conn = dataSource.getConnection();
|
||||||
PreparedStatement stmt = conn.prepareStatement(
|
PreparedStatement stmt = conn.prepareStatement(
|
||||||
|
@ -66,7 +66,7 @@ public class DBUtils {
|
||||||
stmt.setString(3, username);
|
stmt.setString(3, username);
|
||||||
stmt.setTimestamp(4, Timestamp.valueOf(LocalDateTime.now()));
|
stmt.setTimestamp(4, Timestamp.valueOf(LocalDateTime.now()));
|
||||||
stmt.execute();
|
stmt.execute();
|
||||||
log.info("Record (usr:{},srv:{},unm:{}) created!", user_id, server_id, username);
|
log.info("Record (usr:" + user_id + ",srv:" + server_id + ",unm:" + username + ") created!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -81,7 +81,7 @@ public class DBUtils {
|
||||||
*/
|
*/
|
||||||
public static void updateUserRecord(long user_id, long server_id, Timestamp now, int xp, int totalXp, int level) throws SQLException {
|
public static void updateUserRecord(long user_id, long server_id, Timestamp now, int xp, int totalXp, int level) throws SQLException {
|
||||||
Logger log = Logging.getLogger();
|
Logger log = Logging.getLogger();
|
||||||
log.info("Updating record (usr:{},srv:{})", user_id, server_id);
|
log.info("Updating record (usr:" + user_id + ",srv:" + server_id + ")");
|
||||||
BasicDataSource dataSource = Doki.getDataSource();
|
BasicDataSource dataSource = Doki.getDataSource();
|
||||||
Connection conn = dataSource.getConnection();
|
Connection conn = dataSource.getConnection();
|
||||||
PreparedStatement stmt = conn.prepareStatement(
|
PreparedStatement stmt = conn.prepareStatement(
|
||||||
|
@ -94,7 +94,7 @@ public class DBUtils {
|
||||||
stmt.setLong(5, user_id);
|
stmt.setLong(5, user_id);
|
||||||
stmt.setLong(6, server_id);
|
stmt.setLong(6, server_id);
|
||||||
stmt.executeQuery();
|
stmt.executeQuery();
|
||||||
log.info("Updated record (usr:{},srv:{})!", user_id, server_id);
|
log.info("Updated record (usr:" + user_id + ",srv:" + server_id + ")!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -27,9 +27,9 @@ public class LevellingUtils {
|
||||||
totalXp,
|
totalXp,
|
||||||
levelNew
|
levelNew
|
||||||
);
|
);
|
||||||
logger.info("Incremented {}'s XP in {} ({} -> {})", userRecord.username, userRecord.server_id, userRecord.xp, xpNew);
|
logger.info("Incremented " + userRecord.username + "'s XP in " + userRecord.server_id + " (" + userRecord.xp + " -> " + xpNew + ")");
|
||||||
if (levelNew > userRecord.level) {
|
if (levelNew > userRecord.level) {
|
||||||
logger.info("Incremented {}'s level in {} ({} -> {})", userRecord.username, userRecord.server_id, userRecord.level, levelNew);
|
logger.info("Incremented " + userRecord.username + "'s level in " + userRecord.server_id + " (" + userRecord.level + " -> " + levelNew + ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue