Minor update

This commit is contained in:
Steven Tracey 2022-04-25 22:40:42 -04:00
parent 19b52eaead
commit 62ea316e07
6 changed files with 153 additions and 43 deletions

View File

@ -7,7 +7,7 @@ plugins {
mainClassName = 'net.nevet5.buzzbot.Bot'
group 'net.nevet5'
version '0.1.0'
version '0.2.0'
def jdaVer = '4.4.0_350'
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17

View File

@ -3,8 +3,6 @@ package net.nevet5.buzzbot;
import org.simpleyaml.configuration.file.YamlFile;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Config {
private static final YamlFile YML_FILE = new YamlFile("./config.yml");
@ -32,9 +30,9 @@ public class Config {
YML_FILE.addDefault("bot.activity", "playing");
YML_FILE.addDefault("bot.action", "with myself");
YML_FILE.addDefault("database.url", "localhost");
YML_FILE.addDefault("database.database", "buzzbot");
YML_FILE.addDefault("database.user", "barry");
YML_FILE.addDefault("database.password", "benson");
YML_FILE.addDefault("database.database", "buzzbot");
try {
YML_FILE.save();

View File

@ -1,9 +1,19 @@
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 static void main(String[] args) {
//TODO Fix This
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();
}
}

View File

@ -0,0 +1,79 @@
package net.nevet5.buzzbot.commands;
import net.nevet5.buzzbot.commands.utils.CommandContext;
import net.nevet5.buzzbot.commands.utils.ICommand;
import java.util.List;
public class BanCmd implements ICommand {
@Override
public void handle(CommandContext ctx) {
//TODO Add checks for commands so they dont break the bot
//TODO Get username and discriminator of person banned and mod
//TODO DM Person who was banned with info about ban
//TODO Make bans able to be modified by original banner only
String userName;
long userId;
long banLength;
String banReason;
List<String> args = ctx.getArgs();
if (args.size() < 3) {
ctx.getChannel().sendMessage("Not enough arguments, please try again").queue();
return;
}
if (args.get(0).contains("<@")) {
userId = Long.parseLong(args.get(0).replace("<","").replace("@","").replace("&","").replace(">",""));
} else {
userId = Long.parseLong(args.get(0));
}
if (args.get(1).contains("perm")) {
banLength = 0;
} else if (args.get(1).contains("h")) {
banLength = Long.parseLong(args.get(1).replace("h",""));
} else if (args.get(1).contains("d")) {
banLength = Long.parseLong(args.get(1).replace("d","")) * 24;
} else if (args.get(1).contains("w")) {
banLength = Long.parseLong(args.get(1).replace("w","")) * 24 * 7;
} else if (args.get(1).contains("m")) {
banLength = Long.parseLong(args.get(1).replace("m", "")) * 24 * 30;
} else if (args.get(1).contains("y")) {
banLength = Long.parseLong(args.get(1).replace("y","")) * 24 * 365;
} else {
return;
}
StringBuilder sb = new StringBuilder();
if (args.size() >= 2) {
for (int i = 2; i < args.size(); i++) {
sb.append(args.get(i));
sb.append(" ");
}
}
banReason = sb.toString().trim();
if (banLength == 0) {
ctx.getChannel().sendMessage("<@" + ctx.getMessage().getAuthor().getId() + "> permanently banned <@" + userId + ">. Reason: " + banReason).queue();
} else {
ctx.getChannel().sendMessage("<@" + ctx.getMessage().getAuthor().getId() + "> banned <@" + userId + "> for " + banLength + " hours. Reason: " + banReason).queue();
}
//ctx.getEvent().getGuild().ban(cmdf, 1 , "").submit();
//ctx.getMessage().reply("yes ban");
}
@Override
public String getName() {
return "ban";
}
@Override
public String getHelp() {
return "Bans the specified user";
}
}

View File

@ -2,6 +2,7 @@ package net.nevet5.buzzbot.commands.utils;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.nevet5.buzzbot.Config;
import net.nevet5.buzzbot.commands.BanCmd;
import net.nevet5.buzzbot.commands.HelpCmd;
import net.nevet5.buzzbot.commands.PandaCmd;
import net.nevet5.buzzbot.commands.PingCmd;
@ -17,6 +18,7 @@ public class CommandManager {
public CommandManager() {
//Add to this list in alphabetical order
addCommand(new BanCmd());
addCommand(new HelpCmd(this));
addCommand(new PandaCmd());
addCommand(new PingCmd());

View File

@ -8,19 +8,19 @@ import java.time.LocalTime;
public class SqlDB {
//TODO Make this a two way class for reading and writing from db
private int userId;
private long userId;
private String userName;
private int userDiscriminator;
private String date = LocalDate.now().toString();
private String time = LocalTime.now().toString().split("\\.")[0];
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 int modId;
private long modId;
private String serverName;
private int serverId;
private long serverId;
private Connection connect;
private Statement statement;
@ -31,7 +31,6 @@ public class SqlDB {
try {
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"));
statement = connect.createStatement();
} catch (Exception e) {
e.printStackTrace();
}
@ -62,39 +61,61 @@ public class SqlDB {
}
}
private void writeResultSet(ResultSet resultSet) throws SQLException {
private void query(ResultSet resultSet) throws SQLException {
while (resultSet.next()) {
userId = resultSet.getInt("userid");
userId = resultSet.getLong("userid");
userName = resultSet.getString("username");
userDiscriminator = resultSet.getInt("userdiscriminator");
// date;
// time;
// banType;
// banLength;
// banReason;
// modName;
// modId;
// serverName;
// serverId;
String user = resultSet.getString("myuser");
String website = resultSet.getString("webpage");
String summary = resultSet.getString("summary");
Date date = resultSet.getDate("datum");
String comment = resultSet.getString("comments");
System.out.println("User: " + user);
System.out.println("Website: " + website);
System.out.println("summary: " + summary);
System.out.println("Date: " + date);
System.out.println("Comment: " + comment);
date = resultSet.getDate("bandate");
time = resultSet.getTime("bantime");
banType = resultSet.getBoolean("bantype");
banLength = resultSet.getInt("");
banReason = resultSet.getString("banreason");
modName = resultSet.getString("modname");
modId = resultSet.getLong("modid");
serverName = resultSet.getString("servername");
serverId = resultSet.getLong("serverid");
}
}
public void setUserId(int userId) {
private void close() {
try {
if (resultSet != null) {
resultSet.close();
}
if (statement != null) {
statement.close();
}
if (connect != null) {
connect.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
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 int getUserId() {
public long getUserId() {
return userId;
}
@ -114,19 +135,19 @@ public class SqlDB {
return userDiscriminator;
}
public void setDate(String date) {
public void setDate(Date date) {
this.date = date;
}
public String getDate() {
public Date getDate() {
return date;
}
public void setTime(String time) {
public void setTime(Time time) {
this.time = time;
}
public String getTime() {
public Time getTime() {
return time;
}
@ -162,11 +183,11 @@ public class SqlDB {
return modName;
}
public void setModId(int modId) {
public void setModId(long modId) {
this.modId = modId;
}
public int getModId() {
public long getModId() {
return modId;
}
@ -178,11 +199,11 @@ public class SqlDB {
return serverName;
}
public void setServerId(int serverId) {
public void setServerId(long serverId) {
this.serverId = serverId;
}
public int getServerId() {
public long getServerId() {
return serverId;
}
}