Compare commits

...

2 Commits

Author SHA1 Message Date
d8a43381d2 Added some more slash commands 2022-05-25 10:12:17 -04:00
6f87ef3a5e fixed db and reworked bans 2022-05-24 21:03:01 -04:00
12 changed files with 50 additions and 77 deletions

View File

@ -30,6 +30,7 @@ public class Bot {
.build(); .build();
CommandManager.registerSlashCommands(); CommandManager.registerSlashCommands();
getActivity(); getActivity();
LOGGER.info("BuzzBot finished loading!");
} catch (LoginException e) { } catch (LoginException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -18,16 +18,10 @@ public class Test {
private static JDA jda; private static JDA jda;
public static void main(String[] args) { public static void main(String[] args) {
Config.loadConfig(); Config.loadConfig();
initJda();
SqlDB sql = new SqlDB(); jda.retrieveUserById(712116155388526693L).queue(user -> { System.out.println(Integer.parseInt(user.getDiscriminator())); });
GuildData guild = new GuildData();
guild.setName("DevHQ");
guild.setId(824071914673668138L);
guild.setGroup("developer");
guild.setProfanityLevel(3);
sql.addGuild(guild);
//sqlTest(); //sqlTest();
} }
@ -51,7 +45,7 @@ public class Test {
private static void sqlTest() { private static void sqlTest() {
SqlDB db = new SqlDB(); SqlDB db = new SqlDB();
BanData ban = new BanData(972924565361695745L, "nevetS", 3866, Date.valueOf(LocalDate.now()), Time.valueOf(LocalTime.now()), true, 0, "Reason", "test3", 865368792980914186L, "DevHQ", 824071914673668138L); BanData ban = new BanData(972924565361695745L, "nevetS", Date.valueOf(LocalDate.now()), Time.valueOf(LocalTime.now()), true, 0, "Reason", "test3", 865368792980914186L, "DevHQ", 824071914673668138L);
db.insertBan(ban, "masterbanlist"); db.insertBan(ban, "masterbanlist");
SqlDB db2 = new SqlDB(); SqlDB db2 = new SqlDB();

View File

@ -3,6 +3,7 @@ package net.nevet5gi.buzzbot.commands;
import net.nevet5gi.buzzbot.Bot; import net.nevet5gi.buzzbot.Bot;
import net.nevet5gi.buzzbot.commands.utils.CommandContext; import net.nevet5gi.buzzbot.commands.utils.CommandContext;
import net.nevet5gi.buzzbot.commands.utils.ICommand; import net.nevet5gi.buzzbot.commands.utils.ICommand;
import net.nevet5gi.buzzbot.database.SqlDB;
import net.nevet5gi.buzzbot.objects.BanData; import net.nevet5gi.buzzbot.objects.BanData;
import java.util.List; import java.util.List;
@ -69,12 +70,13 @@ public class BanCmd implements ICommand {
} }
Bot.jda.retrieveUserById(ban.getUserId()).queue(user -> { ban.setUserName(user.getName()); }); Bot.jda.retrieveUserById(ban.getUserId()).queue(user -> { ban.setUserName(user.getName()); });
Bot.jda.retrieveUserById(ban.getUserId()).queue(user -> { ban.setUserDiscriminator(Integer.parseInt(user.getDiscriminator())); });
ban.setModId(ctx.getMessage().getAuthor().getIdLong()); ban.setModId(ctx.getMessage().getAuthor().getIdLong());
ban.setModName(ctx.getMessage().getAuthor().getName()); ban.setModName(ctx.getMessage().getAuthor().getName());
ban.setServerId(ctx.getGuild().getIdLong()); ban.setServerId(ctx.getGuild().getIdLong());
ban.setServerName(ctx.getGuild().getName()); ban.setServerName(ctx.getGuild().getName());
SqlDB db = new SqlDB();
db.insertBan(ban, "master_ban_list");
//ctx.getEvent().getGuild().ban(cmdf, 1 , "").submit(); //ctx.getEvent().getGuild().ban(cmdf, 1 , "").submit();
//ctx.getMessage().reply("yes ban"); //ctx.getMessage().reply("yes ban");

View File

@ -23,7 +23,7 @@ public class PandaCmd implements ICommand {
EmbedBuilder eb = new EmbedBuilder(); EmbedBuilder eb = new EmbedBuilder();
ctx.getChannel().sendTyping().queue(); ctx.getChannel().sendTyping().queue();
eb.setImage(url.replace("\"","")); eb.setImage(url.replace("\"",""));
ctx.getChannel().sendMessage(eb.build()).queue(); ctx.getChannel().sendMessageEmbeds(eb.build()).queue();
} }
@Override @Override

View File

@ -1,7 +1,6 @@
package net.nevet5gi.buzzbot.commands.utils; package net.nevet5gi.buzzbot.commands.utils;
import me.duncte123.botcommons.commands.ICommandContext; import me.duncte123.botcommons.commands.ICommandContext;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
@ -22,11 +21,6 @@ public class CommandContext implements ICommandContext {
this.args = args; this.args = args;
} }
@Override
public Guild getGuild() {
return null;
}
@Override @Override
public GuildMessageReceivedEvent getEvent() { public GuildMessageReceivedEvent getEvent() {
return this.event; return this.event;

View File

@ -0,0 +1,2 @@
package net.nevet5gi.buzzbot.commands.utils;public class ICommandContext {
}

View File

@ -9,8 +9,6 @@ import net.nevet5gi.buzzbot.objects.WarnData;
import java.sql.*; import java.sql.*;
public class SqlDB { public class SqlDB {
//TODO Make this a two way class for reading and writing from db
private Connection connect; private Connection connect;
private Statement statement; private Statement statement;
private ResultSet resultSet; private ResultSet resultSet;
@ -27,7 +25,7 @@ public class SqlDB {
public void insertBan(BanData ban, String table) { public void insertBan(BanData ban, String table) {
try { try {
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() + ")"); statement.executeUpdate("INSERT INTO " + table + " VALUES (default, " + ban.getUserId() + ", '" + ban.getUserName() + "', '" + ban.getDate() + "', '" + ban.getTime() + "', " + ban.getBanType() + ", " + ban.getBanLength() + ", '" + ban.getBanReason() + "', '" + ban.getModName() + "', " + ban.getModId() + ", '" + ban.getServerName() + "', " + ban.getServerId() + ")");
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -37,7 +35,7 @@ public class SqlDB {
public void insertMute(MuteData mute, String table) { public void insertMute(MuteData mute, String table) {
try { try {
statement.executeUpdate("INSERT INTO " + table + " VALUES (default, " + mute.getUserId() + ", '" + mute.getUserName() + "', '" + mute.getUserDiscriminator() + "', '" + mute.getDate() + "', '" + mute.getTime() + "', " + mute.getMuteLength() + ", '" + mute.getMuteReason() + "', '" + mute.getModName() + "', " + mute.getModId() + ", '" + mute.getServerName() + "', " + mute.getServerId() + ")"); statement.executeUpdate("INSERT INTO " + table + " VALUES (default, " + mute.getUserId() + ", '" + mute.getUserName() + "', '" + mute.getDate() + "', '" + mute.getTime() + "', " + mute.getMuteLength() + ", '" + mute.getMuteReason() + "', '" + mute.getModName() + "', " + mute.getModId() + ", '" + mute.getServerName() + "', " + mute.getServerId() + ")");
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -45,7 +43,7 @@ public class SqlDB {
public void insertWarn(WarnData warn, String table) { public void insertWarn(WarnData warn, String table) {
try { try {
statement.executeUpdate("INSERT INTO " + table + " VALUES (default, " + warn.getUserId() + ", '" + warn.getUserName() + "', '" + warn.getUserDiscriminator() + "', '" + warn.getDate() + "', '" + warn.getTime() + "', " + warn.getBanType() + ", " + warn.getBanLength() + ", '" + warn.getBanReason() + "', '" + warn.getModName() + "', " + warn.getModId() + ", '" + warn.getServerName() + "', " + warn.getServerId() + ")"); statement.executeUpdate("INSERT INTO " + table + " VALUES (default, " + warn.getUserId() + ", '" + warn.getUserName() + "', '" + warn.getDate() + "', '" + warn.getTime() + "', " + warn.getBanType() + ", " + warn.getBanLength() + ", '" + warn.getBanReason() + "', '" + warn.getModName() + "', " + warn.getModId() + ", '" + warn.getServerName() + "', " + warn.getServerId() + ")");
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -60,18 +58,17 @@ public class SqlDB {
resultSet = statement.executeQuery("SELECT * FROM " + table + " WHERE userId=" + userId); resultSet = statement.executeQuery("SELECT * FROM " + table + " WHERE userId=" + userId);
while (resultSet.next()) { while (resultSet.next()) {
ban.setUserId(resultSet.getLong("userid")); ban.setUserId(resultSet.getLong("user_id"));
ban.setUserName(resultSet.getString("username")); ban.setUserName(resultSet.getString("user_name"));
ban.setUserDiscriminator(resultSet.getInt("userdiscriminator")); ban.setDate(resultSet.getDate("ban_date"));
ban.setDate(resultSet.getDate("bandate")); ban.setTime(resultSet.getTime("ban_time"));
ban.setTime(resultSet.getTime("bantime")); ban.setBanType(resultSet.getBoolean("ban_type"));
ban.setBanType(resultSet.getBoolean("bantype")); ban.setBanLength(resultSet.getInt("ban_length"));
ban.setBanLength(resultSet.getInt("banlength")); ban.setBanReason(resultSet.getString("ban_reason"));
ban.setBanReason(resultSet.getString("banreason")); ban.setModName(resultSet.getString("mod_name"));
ban.setModName(resultSet.getString("modname")); ban.setModId(resultSet.getLong("mod_id"));
ban.setModId(resultSet.getLong("modid")); ban.setServerName(resultSet.getString("server_name"));
ban.setServerName(resultSet.getString("servername")); ban.setServerId(resultSet.getLong("server_id"));
ban.setServerId(resultSet.getLong("serverid"));
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
@ -89,9 +86,8 @@ public class SqlDB {
resultSet = statement.executeQuery("SELECT * FROM " + table + "WHERE userId=" + userId); resultSet = statement.executeQuery("SELECT * FROM " + table + "WHERE userId=" + userId);
while (resultSet.next()) { while (resultSet.next()) {
mute.setUserId(resultSet.getLong("userid")); mute.setUserId(resultSet.getLong("user_id"));
mute.setUserName(resultSet.getString("username")); mute.setUserName(resultSet.getString("user_name"));
mute.setUserDiscriminator(resultSet.getInt("userdiscriminator"));
//mute.setDate(resultSet.); //mute.setDate(resultSet.);
} }
} catch (SQLException e) { } catch (SQLException e) {
@ -108,9 +104,8 @@ public class SqlDB {
resultSet = statement.executeQuery("SELECT * FROM " + table + "WHERE userId=" + userId); resultSet = statement.executeQuery("SELECT * FROM " + table + "WHERE userId=" + userId);
while (resultSet.next()) { while (resultSet.next()) {
warn.setUserId(resultSet.getLong("userid")); warn.setUserId(resultSet.getLong("user_id"));
warn.setUserName(resultSet.getString("username")); warn.setUserName(resultSet.getString("user_name"));
warn.setUserDiscriminator(resultSet.getInt("userdiscriminator"));
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
@ -121,7 +116,7 @@ public class SqlDB {
public void addGuild(GuildData guild) { public void addGuild(GuildData guild) {
try { try {
statement.executeUpdate("INSERT INTO guild_settings VALUES (\"" + guild.getName() + "\", " + guild.getId() + ", \"" + guild.getGroup() + "\", " + guild.getProfanityLevel() + ")"); statement.executeUpdate("INSERT INTO guild_settings VALUES ('" + guild.getName() + "', " + guild.getId() + ", '" + guild.getGroup() + "', " + guild.getProfanityLevel() + ")");
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -10,8 +10,8 @@ public class BanData extends UserData {
public BanData() {} 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) { public BanData(long userId, String userName, 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); super(userId, userName, date, time, modName, modId, serverName, serverId);
this.banType = banType; this.banType = banType;
this.banLength = banLength; this.banLength = banLength;
this.banReason = banReason; this.banReason = banReason;

View File

@ -9,8 +9,8 @@ public class MuteData extends UserData {
public MuteData() {} 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) { public MuteData(long userId, String userName, 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); super(userId, userName, date, time, modName, modId, serverName, serverId);
this.muteLength = muteLength; this.muteLength = muteLength;
this.muteReason = muteReason; this.muteReason = muteReason;
} }

View File

@ -6,10 +6,8 @@ import java.time.LocalDate;
import java.time.LocalTime; import java.time.LocalTime;
public class UserData { public class UserData {
private String name = "users";
private long userId; private long userId;
private String userName; private String userName;
private int userDiscriminator;
private Date date = Date.valueOf(LocalDate.now()); private Date date = Date.valueOf(LocalDate.now());
private Time time = Time.valueOf(LocalTime.now()); private Time time = Time.valueOf(LocalTime.now());
private String modName; private String modName;
@ -19,10 +17,9 @@ public class UserData {
public UserData() {} public UserData() {}
public UserData(long userId, String userName, int userDiscriminator, Date date, Time time, String modName, long modId, String serverName, long serverId) { public UserData(long userId, String userName, Date date, Time time, String modName, long modId, String serverName, long serverId) {
this.setUserId(userId); this.setUserId(userId);
this.setUserName(userName); this.setUserName(userName);
this.setUserDiscriminator(userDiscriminator);
this.setDate(date); this.setDate(date);
this.setTime(time); this.setTime(time);
this.setModName(modName); this.setModName(modName);
@ -31,10 +28,6 @@ public class UserData {
this.setServerId(serverId); this.setServerId(serverId);
} }
public String getName() {
return name;
}
public void setUserId(long userId) { public void setUserId(long userId) {
this.userId = userId; this.userId = userId;
} }
@ -51,14 +44,6 @@ public class UserData {
return userName; return userName;
} }
public void setUserDiscriminator(int userDiscriminator) {
this.userDiscriminator = userDiscriminator;
}
public int getUserDiscriminator() {
return userDiscriminator;
}
public void setDate(Date date) { public void setDate(Date date) {
this.date = date; this.date = date;
} }

View File

@ -10,8 +10,8 @@ public class WarnData extends UserData {
public WarnData() {} 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) { public WarnData(long userId, String userName, 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); super(userId, userName, date, time, modName, modId, serverName, serverId);
this.banType = banType; this.banType = banType;
this.banLength = banLength; this.banLength = banLength;
this.banReason = banReason; this.banReason = banReason;

View File

@ -11,20 +11,20 @@ import java.util.ArrayList;
public class JsonUtils <T extends UserData> { public class JsonUtils <T extends UserData> {
T object; T object;
public void createJson(T object) { // public void createJson(T object) {
try { // try {
Writer writer = new FileWriter("./" + object.getName() + ".json"); // Writer writer = new FileWriter("./" + object.getName() + ".json");
//
GsonBuilder builder = new GsonBuilder(); // GsonBuilder builder = new GsonBuilder();
builder.setPrettyPrinting(); // builder.setPrettyPrinting();
Gson gson = builder.create(); // Gson gson = builder.create();
String jsonString = gson.toJson(object); // String jsonString = gson.toJson(object);
writer.write(jsonString); // writer.write(jsonString);
writer.close(); // writer.close();
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
} // }
public T loadJson(String jsonFileName) { public T loadJson(String jsonFileName) {
try { try {