Periodic update

This commit is contained in:
Steven Tracey 2022-04-27 21:50:06 -04:00
parent 62ea316e07
commit 98abaccf25
21 changed files with 466 additions and 212 deletions

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>

View File

@ -7,7 +7,7 @@ plugins {
mainClassName = 'net.nevet5.buzzbot.Bot' mainClassName = 'net.nevet5.buzzbot.Bot'
group 'net.nevet5' group 'net.nevet5'
version '0.2.0' version '0.3.0'
def jdaVer = '4.4.0_350' def jdaVer = '4.4.0_350'
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17 sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17
@ -28,10 +28,12 @@ repositories {
dependencies { dependencies {
implementation("net.dv8tion:JDA:$jdaVer") implementation("net.dv8tion:JDA:$jdaVer")
implementation 'ch.qos.logback:logback-classic:1.2.8'
implementation group: 'me.duncte123', name: 'botCommons', version: '2.3.8' implementation group: 'me.duncte123', name: 'botCommons', version: '2.3.8'
implementation 'com.google.code.gson:gson:2.9.0' implementation 'com.google.code.gson:gson:2.9.0'
implementation 'me.carleslc.Simple-YAML:Simple-Yaml:1.7.2' implementation 'me.carleslc.Simple-YAML:Simple-Yaml:1.7.2'
implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.28' implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.28'
implementation 'com.github.Kaktushose:jda-commands:v.2.2.0'
} }
compileJava.options.encoding = 'UTF-8' compileJava.options.encoding = 'UTF-8'

View File

@ -1,5 +1,6 @@
package net.nevet5.buzzbot; package net.nevet5.buzzbot;
import com.github.kaktushose.jda.commands.JDACommands;
import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity; import net.dv8tion.jda.api.entities.Activity;
@ -28,6 +29,8 @@ public class Bot {
} catch (LoginException e) { } catch (LoginException e) {
e.printStackTrace(); e.printStackTrace();
} }
JDACommands.start(jda, Bot.class, "net.nevet5.buzzbot.commands.slash");
} }
public static void getActivity() { public static void getActivity() {
@ -45,37 +48,5 @@ public class Bot {
jda.getPresence().setActivity(Activity.playing("with myself!")); jda.getPresence().setActivity(Activity.playing("with myself!"));
} }
} }
// public static void main(String[] args) {
// Config.loadConfig();
//
// JDABuilder jdaBotBuilder = JDABuilder.createDefault(Config.getConfig().getString("bot.token"));
// // A token must be provided
//
// /* Start the JDA bot builder, letting you provide the token externally rather
// * than writing it in your program's code. args[0] is the token. */
//
// // Disable parts of the cache
// jdaBotBuilder.disableCache(CacheFlag.MEMBER_OVERRIDES, CacheFlag.VOICE_STATE);
//
// // Enable the bulk delete event - this means you'll have to handle it yourself!
// jdaBotBuilder.setBulkDeleteSplittingEnabled(false);
//
// // Set activity (like "playing Something")
//
// // Set event listeners
// jdaBotBuilder.addEventListeners(/*new MessageListener(), new ReadyListener()*/);
//
// try {
// // create the instance of JDA
// JDA discordBot = jdaBotBuilder.build();
//
// // optionally block until JDA is ready
// discordBot.awaitReady();
// } catch (LoginException | InterruptedException e) {
// System.err.println("Couldn't login.");
// e.printStackTrace();
// }
// }
} }

View File

@ -0,0 +1,5 @@
package net.nevet5.buzzbot;
public class Group {
}

View File

@ -13,7 +13,7 @@ public class Listener extends ListenerAdapter {
@Override @Override
public void onReady(@Nonnull ReadyEvent event) { public void onReady(@Nonnull ReadyEvent event) {
System.out.println("BuzzBot is ready" + event.getJDA().getSelfUser().getAsTag()); System.out.println("BuzzBot is ready: " + event.getJDA().getSelfUser().getAsTag());
} }
@Override @Override

View File

@ -1,19 +1,15 @@
package net.nevet5.buzzbot; package net.nevet5.buzzbot;
import net.nevet5.buzzbot.database.SqlDB;
import java.sql.Date;
import java.sql.Time;
import java.time.LocalDate;
import java.time.LocalTime;
public class Test { public class Test {
public static void main(String[] args) { public static void main(String[] args) {
//TODO Fix This
Config.loadConfig(); Config.loadConfig();
SqlDB db = new SqlDB();
db.set(672987743361695745L, "nevetS", 3866, Date.valueOf(LocalDate.now()), Time.valueOf(LocalTime.now()), true, 0, "Reason", "5gi", 865368792980914186L, "DevHQ", 824071914673668138L);
db.insert();
// SqlDB db = new SqlDB();
// BanEntry ban = new BanEntry(972924565361695745L, "nevetS", 3866, Date.valueOf(LocalDate.now()), Time.valueOf(LocalTime.now()), true, 0, "Reason", "test3", 865368792980914186L, "DevHQ", 824071914673668138L);
// db.insertBan(ban, "masterbanlist");
} }
} }

View File

@ -0,0 +1,21 @@
package net.nevet5.buzzbot.commands;
import net.nevet5.buzzbot.commands.utils.CommandContext;
import net.nevet5.buzzbot.commands.utils.ICommand;
public class MuteCmd implements ICommand {
@Override
public void handle(CommandContext ctx) {
ctx.getMessage().reply("This command has not been implemented yet").queue();
}
@Override
public String getName() {
return "mute";
}
@Override
public String getHelp() {
return "Mutes the specified user";
}
}

View File

@ -0,0 +1,21 @@
package net.nevet5.buzzbot.commands;
import net.nevet5.buzzbot.commands.utils.CommandContext;
import net.nevet5.buzzbot.commands.utils.ICommand;
public class TestCmd implements ICommand {
@Override
public void handle(CommandContext ctx) {
ctx.getMessage().reply("text").queue();
}
@Override
public String getName() {
return "test";
}
@Override
public String getHelp() {
return null;
}
}

View File

@ -0,0 +1,21 @@
package net.nevet5.buzzbot.commands;
import net.nevet5.buzzbot.commands.utils.CommandContext;
import net.nevet5.buzzbot.commands.utils.ICommand;
public class UnbanCmd implements ICommand {
@Override
public void handle(CommandContext ctx) {
ctx.getMessage().reply("This command doesn't work yet").queue();
}
@Override
public String getName() {
return "unban";
}
@Override
public String getHelp() {
return "Unbans the specified user";
}
}

View File

@ -0,0 +1,21 @@
package net.nevet5.buzzbot.commands;
import net.nevet5.buzzbot.commands.utils.CommandContext;
import net.nevet5.buzzbot.commands.utils.ICommand;
public class UnmuteCmd implements ICommand {
@Override
public void handle(CommandContext ctx) {
ctx.getMessage().reply("This command has not been implemented yet").queue();
}
@Override
public String getName() {
return "unmute";
}
@Override
public String getHelp() {
return "Unmutes the specified user";
}
}

View File

@ -0,0 +1,22 @@
package net.nevet5.buzzbot.commands;
import net.nevet5.buzzbot.commands.utils.CommandContext;
import net.nevet5.buzzbot.commands.utils.ICommand;
public class UnwarnCmd implements ICommand {
//TODO Make this command only work for warns that were given from the same server
@Override
public void handle(CommandContext ctx) {
ctx.getMessage().reply("This command has not been implemented yet").queue();
}
@Override
public String getName() {
return "unwarn";
}
@Override
public String getHelp() {
return "Unwarns the specified user";
}
}

View File

@ -0,0 +1,21 @@
package net.nevet5.buzzbot.commands;
import net.nevet5.buzzbot.commands.utils.CommandContext;
import net.nevet5.buzzbot.commands.utils.ICommand;
public class WarnCmd implements ICommand {
@Override
public void handle(CommandContext ctx) {
ctx.getMessage().reply("This command has not been implemented yet").queue();
}
@Override
public String getName() {
return "warn";
}
@Override
public String getHelp() {
return "Warns the specified user";
}
}

View File

@ -2,10 +2,7 @@ package net.nevet5.buzzbot.commands.utils;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.nevet5.buzzbot.Config; import net.nevet5.buzzbot.Config;
import net.nevet5.buzzbot.commands.BanCmd; import net.nevet5.buzzbot.commands.*;
import net.nevet5.buzzbot.commands.HelpCmd;
import net.nevet5.buzzbot.commands.PandaCmd;
import net.nevet5.buzzbot.commands.PingCmd;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
@ -20,8 +17,13 @@ public class CommandManager {
//Add to this list in alphabetical order //Add to this list in alphabetical order
addCommand(new BanCmd()); addCommand(new BanCmd());
addCommand(new HelpCmd(this)); addCommand(new HelpCmd(this));
addCommand(new MuteCmd());
addCommand(new PandaCmd()); addCommand(new PandaCmd());
addCommand(new PingCmd()); addCommand(new PingCmd());
addCommand(new UnbanCmd());
addCommand(new UnmuteCmd());
addCommand(new UnwarnCmd());
addCommand(new WarnCmd());
//addCommand(new CommandClass()); //addCommand(new CommandClass());
} }

View File

@ -1,88 +1,69 @@
package net.nevet5.buzzbot.database; package net.nevet5.buzzbot.database;
import net.nevet5.buzzbot.Config; import net.nevet5.buzzbot.Config;
import net.nevet5.buzzbot.objects.BanData;
import java.sql.*; import java.sql.*;
import java.time.LocalDate;
import java.time.LocalTime;
public class SqlDB { public class SqlDB {
//TODO Make this a two way class for reading and writing from db //TODO Make this a two way class for reading and writing from db
private long userId;
private String userName;
private int userDiscriminator;
private Date date = Date.valueOf(LocalDate.now());
private Time time = Time.valueOf(LocalTime.now());
private boolean banType;
private int banLength;
private String banReason;
private String modName;
private long modId;
private String serverName;
private long serverId;
private Connection connect; private Connection connect;
private Statement statement; private Statement statement;
private PreparedStatement preparedStatement;
private ResultSet resultSet; private ResultSet resultSet;
public SqlDB() { public SqlDB() {
try { try {
Class.forName("com.mysql.jdbc.Driver"); Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://" + Config.getConfig().getString("database.url") + "/" + Config.getConfig().getString("database.database") + "?user=" + Config.getConfig().getString("database.user") + "&password=" + Config.getConfig().getString("database.password")); connect = DriverManager.getConnection("jdbc:mysql://" + Config.getConfig().getString("database.url") + "/" + Config.getConfig().getString("database.database"), Config.getConfig().getString("database.user"), Config.getConfig().getString("database.password"));
statement = connect.createStatement();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public void readDatabase() { public void insertBan(BanData ban, String table) {
try { try {
Class.forName("com.mysql.jdbc.Driver"); System.out.println("Created Statement");
statement.executeUpdate("INSERT INTO " + table + " VALUES (default, " + ban.getUserId() + ", '" + ban.getUserName() + "', '" + ban.getUserDiscriminator() + "', '" + ban.getDate() + "', '" + ban.getTime() + "', " + ban.getBanType() + ", " + ban.getBanLength() + ", '" + ban.getBanReason() + "', '" + ban.getModName() + "', " + ban.getModId() + ", '" + ban.getServerName() + "', " + ban.getServerId() + ")");
connect = DriverManager.getConnection("jdbc:mysql://" + Config.getConfig().getString("database.url") + "/" + Config.getConfig().getString("database.database") + "?user=" + Config.getConfig().getString("database.user") + "&password=" + Config.getConfig().getString("database.password")); System.out.println("Executed Statement");
close();
statement = connect.createStatement(); System.out.println("Closed");
resultSet = statement
.executeQuery("SELECT * FROM masterbanlist");
} catch (ClassNotFoundException | SQLException e) {
throw new RuntimeException(e);
}
}
public void insert() {
try {
statement = connect.createStatement();
resultSet = statement.executeQuery("INSERT INTO " + Config.getConfig().getString("database.database") + " VALUES (default, " + userId + ", '" + userName + "', '" + userDiscriminator + "', '" + date + "', '" + time + "', " + banType + ", " + banLength + ", '" + banReason + "', '" + modName + "', " + modId + ", '" + serverName + "', " + serverId + ");");
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); e.printStackTrace();
} }
} }
private void query(ResultSet resultSet) throws SQLException { private BanData query(long userId) throws SQLException {
BanData ban = new BanData();
String group = "masterbanlist"; //TODO Make this use GuildUtils in order to get the proper group for the server
resultSet = statement.executeQuery("SELECT * IN " + group + " WHERE userId='" + userId + "'");
while (resultSet.next()) { while (resultSet.next()) {
userId = resultSet.getLong("userid"); ban.setUserId(resultSet.getLong("userid"));
userName = resultSet.getString("username"); ban.setUserName(resultSet.getString("username"));
userDiscriminator = resultSet.getInt("userdiscriminator"); ban.setUserDiscriminator(resultSet.getInt("userdiscriminator"));
date = resultSet.getDate("bandate"); ban.setDate(resultSet.getDate("bandate"));
time = resultSet.getTime("bantime"); ban.setTime(resultSet.getTime("bantime"));
banType = resultSet.getBoolean("bantype"); ban.setBanType(resultSet.getBoolean("bantype"));
banLength = resultSet.getInt(""); ban.setBanLength(resultSet.getInt(""));
banReason = resultSet.getString("banreason"); ban.setBanReason(resultSet.getString("banreason"));
modName = resultSet.getString("modname"); ban.setModName(resultSet.getString("modname"));
modId = resultSet.getLong("modid"); ban.setModId(resultSet.getLong("modid"));
serverName = resultSet.getString("servername"); ban.setServerName(resultSet.getString("servername"));
serverId = resultSet.getLong("serverid"); ban.setServerId(resultSet.getLong("serverid"));
} }
return ban;
} }
private void close() { private void close() {
try { try {
if (resultSet != null) { //if (resultSet != null) {
resultSet.close(); // resultSet.close();
} //}
if (statement != null) { if (statement != null) {
statement.close(); statement.close();
@ -96,114 +77,4 @@ public class SqlDB {
} }
} }
public void set(long userId, String userName, int userDiscriminator, Date date, Time time, boolean banType, int banLength, String banReason, String modName, long modId, String serverName, long serverId) {
this.userId = userId;
this.userName = userName;
this.userDiscriminator = userDiscriminator;
this.date = date;
this.time = time;
this.banType = banType;
this.banLength = banLength;
this.banReason = banReason;
this.modName = modName;
this.modId = modId;
this.serverName = serverName;
this.serverId = serverId;
}
public void setUserId(long userId) {
this.userId = userId;
}
public long getUserId() {
return userId;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserName() {
return userName;
}
public void setUserDiscriminator(int userDiscriminator) {
this.userDiscriminator = userDiscriminator;
}
public int getUserDiscriminator() {
return userDiscriminator;
}
public void setDate(Date date) {
this.date = date;
}
public Date getDate() {
return date;
}
public void setTime(Time time) {
this.time = time;
}
public Time getTime() {
return time;
}
public void setBanType(boolean banType) {
this.banType = banType;
}
public boolean getBanType() {
return banType;
}
public void setBanLength(int banLength) {
this.banLength = banLength;
}
public int getBanLength() {
return banLength;
}
public void setBanReason(String banReason) {
this.banReason = banReason;
}
public String getBanReason() {
return banReason;
}
public void setModName(String modName) {
this.modName = modName;
}
public String getModName() {
return modName;
}
public void setModId(long modId) {
this.modId = modId;
}
public long getModId() {
return modId;
}
public void setServerName(String serverName) {
this.serverName = serverName;
}
public String getServerName() {
return serverName;
}
public void setServerId(long serverId) {
this.serverId = serverId;
}
public long getServerId() {
return serverId;
}
} }

View File

@ -0,0 +1,43 @@
package net.nevet5.buzzbot.objects;
import java.sql.Date;
import java.sql.Time;
public class BanData extends UserData {
private boolean banType;
private int banLength;
private String banReason;
public BanData() {}
public BanData(long userId, String userName, int userDiscriminator, Date date, Time time, boolean banType, int banLength, String banReason, String modName, long modId, String serverName, long serverId) {
super(userId, userName, userDiscriminator, date, time, modName, modId, serverName, serverId);
this.banType = banType;
this.banLength = banLength;
this.banReason = banReason;
}
public void setBanType(boolean banType) {
this.banType = banType;
}
public boolean getBanType() {
return banType;
}
public void setBanLength(int banLength) {
this.banLength = banLength;
}
public int getBanLength() {
return banLength;
}
public void setBanReason(String banReason) {
this.banReason = banReason;
}
public String getBanReason() {
return banReason;
}
}

View File

@ -0,0 +1,33 @@
package net.nevet5.buzzbot.objects;
import java.sql.Date;
import java.sql.Time;
public class MuteData extends UserData {
private int muteLength;
private String muteReason;
public MuteData() {}
public MuteData(long userId, String userName, int userDiscriminator, Date date, Time time, int muteLength, String muteReason, String modName, long modId, String serverName, long serverId) {
super(userId, userName, userDiscriminator, date, time, modName, modId, serverName, serverId);
this.muteLength = muteLength;
this.muteReason = muteReason;
}
public void setMuteLength(int muteLength) {
this.muteLength = muteLength;
}
public int getMuteLength() {
return muteLength;
}
public void setMuteReason(String muteReason) {
this.muteReason = muteReason;
}
public String getMuteReason() {
return muteReason;
}
}

View File

@ -0,0 +1,109 @@
package net.nevet5.buzzbot.objects;
import java.sql.Date;
import java.sql.Time;
import java.time.LocalDate;
import java.time.LocalTime;
public class UserData {
private String name = "users";
private long userId;
private String userName;
private int userDiscriminator;
private Date date = Date.valueOf(LocalDate.now());
private Time time = Time.valueOf(LocalTime.now());
private String modName;
private long modId;
private String serverName;
private long serverId;
public UserData() {}
public UserData(long userId, String userName, int userDiscriminator, Date date, Time time, String modName, long modId, String serverName, long serverId) {
this.setUserId(userId);
this.setUserName(userName);
this.setUserDiscriminator(userDiscriminator);
this.setDate(date);
this.setTime(time);
this.setModName(modName);
this.setModId(modId);
this.setServerName(serverName);
this.setServerId(serverId);
}
public String getName() {
return name;
}
public void setUserId(long userId) {
this.userId = userId;
}
public long getUserId() {
return userId;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserName() {
return userName;
}
public void setUserDiscriminator(int userDiscriminator) {
this.userDiscriminator = userDiscriminator;
}
public int getUserDiscriminator() {
return userDiscriminator;
}
public void setDate(Date date) {
this.date = date;
}
public Date getDate() {
return date;
}
public void setTime(Time time) {
this.time = time;
}
public Time getTime() {
return time;
}
public void setModName(String modName) {
this.modName = modName;
}
public String getModName() {
return modName;
}
public void setModId(long modId) {
this.modId = modId;
}
public long getModId() {
return modId;
}
public void setServerName(String serverName) {
this.serverName = serverName;
}
public String getServerName() {
return serverName;
}
public void setServerId(long serverId) {
this.serverId = serverId;
}
public long getServerId() {
return serverId;
}
}

View File

@ -0,0 +1,43 @@
package net.nevet5.buzzbot.objects;
import java.sql.Date;
import java.sql.Time;
public class WarnData extends UserData {
private boolean banType;
private int banLength;
private String banReason;
public WarnData() {}
public WarnData(long userId, String userName, int userDiscriminator, Date date, Time time, boolean banType, int banLength, String banReason, String modName, long modId, String serverName, long serverId) {
super(userId, userName, userDiscriminator, date, time, modName, modId, serverName, serverId);
this.banType = banType;
this.banLength = banLength;
this.banReason = banReason;
}
public void setBanType(boolean banType) {
this.banType = banType;
}
public boolean getBanType() {
return banType;
}
public void setBanLength(int banLength) {
this.banLength = banLength;
}
public int getBanLength() {
return banLength;
}
public void setBanReason(String banReason) {
this.banReason = banReason;
}
public String getBanReason() {
return banReason;
}
}

View File

@ -0,0 +1,10 @@
package net.nevet5.buzzbot.util;
import net.nevet5.buzzbot.Group;
public class GuildUtils {
public static Group getGroupById(long guildId) {
return new Group();
}
}

View File

@ -0,0 +1,29 @@
package net.nevet5.buzzbot.util;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.nevet5.buzzbot.objects.UserData;
import java.io.*;
import java.lang.reflect.Type;
public class JsonUtils <T extends UserData> {
T object;
public void createJson(T object) throws IOException {
Writer writer = new FileWriter("./" + object.getName() + ".json");
GsonBuilder builder = new GsonBuilder();
builder.setPrettyPrinting();
Gson gson = builder.create();
String jsonString = gson.toJson(object);
writer.write(jsonString);
writer.close();
}
public T loadJson(String jsonFileName) throws FileNotFoundException {
BufferedReader reader = new BufferedReader(new FileReader("./" + jsonFileName + ".json"));
return new Gson().fromJson(reader, (Type) object);
}
}

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} %-34.-34thread %10.10X{jda.shard} %-15.-15logger{0} %-6level %msg%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>