fixed db and reworked bans
This commit is contained in:
		
							parent
							
								
									f82a8988f9
								
							
						
					
					
						commit
						6f87ef3a5e
					
				@ -30,6 +30,7 @@ public class Bot {
 | 
			
		||||
                    .build();
 | 
			
		||||
            CommandManager.registerSlashCommands();
 | 
			
		||||
            getActivity();
 | 
			
		||||
            LOGGER.info("BuzzBot finished loading!");
 | 
			
		||||
        } catch (LoginException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -18,16 +18,10 @@ public class Test {
 | 
			
		||||
    private static JDA jda;
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
        Config.loadConfig();
 | 
			
		||||
        initJda();
 | 
			
		||||
 | 
			
		||||
        SqlDB sql = new SqlDB();
 | 
			
		||||
        GuildData guild = new GuildData();
 | 
			
		||||
        jda.retrieveUserById(712116155388526693L).queue(user -> { System.out.println(Integer.parseInt(user.getDiscriminator())); });
 | 
			
		||||
 | 
			
		||||
        guild.setName("DevHQ");
 | 
			
		||||
        guild.setId(824071914673668138L);
 | 
			
		||||
        guild.setGroup("developer");
 | 
			
		||||
        guild.setProfanityLevel(3);
 | 
			
		||||
 | 
			
		||||
        sql.addGuild(guild);
 | 
			
		||||
 | 
			
		||||
        //sqlTest();
 | 
			
		||||
    }
 | 
			
		||||
@ -51,7 +45,7 @@ public class Test {
 | 
			
		||||
 | 
			
		||||
    private static void sqlTest() {
 | 
			
		||||
        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");
 | 
			
		||||
 | 
			
		||||
        SqlDB db2 = new SqlDB();
 | 
			
		||||
 | 
			
		||||
@ -3,6 +3,7 @@ package net.nevet5gi.buzzbot.commands;
 | 
			
		||||
import net.nevet5gi.buzzbot.Bot;
 | 
			
		||||
import net.nevet5gi.buzzbot.commands.utils.CommandContext;
 | 
			
		||||
import net.nevet5gi.buzzbot.commands.utils.ICommand;
 | 
			
		||||
import net.nevet5gi.buzzbot.database.SqlDB;
 | 
			
		||||
import net.nevet5gi.buzzbot.objects.BanData;
 | 
			
		||||
 | 
			
		||||
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.setUserDiscriminator(Integer.parseInt(user.getDiscriminator())); });
 | 
			
		||||
        ban.setModId(ctx.getMessage().getAuthor().getIdLong());
 | 
			
		||||
        ban.setModName(ctx.getMessage().getAuthor().getName());
 | 
			
		||||
        ban.setServerId(ctx.getGuild().getIdLong());
 | 
			
		||||
        ban.setServerName(ctx.getGuild().getName());
 | 
			
		||||
 | 
			
		||||
        SqlDB db = new SqlDB();
 | 
			
		||||
        db.insertBan(ban, "master_ban_list");
 | 
			
		||||
 | 
			
		||||
        //ctx.getEvent().getGuild().ban(cmdf, 1 , "").submit();
 | 
			
		||||
        //ctx.getMessage().reply("yes ban");
 | 
			
		||||
 | 
			
		||||
@ -23,7 +23,7 @@ public class PandaCmd implements ICommand {
 | 
			
		||||
        EmbedBuilder eb = new EmbedBuilder();
 | 
			
		||||
        ctx.getChannel().sendTyping().queue();
 | 
			
		||||
        eb.setImage(url.replace("\"",""));
 | 
			
		||||
        ctx.getChannel().sendMessage(eb.build()).queue();
 | 
			
		||||
        ctx.getChannel().sendMessageEmbeds(eb.build()).queue();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,6 @@
 | 
			
		||||
package net.nevet5gi.buzzbot.commands.utils;
 | 
			
		||||
 | 
			
		||||
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.message.guild.GuildMessageReceivedEvent;
 | 
			
		||||
 | 
			
		||||
@ -22,11 +21,6 @@ public class CommandContext implements ICommandContext {
 | 
			
		||||
        this.args = args;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Guild getGuild() {
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public GuildMessageReceivedEvent getEvent() {
 | 
			
		||||
        return this.event;
 | 
			
		||||
 | 
			
		||||
@ -9,8 +9,6 @@ import net.nevet5gi.buzzbot.objects.WarnData;
 | 
			
		||||
import java.sql.*;
 | 
			
		||||
 | 
			
		||||
public class SqlDB {
 | 
			
		||||
    //TODO Make this a two way class for reading and writing from db
 | 
			
		||||
 | 
			
		||||
    private Connection connect;
 | 
			
		||||
    private Statement statement;
 | 
			
		||||
    private ResultSet resultSet;
 | 
			
		||||
@ -27,7 +25,7 @@ public class SqlDB {
 | 
			
		||||
 | 
			
		||||
    public void insertBan(BanData ban, String table) {
 | 
			
		||||
        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) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
@ -37,7 +35,7 @@ public class SqlDB {
 | 
			
		||||
 | 
			
		||||
    public void insertMute(MuteData mute, String table) {
 | 
			
		||||
        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) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
@ -45,7 +43,7 @@ public class SqlDB {
 | 
			
		||||
 | 
			
		||||
    public void insertWarn(WarnData warn, String table) {
 | 
			
		||||
        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) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
@ -60,18 +58,17 @@ public class SqlDB {
 | 
			
		||||
            resultSet = statement.executeQuery("SELECT * FROM " + table + " WHERE userId=" + userId);
 | 
			
		||||
 | 
			
		||||
            while (resultSet.next()) {
 | 
			
		||||
                ban.setUserId(resultSet.getLong("userid"));
 | 
			
		||||
                ban.setUserName(resultSet.getString("username"));
 | 
			
		||||
                ban.setUserDiscriminator(resultSet.getInt("userdiscriminator"));
 | 
			
		||||
                ban.setDate(resultSet.getDate("bandate"));
 | 
			
		||||
                ban.setTime(resultSet.getTime("bantime"));
 | 
			
		||||
                ban.setBanType(resultSet.getBoolean("bantype"));
 | 
			
		||||
                ban.setBanLength(resultSet.getInt("banlength"));
 | 
			
		||||
                ban.setBanReason(resultSet.getString("banreason"));
 | 
			
		||||
                ban.setModName(resultSet.getString("modname"));
 | 
			
		||||
                ban.setModId(resultSet.getLong("modid"));
 | 
			
		||||
                ban.setServerName(resultSet.getString("servername"));
 | 
			
		||||
                ban.setServerId(resultSet.getLong("serverid"));
 | 
			
		||||
                ban.setUserId(resultSet.getLong("user_id"));
 | 
			
		||||
                ban.setUserName(resultSet.getString("user_name"));
 | 
			
		||||
                ban.setDate(resultSet.getDate("ban_date"));
 | 
			
		||||
                ban.setTime(resultSet.getTime("ban_time"));
 | 
			
		||||
                ban.setBanType(resultSet.getBoolean("ban_type"));
 | 
			
		||||
                ban.setBanLength(resultSet.getInt("ban_length"));
 | 
			
		||||
                ban.setBanReason(resultSet.getString("ban_reason"));
 | 
			
		||||
                ban.setModName(resultSet.getString("mod_name"));
 | 
			
		||||
                ban.setModId(resultSet.getLong("mod_id"));
 | 
			
		||||
                ban.setServerName(resultSet.getString("server_name"));
 | 
			
		||||
                ban.setServerId(resultSet.getLong("server_id"));
 | 
			
		||||
            }
 | 
			
		||||
        } catch (SQLException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
@ -89,9 +86,8 @@ public class SqlDB {
 | 
			
		||||
            resultSet = statement.executeQuery("SELECT * FROM " + table + "WHERE userId=" + userId);
 | 
			
		||||
 | 
			
		||||
            while (resultSet.next()) {
 | 
			
		||||
                mute.setUserId(resultSet.getLong("userid"));
 | 
			
		||||
                mute.setUserName(resultSet.getString("username"));
 | 
			
		||||
                mute.setUserDiscriminator(resultSet.getInt("userdiscriminator"));
 | 
			
		||||
                mute.setUserId(resultSet.getLong("user_id"));
 | 
			
		||||
                mute.setUserName(resultSet.getString("user_name"));
 | 
			
		||||
                //mute.setDate(resultSet.);
 | 
			
		||||
            }
 | 
			
		||||
        } catch (SQLException e) {
 | 
			
		||||
@ -108,9 +104,8 @@ public class SqlDB {
 | 
			
		||||
            resultSet = statement.executeQuery("SELECT * FROM " + table + "WHERE userId=" + userId);
 | 
			
		||||
 | 
			
		||||
            while (resultSet.next()) {
 | 
			
		||||
                warn.setUserId(resultSet.getLong("userid"));
 | 
			
		||||
                warn.setUserName(resultSet.getString("username"));
 | 
			
		||||
                warn.setUserDiscriminator(resultSet.getInt("userdiscriminator"));
 | 
			
		||||
                warn.setUserId(resultSet.getLong("user_id"));
 | 
			
		||||
                warn.setUserName(resultSet.getString("user_name"));
 | 
			
		||||
            }
 | 
			
		||||
        } catch (SQLException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
@ -121,7 +116,7 @@ public class SqlDB {
 | 
			
		||||
 | 
			
		||||
    public void addGuild(GuildData guild) {
 | 
			
		||||
        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) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -10,8 +10,8 @@ public class BanData extends UserData {
 | 
			
		||||
 | 
			
		||||
    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);
 | 
			
		||||
    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, date, time, modName, modId, serverName, serverId);
 | 
			
		||||
        this.banType = banType;
 | 
			
		||||
        this.banLength = banLength;
 | 
			
		||||
        this.banReason = banReason;
 | 
			
		||||
 | 
			
		||||
@ -9,8 +9,8 @@ public class MuteData extends UserData {
 | 
			
		||||
 | 
			
		||||
    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);
 | 
			
		||||
    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, date, time, modName, modId, serverName, serverId);
 | 
			
		||||
        this.muteLength = muteLength;
 | 
			
		||||
        this.muteReason = muteReason;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -6,10 +6,8 @@ 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;
 | 
			
		||||
@ -19,10 +17,9 @@ public class 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.setUserName(userName);
 | 
			
		||||
        this.setUserDiscriminator(userDiscriminator);
 | 
			
		||||
        this.setDate(date);
 | 
			
		||||
        this.setTime(time);
 | 
			
		||||
        this.setModName(modName);
 | 
			
		||||
@ -31,10 +28,6 @@ public class UserData {
 | 
			
		||||
        this.setServerId(serverId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getName() {
 | 
			
		||||
        return name;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setUserId(long userId) {
 | 
			
		||||
        this.userId = userId;
 | 
			
		||||
    }
 | 
			
		||||
@ -51,14 +44,6 @@ public class UserData {
 | 
			
		||||
        return userName;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setUserDiscriminator(int userDiscriminator) {
 | 
			
		||||
        this.userDiscriminator = userDiscriminator;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getUserDiscriminator() {
 | 
			
		||||
        return userDiscriminator;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setDate(Date date) {
 | 
			
		||||
        this.date = date;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -10,8 +10,8 @@ public class WarnData extends UserData {
 | 
			
		||||
 | 
			
		||||
    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);
 | 
			
		||||
    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, date, time, modName, modId, serverName, serverId);
 | 
			
		||||
        this.banType = banType;
 | 
			
		||||
        this.banLength = banLength;
 | 
			
		||||
        this.banReason = banReason;
 | 
			
		||||
 | 
			
		||||
@ -11,20 +11,20 @@ import java.util.ArrayList;
 | 
			
		||||
public class JsonUtils <T extends UserData> {
 | 
			
		||||
    T object;
 | 
			
		||||
 | 
			
		||||
    public void createJson(T object) {
 | 
			
		||||
        try {
 | 
			
		||||
            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();
 | 
			
		||||
        } catch (IOException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
//    public void createJson(T object) {
 | 
			
		||||
//        try {
 | 
			
		||||
//            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();
 | 
			
		||||
//        } catch (IOException e) {
 | 
			
		||||
//            e.printStackTrace();
 | 
			
		||||
//        }
 | 
			
		||||
//    }
 | 
			
		||||
 | 
			
		||||
    public T loadJson(String jsonFileName) {
 | 
			
		||||
        try {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user