Minor update
This commit is contained in:
parent
19b52eaead
commit
62ea316e07
@ -7,7 +7,7 @@ plugins {
|
|||||||
mainClassName = 'net.nevet5.buzzbot.Bot'
|
mainClassName = 'net.nevet5.buzzbot.Bot'
|
||||||
|
|
||||||
group 'net.nevet5'
|
group 'net.nevet5'
|
||||||
version '0.1.0'
|
version '0.2.0'
|
||||||
def jdaVer = '4.4.0_350'
|
def jdaVer = '4.4.0_350'
|
||||||
|
|
||||||
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17
|
||||||
|
@ -3,8 +3,6 @@ package net.nevet5.buzzbot;
|
|||||||
import org.simpleyaml.configuration.file.YamlFile;
|
import org.simpleyaml.configuration.file.YamlFile;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Config {
|
public class Config {
|
||||||
private static final YamlFile YML_FILE = new YamlFile("./config.yml");
|
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.activity", "playing");
|
||||||
YML_FILE.addDefault("bot.action", "with myself");
|
YML_FILE.addDefault("bot.action", "with myself");
|
||||||
YML_FILE.addDefault("database.url", "localhost");
|
YML_FILE.addDefault("database.url", "localhost");
|
||||||
|
YML_FILE.addDefault("database.database", "buzzbot");
|
||||||
YML_FILE.addDefault("database.user", "barry");
|
YML_FILE.addDefault("database.user", "barry");
|
||||||
YML_FILE.addDefault("database.password", "benson");
|
YML_FILE.addDefault("database.password", "benson");
|
||||||
YML_FILE.addDefault("database.database", "buzzbot");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
YML_FILE.save();
|
YML_FILE.save();
|
||||||
|
@ -1,9 +1,19 @@
|
|||||||
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;
|
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();
|
||||||
|
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
79
src/main/java/net/nevet5/buzzbot/commands/BanCmd.java
Normal file
79
src/main/java/net/nevet5/buzzbot/commands/BanCmd.java
Normal 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";
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +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.HelpCmd;
|
import net.nevet5.buzzbot.commands.HelpCmd;
|
||||||
import net.nevet5.buzzbot.commands.PandaCmd;
|
import net.nevet5.buzzbot.commands.PandaCmd;
|
||||||
import net.nevet5.buzzbot.commands.PingCmd;
|
import net.nevet5.buzzbot.commands.PingCmd;
|
||||||
@ -17,6 +18,7 @@ public class CommandManager {
|
|||||||
|
|
||||||
public CommandManager() {
|
public CommandManager() {
|
||||||
//Add to this list in alphabetical order
|
//Add to this list in alphabetical order
|
||||||
|
addCommand(new BanCmd());
|
||||||
addCommand(new HelpCmd(this));
|
addCommand(new HelpCmd(this));
|
||||||
addCommand(new PandaCmd());
|
addCommand(new PandaCmd());
|
||||||
addCommand(new PingCmd());
|
addCommand(new PingCmd());
|
||||||
|
@ -9,18 +9,18 @@ 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 int userId;
|
private long userId;
|
||||||
private String userName;
|
private String userName;
|
||||||
private int userDiscriminator;
|
private int userDiscriminator;
|
||||||
private String date = LocalDate.now().toString();
|
private Date date = Date.valueOf(LocalDate.now());
|
||||||
private String time = LocalTime.now().toString().split("\\.")[0];
|
private Time time = Time.valueOf(LocalTime.now());
|
||||||
private boolean banType;
|
private boolean banType;
|
||||||
private int banLength;
|
private int banLength;
|
||||||
private String banReason;
|
private String banReason;
|
||||||
private String modName;
|
private String modName;
|
||||||
private int modId;
|
private long modId;
|
||||||
private String serverName;
|
private String serverName;
|
||||||
private int serverId;
|
private long serverId;
|
||||||
|
|
||||||
private Connection connect;
|
private Connection connect;
|
||||||
private Statement statement;
|
private Statement statement;
|
||||||
@ -31,7 +31,6 @@ public class 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") + "?user=" + Config.getConfig().getString("database.user") + "&password=" + Config.getConfig().getString("database.password"));
|
||||||
statement = connect.createStatement();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
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()) {
|
while (resultSet.next()) {
|
||||||
userId = resultSet.getInt("userid");
|
userId = resultSet.getLong("userid");
|
||||||
userName = resultSet.getString("username");
|
userName = resultSet.getString("username");
|
||||||
userDiscriminator = resultSet.getInt("userdiscriminator");
|
userDiscriminator = resultSet.getInt("userdiscriminator");
|
||||||
// date;
|
date = resultSet.getDate("bandate");
|
||||||
// time;
|
time = resultSet.getTime("bantime");
|
||||||
// banType;
|
banType = resultSet.getBoolean("bantype");
|
||||||
// banLength;
|
banLength = resultSet.getInt("");
|
||||||
// banReason;
|
banReason = resultSet.getString("banreason");
|
||||||
// modName;
|
modName = resultSet.getString("modname");
|
||||||
// modId;
|
modId = resultSet.getLong("modid");
|
||||||
// serverName;
|
serverName = resultSet.getString("servername");
|
||||||
// serverId;
|
serverId = resultSet.getLong("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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
this.userId = userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUserId() {
|
public long getUserId() {
|
||||||
return userId;
|
return userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,19 +135,19 @@ public class SqlDB {
|
|||||||
return userDiscriminator;
|
return userDiscriminator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDate(String date) {
|
public void setDate(Date date) {
|
||||||
this.date = date;
|
this.date = date;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDate() {
|
public Date getDate() {
|
||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTime(String time) {
|
public void setTime(Time time) {
|
||||||
this.time = time;
|
this.time = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTime() {
|
public Time getTime() {
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,11 +183,11 @@ public class SqlDB {
|
|||||||
return modName;
|
return modName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setModId(int modId) {
|
public void setModId(long modId) {
|
||||||
this.modId = modId;
|
this.modId = modId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getModId() {
|
public long getModId() {
|
||||||
return modId;
|
return modId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,11 +199,11 @@ public class SqlDB {
|
|||||||
return serverName;
|
return serverName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setServerId(int serverId) {
|
public void setServerId(long serverId) {
|
||||||
this.serverId = serverId;
|
this.serverId = serverId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getServerId() {
|
public long getServerId() {
|
||||||
return serverId;
|
return serverId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user