BotUpload
This commit is contained in:
37
src/main/java/me/lenajenichen/voicebot/CommandManager.java
Normal file
37
src/main/java/me/lenajenichen/voicebot/CommandManager.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package me.lenajenichen.voicebot;
|
||||
|
||||
import me.lenajenichen.voicebot.commands.LockCommand;
|
||||
import me.lenajenichen.voicebot.commands.ServerCommand;
|
||||
import me.lenajenichen.voicebot.commands.SetupCommand;
|
||||
import me.lenajenichen.voicebot.commands.UnlockCommand;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class CommandManager {
|
||||
|
||||
public ConcurrentHashMap<String, ServerCommand> commands;
|
||||
|
||||
public CommandManager() {
|
||||
this.commands = new ConcurrentHashMap<>();
|
||||
|
||||
this.commands.put("unlock", new UnlockCommand());
|
||||
this.commands.put("lock", new LockCommand());
|
||||
this.commands.put("setup", new SetupCommand());
|
||||
}
|
||||
|
||||
public boolean perform(String command, Member m, TextChannel channel, Message message) {
|
||||
|
||||
ServerCommand cmd;
|
||||
if((cmd = this.commands.get(command.toLowerCase())) != null) {
|
||||
cmd.performCommand(m, channel, message);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
28
src/main/java/me/lenajenichen/voicebot/LoggerInit.java
Normal file
28
src/main/java/me/lenajenichen/voicebot/LoggerInit.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package me.lenajenichen.voicebot;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.FileHandler;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.SimpleFormatter;
|
||||
|
||||
public class LoggerInit {
|
||||
|
||||
public static Logger logger = Logger.getLogger("Log");
|
||||
|
||||
public static void initLogger() {
|
||||
FileHandler fh;
|
||||
|
||||
try {
|
||||
fh = new FileHandler("Log.log");
|
||||
logger.addHandler(fh);
|
||||
SimpleFormatter formatter = new SimpleFormatter();
|
||||
fh.setFormatter(formatter);
|
||||
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package me.lenajenichen.voicebot.api;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
public class CreateCaptchaImage {
|
||||
|
||||
private static @NotNull String code = "null";
|
||||
|
||||
public static void create() throws IOException {
|
||||
|
||||
int width = 250;
|
||||
int height = 125;
|
||||
code = Generator.generate();
|
||||
|
||||
// Constructs a BufferedImage of one of the predefined image types.
|
||||
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
// Create a graphics which can be used to draw into the buffered image
|
||||
Graphics2D g2d = bufferedImage.createGraphics();
|
||||
|
||||
g2d.setColor(Color.decode("#3B8EB7"));
|
||||
g2d.fillRect(0, 0, width, height);
|
||||
|
||||
g2d.setColor(Color.decode("#327B9F"));
|
||||
g2d.setFont(new Font("SansSerif", Font.PLAIN, 43));
|
||||
g2d.drawString(code, 65, 75);
|
||||
|
||||
g2d.setColor(Color.black);
|
||||
for(int i = 0; i < 6; i++) {
|
||||
int y1 = (int) Math.round(Math.random() * (90 - (-20) + 1) + 0);
|
||||
int y2 = (int) Math.round(Math.random() * (90 - (-20) + 1) + 0);
|
||||
g2d.drawLine(53, y1, 183, y2);
|
||||
}
|
||||
|
||||
// Save as PNG
|
||||
File file = new File("/var/www/html/images/captcha.png");
|
||||
ImageIO.write(bufferedImage, "png", file);
|
||||
}
|
||||
|
||||
public static @NotNull String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
package me.lenajenichen.voicebot.api;
|
||||
|
||||
import me.lenajenichen.voicebot.mysql.MySQL;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class CreateDescription {
|
||||
|
||||
private static long latestMessageID = 0L;
|
||||
|
||||
public static void createDescriptionMessage(String message, String colorcode, TextChannel channel) {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
builder.setDescription(message);
|
||||
builder.setColor(Color.decode(colorcode));
|
||||
channel.sendMessage(builder.build()).queue();
|
||||
}
|
||||
|
||||
public static void createDescriptionMessageTitle(String message, String colorcode, String title,TextChannel channel) {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
builder.setDescription(message);
|
||||
builder.setColor(Color.decode(colorcode));
|
||||
builder.setTitle(title);
|
||||
channel.sendMessage(builder.build()).queue();
|
||||
}
|
||||
|
||||
public static void createDescriptionImageMessage(String message, String colorcode, TextChannel channel, String url,
|
||||
String name) {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
builder.setDescription(message);
|
||||
builder.setColor(Color.decode(colorcode));
|
||||
builder.setAuthor(name, null, url);
|
||||
channel.sendMessage(builder.build()).queue();
|
||||
}
|
||||
|
||||
public static void createDescriptionImageMessageTitle(String message, String colorcode, TextChannel channel, String url,
|
||||
String name, String title) {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
builder.setDescription(message);
|
||||
builder.setColor(Color.decode(colorcode));
|
||||
builder.setAuthor(name, null, url);
|
||||
builder.setTitle(title);
|
||||
channel.sendMessage(builder.build()).queue();
|
||||
}
|
||||
|
||||
public static void createDescriptionTitleAuthorMessage(String message, String colorcode, TextChannel channel,
|
||||
String url, String Title, String name) {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
builder.setDescription(message);
|
||||
builder.setColor(Color.decode(colorcode));
|
||||
builder.setTitle(Title, url);
|
||||
builder.setAuthor(name, null, url);
|
||||
channel.sendMessage(builder.build()).queue();
|
||||
}
|
||||
|
||||
public static void createDescriptionTitleAuthorMessageFooterSQL(String message, String colorcode, TextChannel channel,
|
||||
String url, String Title, String name, String footer) {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
builder.setDescription(message);
|
||||
builder.setColor(Color.decode(colorcode));
|
||||
builder.setTitle(Title, null);
|
||||
builder.setAuthor(name, null, url);
|
||||
builder.setFooter(footer);
|
||||
channel.sendMessage(builder.build()).queue();
|
||||
MySQL.updateQuery("UPDATE createvoice_captchas SET message_id_teamchat = '" + channel.getLatestMessageId() + "'");
|
||||
}
|
||||
|
||||
public static void createDescriptionTitleMessageFooterSQL(String message, String colorcode, TextChannel channel,
|
||||
String Title, String name, String footer) {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
builder.setDescription(message);
|
||||
builder.setColor(Color.decode(colorcode));
|
||||
builder.setTitle(Title, null);
|
||||
builder.setAuthor(name, null);
|
||||
builder.setFooter(footer);
|
||||
channel.sendMessage(builder.build()).queue();
|
||||
MySQL.updateQuery("UPDATE createvoice_captchas SET message_id_teamchat = '" + channel.getLatestMessageId() + "'");
|
||||
}
|
||||
|
||||
public static void createDescriptionTitleAuthorMessageFooter(String message, String colorcode, TextChannel channel,
|
||||
String url, String Title, String name, String footer) {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
builder.setDescription(message);
|
||||
builder.setColor(Color.decode(colorcode));
|
||||
builder.setTitle(Title, null);
|
||||
builder.setAuthor(name, null, url);
|
||||
builder.setFooter(footer);
|
||||
channel.sendMessage(builder.build()).queue();
|
||||
}
|
||||
|
||||
public static void createDescriptionPrivateMemberURL(Member m, String message, String colorcode, String name, String url) {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
builder.setDescription(message);
|
||||
builder.setColor(Color.decode(colorcode));
|
||||
builder.setAuthor(name, null, url);
|
||||
m.getUser().openPrivateChannel().queue(channel -> {
|
||||
channel.sendMessage(builder.build()).queue();
|
||||
});
|
||||
}
|
||||
|
||||
public static void createDescriptionPrivateMemberMessageTitle(Member m, String message, String colorcode, String title, String imageURL) {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
builder.setDescription(message);
|
||||
builder.setColor(Color.decode(colorcode));
|
||||
builder.setTitle(title);
|
||||
builder.setImage(imageURL);
|
||||
m.getUser().openPrivateChannel().queue(channel -> {
|
||||
channel.sendMessage(builder.build()).queue();
|
||||
latestMessageID = channel.getLatestMessageIdLong();
|
||||
});
|
||||
ResultSet getUserID = MySQL.queryMySQL("SELECT user_id FROM createvoice_captchas WHERE user_id = '" + m.getUser().getId() + "'");
|
||||
try {
|
||||
if (getUserID.next()) {
|
||||
ResultSet getKicks = MySQL.queryMySQL("SELECT kicks FROM createvoice_captchas WHERE user_id = '" + m.getUser().getId() + "'");
|
||||
if(getKicks.next()) {
|
||||
int kicks = getKicks.getInt("kicks");
|
||||
}
|
||||
} else {
|
||||
MySQL.updateQuery("INSERT INTO createvoice_captchas(guild_id, message_id, message_id_teamchat, user_id, code, attempts, kicks) VALUES('" + " " + "', '" + latestMessageID + "', '" + " " + "', '" + m.getUser().getId() + "', '" + CreateCaptchaImage.getCode() + "', '" + 0 + "', '" + 0 + "')");
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void createDescriptionPrivateMember(Member m, String message, String colorcode, String title) {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
builder.setDescription(message);
|
||||
builder.setColor(Color.decode(colorcode));
|
||||
builder.setTitle(title);
|
||||
m.getUser().openPrivateChannel().queue(channel -> {
|
||||
channel.sendMessage(builder.build()).queue();
|
||||
});
|
||||
}
|
||||
|
||||
public static void createDescriptionPrivateUser(User user, String message, String colorcode, String title) {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
builder.setDescription(message);
|
||||
builder.setColor(Color.decode(colorcode));
|
||||
builder.setTitle(title);
|
||||
user.openPrivateChannel().queue(channel -> {
|
||||
channel.sendMessage(builder.build()).queue();
|
||||
});
|
||||
}
|
||||
|
||||
public static void createDescriptionPrivateUserAll(User user, String message, String colorcode, String url, String name) {
|
||||
EmbedBuilder builder = new EmbedBuilder();
|
||||
builder.setDescription(message);
|
||||
builder.setColor(Color.decode(colorcode));
|
||||
builder.setAuthor(name, null, url);
|
||||
user.openPrivateChannel().queue(channel -> {
|
||||
channel.sendMessage(builder.build()).queue();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
30
src/main/java/me/lenajenichen/voicebot/api/Generator.java
Normal file
30
src/main/java/me/lenajenichen/voicebot/api/Generator.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package me.lenajenichen.voicebot.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class Generator {
|
||||
|
||||
private static final String LOWER = "abcdefghijklmnopqrstuvwxyz";
|
||||
private static final String UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
private static final String DIGITS = "0123456789";
|
||||
private static final String PUNCTUATION = "!$%&/()=?;,.#+*~";
|
||||
|
||||
public static String generate() {
|
||||
StringBuilder code = new StringBuilder(5);
|
||||
Random random = new Random(System.nanoTime());
|
||||
|
||||
List<String> charCategories = new ArrayList<>(4);
|
||||
charCategories.add(LOWER);
|
||||
charCategories.add(UPPER);
|
||||
charCategories.add(DIGITS);
|
||||
charCategories.add(PUNCTUATION);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
String charCategory = charCategories.get(random.nextInt(charCategories.size()));
|
||||
int position = random.nextInt(charCategory.length());
|
||||
code.append(charCategory.charAt(position));
|
||||
}
|
||||
return new String(code);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package me.lenajenichen.voicebot.commands;
|
||||
|
||||
import me.lenajenichen.voicebot.LoggerInit;
|
||||
import me.lenajenichen.voicebot.api.CreateDescription;
|
||||
import me.lenajenichen.voicebot.listener.VoiceListener;
|
||||
import me.lenajenichen.voicebot.mysql.MySQL;
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class LockCommand implements ServerCommand {
|
||||
|
||||
@Override
|
||||
public void performCommand(Member m, TextChannel channel, Message message) {
|
||||
String[] args = message.getContentDisplay().split(" ");
|
||||
|
||||
//.voice 1
|
||||
if(args.length == 2) {
|
||||
Guild guild = m.getGuild();
|
||||
VoiceChannel vc = m.getVoiceState().getChannel();
|
||||
ResultSet getChannelID = MySQL.queryMySQL("SELECT channel_id FROM createvoice_createdchannels WHERE channel_id = '" + vc.getIdLong() + "'");
|
||||
try {
|
||||
if(getChannelID.next()) {
|
||||
ResultSet getMemberID = MySQL.queryMySQL("SELECT user_id FROM createvoice_createdchannels WHERE channel_id = '" + vc.getIdLong() + "'");
|
||||
if(getMemberID.next()) {
|
||||
vc.putPermissionOverride(guild.getPublicRole()).setDeny(Permission.VOICE_CONNECT).queue();
|
||||
CreateDescription.createDescriptionMessage(m.getAsMention() + " dein channel wurde gesperrt!", "#00FF00", channel);
|
||||
} else {
|
||||
CreateDescription.createDescriptionMessage(m.getAsMention() + " das ist nicht dein Channel!","#FF0000", channel);
|
||||
}
|
||||
} else {
|
||||
CreateDescription.createDescriptionMessage(m.getAsMention() + " du besitzt momentan keinen Channel!", "#FF0000", channel);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
LoggerInit.logger.warning(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package me.lenajenichen.voicebot.commands;
|
||||
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
|
||||
public interface ServerCommand {
|
||||
|
||||
void performCommand(Member m, TextChannel channel, Message message);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
package me.lenajenichen.voicebot.commands;
|
||||
|
||||
import me.lenajenichen.voicebot.LoggerInit;
|
||||
import me.lenajenichen.voicebot.api.CreateDescription;
|
||||
import me.lenajenichen.voicebot.main.BotMain;
|
||||
import me.lenajenichen.voicebot.mysql.MySQL;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class SetupCommand implements ServerCommand {
|
||||
|
||||
|
||||
@Override
|
||||
public void performCommand(Member m, TextChannel channel, Message message) {
|
||||
String[] args = message.getContentDisplay().split(" ");
|
||||
|
||||
//.voice setup createchannel
|
||||
if (m.hasPermission(Permission.MANAGE_SERVER)) {
|
||||
if (args.length == 4) {
|
||||
if (args[1].equalsIgnoreCase("setup")) {
|
||||
if (args[2].equalsIgnoreCase("createchannel")) {
|
||||
String channel_id = args[3];
|
||||
ResultSet guildid_exists = MySQL.queryMySQL("SELECT guild_id FROM createvoice_data WHERE guild_id = '" + channel.getGuild().getId() + "'");
|
||||
try {
|
||||
if (guildid_exists.next()) {
|
||||
MySQL.updateQuery("UPDATE createvoice_data SET channel_id = '" + Long.valueOf(channel_id) + "' WHERE guild_id = '" + Long.valueOf(channel.getGuild().getId()) + "'");
|
||||
CreateDescription.createDescriptionMessageTitle("Der Channel für das erstellen von eigenen Channels wurde geupdated!", "#00FF00", "Createchannel wurde geupdated!", channel);
|
||||
} else {
|
||||
MySQL.updateQuery("INSERT INTO createvoice_data(channel_id, guild_id) VALUES('" + Long.valueOf(channel_id) + "', '" + Long.valueOf(channel.getGuild().getId()) + "')");
|
||||
CreateDescription.createDescriptionMessageTitle("Der Channel für das erstellen von eigenen Channels wurde gesetzt!", "#00FF00", "Createchannel wurde erstellt!", channel);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
BotMain.sendErrorMessage(channel);
|
||||
LoggerInit.logger.warning(e.toString());
|
||||
}
|
||||
} else if (args[2].equalsIgnoreCase("ignorechannel")) {
|
||||
String channel_id = args[3];
|
||||
ResultSet ignoredchannelid_exsits = MySQL.queryMySQL("SELECT ignored_channel_id FROM createvoice_setup WHERE ignored_channel_id = '" + Long.valueOf(channel_id) + "'");
|
||||
try {
|
||||
if (ignoredchannelid_exsits.next()) {
|
||||
CreateDescription.createDescriptionMessageTitle("Dieser channel ist Bereits in der Ignoerierten Liste! \nWenn du den channel entfernen möchtest schreibe `.voice setup removeignoredchannel <channel_id>`.\n Falls du wissen möchtest welche channel bereits in der Liste sind tippe `.voice setup ignoredchannelslist`", "#FF0000", "Channel existiert bereits!", channel);
|
||||
} else {
|
||||
MySQL.updateQuery("INSERT INTO createvoice_setup(guild_id, ignored_channel_id, channel_name) VALUES('" + Long.valueOf(channel.getGuild().getId()) + "', '" + Long.valueOf(channel_id) + "', '" + channel.getGuild().getJDA().getTextChannelById(channel_id).getName() + "')");
|
||||
CreateDescription.createDescriptionMessageTitle("Der channel wurde hinzugefügt!", "#00FF00", "Liste wurde geupdated!", channel);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
BotMain.sendErrorMessage(channel);
|
||||
LoggerInit.logger.warning(e.toString());
|
||||
}
|
||||
} else if (args[2].equalsIgnoreCase("removeignoredchannel")) {
|
||||
String channel_id = args[3];
|
||||
ResultSet ignoredchannelid_exsits = MySQL.queryMySQL("SELECT ignored_channel_id FROM createvoice_setup WHERE ignored_channel_id = '" + Long.valueOf(channel_id) + "'");
|
||||
try {
|
||||
if (ignoredchannelid_exsits.next()) {
|
||||
MySQL.updateQuery("DELETE FROM createvoice_setup WHERE ignored_channel_id = '" + Long.valueOf(channel_id) + "'");
|
||||
CreateDescription.createDescriptionMessageTitle("Du hast erfolgreich den channel " + channel.getGuild().getJDA().getTextChannelById(channel_id).getAsMention() + " entfernt!", "#00FF00", "Channel erfolgreich entfernt!", channel);
|
||||
} else {
|
||||
CreateDescription.createDescriptionMessageTitle("Dieser channel existier nicht in der Ignoerierten Liste!", "#FF0000", "Channel nicht gefunden!", channel);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
BotMain.sendErrorMessage(channel);
|
||||
LoggerInit.logger.warning(e.toString());
|
||||
}
|
||||
} else if (args[2].equalsIgnoreCase("logchannel")) {
|
||||
String channel_id = args[3];
|
||||
ResultSet logchannel_exists = MySQL.queryMySQL("SELECT channel_id FROM createvoice_logchannel WHERE channel_id = '" + Long.valueOf(channel_id) + "'");
|
||||
try {
|
||||
if (logchannel_exists.next()) {
|
||||
MySQL.updateQuery("UPDATE createvoice_logchannel SET channel_id = '" + Long.valueOf(channel_id) + "', channel_name = '" + channel.getGuild().getJDA().getTextChannelById(channel_id).getName() + "' WHERE guild_id = '" + Long.valueOf(channel.getGuild().getId()) + "'");
|
||||
CreateDescription.createDescriptionMessageTitle("Der Logchannel wurde erfolgreich auf " + channel.getGuild().getJDA().getTextChannelById(channel_id).getAsMention() + " gesetzt!", "#00FF00", "Logchannel Updated!", channel);
|
||||
} else {
|
||||
MySQL.updateQuery("INSERT INTO createvoice_logchannel(guild_id, channel_id, channel_name) VALUES('" + Long.valueOf(channel.getGuild().getId()) + "', '" + Long.valueOf(channel_id) + "', '" + channel.getGuild().getJDA().getTextChannelById(channel_id).getName() + "')");
|
||||
CreateDescription.createDescriptionMessageTitle("Der Logchannel wurde erfolgreich zu " + channel.getGuild().getJDA().getTextChannelById(channel_id).getAsMention() + " gesetzt!", "#00FF00", "Logchannel created!", channel);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
BotMain.sendErrorMessage(channel);
|
||||
LoggerInit.logger.warning(e.toString());
|
||||
}
|
||||
|
||||
} else if (args[2].equalsIgnoreCase("teamchat")) {
|
||||
String channel_id = args[3];
|
||||
ResultSet teamchannelExists = MySQL.queryMySQL("SELECT channel_id FROM createvoice_teamchat WHERE channel_id = '" + Long.valueOf(channel_id) + "'");
|
||||
try {
|
||||
if(teamchannelExists.next()) {
|
||||
MySQL.updateQuery("UPDATE createvoice_teamchat SET channel_id = '" + Long.valueOf(channel_id) + "', channel_name = '" + channel.getGuild().getJDA().getTextChannelById(channel_id).getName() + "'");
|
||||
CreateDescription.createDescriptionMessageTitle("Der Teamchat wurde erfolgreich auf " + channel.getGuild().getJDA().getTextChannelById(channel_id).getAsMention() + " geupdated!", "#00FF00", "Teamchat Updated!", channel);
|
||||
} else {
|
||||
MySQL.updateQuery("INSERT INTO createvoice_teamchat(guild_id, channel_id, channel_name) VALUES('" + channel.getGuild().getId() + "', '" + channel_id + "', '" + channel.getGuild().getJDA().getTextChannelById(channel_id) + "')");
|
||||
CreateDescription.createDescriptionMessageTitle("Der Teamchat wurde erfolgreich zu " + channel.getGuild().getJDA().getTextChannelById(channel_id).getAsMention() + " gesetzt!", "#00FF00", "Teamchat created!", channel);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
channel.sendMessage(message.getMember().getAsMention() + " folgende setup Commands existieren: \n`.voice setup createchannel <channel_id>` um den Channel festzulegen wo der Nutzer ein neuen Channel erstellen kann. \n`.voice setup ignoredchannel <channel_id>` um einen Channel hinzuzufügen wo gelöschte nachrichten nicht geloggt werden. \n`.voice setup removeignorechannel <channel_id>` um einen Channel aus der Ignorierten Liste zu entfernen. \n`.voice setup ignoredchannelslist` zeigt dir die Liste der momentan ignorierten Channel an.").queue();
|
||||
}
|
||||
} else {
|
||||
channel.sendMessage(message.getMember().getAsMention() + " folgende setup Commands existieren: \n`.voice setup createchannel <channel_id>` um den Channel festzulegen wo der Nutzer ein neuen Channel erstellen kann. \n`.voice setup ignoredchannel <channel_id>` um einen Channel hinzuzufügen wo gelöschte nachrichten nicht geloggt werden. \n`.voice setup removeignorechannel <channel_id>` um einen Channel aus der Ignorierten Liste zu entfernen. \n`.voice setup ignoredchannelslist` zeigt dir die Liste der momentan ignorierten Channel an.").queue();
|
||||
}
|
||||
} else if (args.length == 3) {
|
||||
if (args[1].equalsIgnoreCase("setup")) {
|
||||
if (args[2].equalsIgnoreCase("ignoredchannelslist")) {
|
||||
ResultSet getAllIgnoredChannels = MySQL.queryMySQL("SELECT channel_name FROM createvoice_setup WHERE guild_id = '" + Long.valueOf(channel.getGuild().getId()) + "'");
|
||||
try {
|
||||
if(getAllIgnoredChannels.next()) {
|
||||
List<String> channelnames = new ArrayList<>();
|
||||
try {
|
||||
do {
|
||||
String channels = getAllIgnoredChannels.getString("channel_name");
|
||||
channelnames.add(channels);
|
||||
} while (getAllIgnoredChannels.next());
|
||||
CreateDescription.createDescriptionMessageTitle(StringUtils.join(channelnames, ", "), "#00FFFF", "Ignored channel list", channel);
|
||||
} catch (SQLException e1) {
|
||||
LoggerInit.logger.warning(e1.toString());
|
||||
}
|
||||
} else {
|
||||
CreateDescription.createDescriptionMessageTitle("Es wurden keine ignorierten Channel in der Datenbank gefunden. Wenn du welche hinzufügen möchtest tippe einfach `.voice setup ignorechannel <channel_id>`", "#FF0000", "No Ignored channels found", channel);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
LoggerInit.logger.warning(e.toString());
|
||||
}
|
||||
} else {
|
||||
channel.sendMessage(message.getMember().getAsMention() + " folgende setup Commands existieren: \n`.voice setup createchannel <channel_id>` um den Channel festzulegen wo der Nutzer ein neuen Channel erstellen kann. \n`.voice setup ignoredchannel <channel_id>` um einen Channel hinzuzufügen wo gelöschte nachrichten nicht geloggt werden. \n`.voice setup removeignorechannel <channel_id>` um einen Channel aus der Ignorierten Liste zu entfernen. \n`.voice setup ignoredchannelslist` zeigt dir die Liste der momentan ignorierten Channel an.").queue();
|
||||
}
|
||||
} else {
|
||||
channel.sendMessage(message.getMember().getAsMention() + " folgende setup Commands existieren: \n`.voice setup createchannel <channel_id>` um den Channel festzulegen wo der Nutzer ein neuen Channel erstellen kann. \n`.voice setup ignoredchannel <channel_id>` um einen Channel hinzuzufügen wo gelöschte nachrichten nicht geloggt werden. \n`.voice setup removeignorechannel <channel_id>` um einen Channel aus der Ignorierten Liste zu entfernen. \n`.voice setup ignoredchannelslist` zeigt dir die Liste der momentan ignorierten Channel an.").queue();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
channel.sendMessage(message.getMember().getAsMention() + " Dazu hast du keine Rechte!").queue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package me.lenajenichen.voicebot.commands;
|
||||
|
||||
import me.lenajenichen.voicebot.LoggerInit;
|
||||
import me.lenajenichen.voicebot.api.CreateDescription;
|
||||
import me.lenajenichen.voicebot.listener.VoiceListener;
|
||||
import me.lenajenichen.voicebot.mysql.MySQL;
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class UnlockCommand implements ServerCommand{
|
||||
|
||||
@Override
|
||||
public void performCommand(Member m, TextChannel channel, Message message) {
|
||||
String[] args = message.getContentDisplay().split(" ");
|
||||
|
||||
//.voice 1
|
||||
if(args.length == 2) {
|
||||
Guild guild = m.getGuild();
|
||||
VoiceChannel vc = m.getVoiceState().getChannel();
|
||||
ResultSet getChannelID = MySQL.queryMySQL("SELECT channel_id FROM createvoice_createdchannels WHERE channel_id = '" + vc.getIdLong() + "'");
|
||||
try {
|
||||
if(getChannelID.next()) {
|
||||
ResultSet getMemberID = MySQL.queryMySQL("SELECT user_id FROM createvoice_createdchannels WHERE channel_id = '" + vc.getIdLong() + "'");
|
||||
if(getMemberID.next()) {
|
||||
vc.putPermissionOverride(guild.getPublicRole()).setAllow(Permission.VIEW_CHANNEL).queue();
|
||||
CreateDescription.createDescriptionMessage(m.getAsMention() + " dein channel wurde entsperrt!", "#00FF00", channel);
|
||||
} else {
|
||||
CreateDescription.createDescriptionMessage(m.getAsMention() + " das ist nicht dein Channel!","#FF0000", channel);
|
||||
}
|
||||
} else {
|
||||
CreateDescription.createDescriptionMessage(m.getAsMention() + " du besitzt momentan keinen Channel!", "#FF0000", channel);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
LoggerInit.logger.warning(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package me.lenajenichen.voicebot.listener;
|
||||
|
||||
import me.lenajenichen.voicebot.LoggerInit;
|
||||
import me.lenajenichen.voicebot.mysql.MySQL;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.events.user.update.UserUpdateAvatarEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class AvatarUpdate extends ListenerAdapter {
|
||||
|
||||
@Override
|
||||
public void onUserUpdateAvatar(UserUpdateAvatarEvent e) {
|
||||
User user = e.getUser();
|
||||
ResultSet getUser = MySQL.queryMySQL("SELECT user_id FROM createvoice_users WHERE user_id = '" + user.getId() + "'");
|
||||
try {
|
||||
if(getUser.next()) {
|
||||
MySQL.updateQuery("UPDATE createvoice_users SET avatarURL = '" + user.getAvatarUrl() + "'");
|
||||
} else {
|
||||
MySQL.updateQuery("INSERT INTO createvoice_users(user_id, user_name, user_discriminator, avatarURL) VALUES('" + user.getId() + "', '" + user.getName() + "', '" + user.getDiscriminator() + "', '" + user.getAvatarUrl() + "')");
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
LoggerInit.logger.warning(ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package me.lenajenichen.voicebot.listener;
|
||||
|
||||
import me.lenajenichen.voicebot.api.CreateDescription;
|
||||
import me.lenajenichen.voicebot.main.BotMain;
|
||||
import me.lenajenichen.voicebot.mysql.MySQL;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class CaptchaPrivateMessageEvent extends ListenerAdapter {
|
||||
|
||||
@Override
|
||||
public void onPrivateMessageReceived(PrivateMessageReceivedEvent e) {
|
||||
Date date = new Date();
|
||||
String now = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(new Date());
|
||||
if (!e.getAuthor().isBot()) {
|
||||
if (!(e.getAuthor().isBot())) {
|
||||
System.out.println(e.getAuthor().getId());
|
||||
ResultSet getCode = MySQL.queryMySQL("SELECT code FROM createvoice_captchas WHERE user_id = '" + e.getAuthor().getId() + "'");
|
||||
try {
|
||||
if (getCode.next()) {
|
||||
String code = getCode.getString("code");
|
||||
ResultSet getAttempts = MySQL.queryMySQL("SELECT attempts FROM createvoice_captchas WHERE user_id = '" + e.getAuthor().getId() + "'");
|
||||
if (getAttempts.next()) {
|
||||
int attempts = getAttempts.getInt("attempts");
|
||||
if (e.getMessage().getContentDisplay().equals(code)) {
|
||||
ResultSet getGuildID = MySQL.queryMySQL("SELECT guild_id FROM createvoice_captchas WHERE user_id = '" + e.getAuthor().getId() + "'");
|
||||
if (getGuildID.next()) {
|
||||
long guildid = getGuildID.getLong("guild_id");
|
||||
System.out.println(guildid);
|
||||
CreateDescription.createDescriptionPrivateUser(e.getMessage().getPrivateChannel().getUser(), "Du wurdest erfolgreich verifiziert!\nDu kannst nun schreiben und hast zugriff auf alle Channel.", "#00FF00", "Erfolgreich verifiziert!");
|
||||
ResultSet getTeamchat = MySQL.queryMySQL("SELECT channel_id FROM createvoice_teamchat WHERE guild_id = '" + guildid + "'");
|
||||
System.out.println("1");
|
||||
if(getTeamchat.next()) {
|
||||
System.out.println("1");
|
||||
long teamchatid = getTeamchat.getLong("channel_id");
|
||||
ResultSet getAvatarURL = MySQL.queryMySQL("SELECT avatarURL FROM createvoice_users WHERE user_id = '" + e.getMessage().getPrivateChannel().getUser().getId() + "'");
|
||||
if (getAvatarURL.next()) {
|
||||
System.out.println("1");
|
||||
String URL = getAvatarURL.getString("avatarURL");
|
||||
if(URL.equalsIgnoreCase("null")) {
|
||||
System.out.println("1");
|
||||
CreateDescription.createDescriptionTitleAuthorMessageFooter("Der nutzer " + e.getAuthor().getName() + " hat sich erfolgreich Verifiziert!", "#00FF00", e.getJDA().getGuildById(guildid).getTextChannelById(teamchatid), "http://195.90.201.89/images/default_discord_pfp.jpg", "Erfolgreiche verifizierung!", e.getAuthor().getName(), now);
|
||||
} else {
|
||||
System.out.println("2");
|
||||
CreateDescription.createDescriptionTitleAuthorMessageFooter("Der nutzer " + e.getAuthor().getName() + " hat sich erfolgreich Verifiziert!", "#00FF00", e.getJDA().getGuildById(guildid).getTextChannelById(teamchatid), URL, "Erfolgreiche verifizierung!", e.getAuthor().getName(), now);
|
||||
}
|
||||
System.out.println("1");
|
||||
MySQL.updateQuery("DELETE FROM createvoice_captchas WHERE user_id = '" + e.getAuthor().getId() + "'");
|
||||
}
|
||||
} else {
|
||||
System.out.println("4");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
MySQL.updateQuery("UPDATE createvoice_captchas SET attempts = '" + attempts + 1 + "'");
|
||||
if (attempts == 3) {
|
||||
ResultSet getGuildID = MySQL.queryMySQL("SELECT guild_id FROM createvoice_captchas WHERE user_id = '" + e.getAuthor().getId() + "'");
|
||||
if (getGuildID.next()) {
|
||||
long guild_id = getGuildID.getLong("guild_id");
|
||||
BotMain.INSTATNCE.shardManager.getGuildById(guild_id).kick(e.getAuthor().getId());
|
||||
ResultSet getTeamchat = MySQL.queryMySQL("SELECT channel_id FROM createvoice_teamchat WHERE guild_id = '" + guild_id + "'");
|
||||
if (getTeamchat.next()) {
|
||||
long teamchat = getTeamchat.getLong("channel_id");
|
||||
CreateDescription.createDescriptionMessageTitle("Der Nutzer " + e.getAuthor().getName() + " hat es nicht geschafft sich nach 3 Versuchen zu verifizieren. Der Nutzer wurde nun gekickt und hat einen weiteren Versuch", "#FF0000", "Verifizierung gescheitert!", BotMain.INSTATNCE.shardManager.getGuildById(guild_id).getTextChannelById(teamchat));
|
||||
ResultSet getKicks = MySQL.queryMySQL("SELECT kicks FROM createvoice_captchas WHERE user_id = '" + e.getAuthor().getId() + "'");
|
||||
if (getKicks.next()) {
|
||||
int kicks = getKicks.getInt("kicks");
|
||||
MySQL.updateQuery("UDPATE createvoice_captchas SET kicks = '" + kicks+1 + "'");
|
||||
if (kicks == 3) {
|
||||
BotMain.INSTATNCE.shardManager.getGuildById(guild_id).ban(e.getAuthor().getId(), 7, "Du wurdest gebannt da du nach 3 kicks nicht die Verifikation geschafft hast. Wenn etwas schief gelaufen ist dann schreibe uns bitte hier ein Entbannungsantrag: ").queue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ResultSet getGuildID = MySQL.queryMySQL("SELECT guild_id FROM createvoice_captchas WHERE user_id = '" + e.getAuthor().getId() + "'");
|
||||
if (getGuildID.next()) {
|
||||
long guild_id = getGuildID.getLong("guild_id");
|
||||
ResultSet getTeamchat = MySQL.queryMySQL("SELECT channel_id FROM createvoice_teamchat WHERE guild_id = '" + guild_id + "'");
|
||||
if (getTeamchat.next()) {
|
||||
ResultSet getKicks = MySQL.queryMySQL("SELECT kicks FROM createvoice_captchas WHERE user_id = '" + e.getAuthor().getId() + "'");
|
||||
if (getKicks.next()) {
|
||||
ResultSet getTeamChatID = MySQL.queryMySQL("SELECT message_id_teamchat FROM createvoice_captchas WHERE user_id = '" + e.getAuthor().getId() + "'");
|
||||
if (getTeamChatID.next()) {
|
||||
long teamchat_id = getTeamChatID.getLong("message_id_teamchat");
|
||||
int kicks = getKicks.getInt("kicks");
|
||||
long teamchat = getTeamchat.getLong("channel_id");
|
||||
MySQL.updateQuery("UPDATE createvoice_captchas SET kicks = '" + kicks+1 + "' WHERE user_id = '" + e.getAuthor().getId() + "'");
|
||||
BotMain.INSTATNCE.shardManager.getGuildById(guild_id).getTextChannelById(teamchat).editMessageById(teamchat_id, "Es wurde ein neuer Account gefunden. Die Person hat nun eine recaptcha erhalten und wird diese Ausfüllen müssen.\n\nVersuche: " + attempts + "/3 | Kicks: " + kicks + "/3");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package me.lenajenichen.voicebot.listener;
|
||||
|
||||
import me.lenajenichen.voicebot.main.BotMain;
|
||||
import net.dv8tion.jda.api.entities.ChannelType;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
|
||||
public class CommandListener extends ListenerAdapter {
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(MessageReceivedEvent e) {
|
||||
String message = e.getMessage().getContentDisplay();
|
||||
|
||||
if(e.isFromType(ChannelType.TEXT)) {
|
||||
TextChannel channel = e.getTextChannel();
|
||||
|
||||
if(message.startsWith(".voice")) {
|
||||
String[] args = message.substring(1).split(" ");
|
||||
if(args.length > 0) {
|
||||
if(!BotMain.INSTATNCE.getCmdMan().perform(args[1], e.getMember(), channel, e.getMessage())) {
|
||||
channel.sendMessage(e.getMessage().getMember().getAsMention() + " folgende Commands existieren: \n`.voice unlock` um den Channel zu entsperren. \n`.voice lock` um deinen Channel zu sperren.").queue();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package me.lenajenichen.voicebot.listener;
|
||||
|
||||
import me.lenajenichen.voicebot.LoggerInit;
|
||||
import me.lenajenichen.voicebot.api.CreateCaptchaImage;
|
||||
import me.lenajenichen.voicebot.api.CreateDescription;
|
||||
import me.lenajenichen.voicebot.mysql.MySQL;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
|
||||
import net.dv8tion.jda.api.events.guild.member.GuildMemberLeaveEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Year;
|
||||
import java.util.Date;
|
||||
|
||||
public class GuildMemberJoin extends ListenerAdapter {
|
||||
|
||||
@Override
|
||||
public void onGuildMemberJoin(GuildMemberJoinEvent e) {
|
||||
User user = e.getUser();
|
||||
System.out.println("1");
|
||||
ResultSet getUser = MySQL.queryMySQL("SELECT user_id FROM createvoice_users WHERE user_id = '" + user.getId() + "'");
|
||||
ResultSet getUserCaptcha = MySQL.queryMySQL("SELECT user_id FROM createvoice_captchas WHERE user_id = '" + user.getId() + "'");
|
||||
try {
|
||||
System.out.println("1");
|
||||
if (!(getUser.next())) {
|
||||
System.out.println("2");
|
||||
MySQL.updateQuery("INSERT INTO createvoice_users(user_id, user_name, user_discriminator, avatarURL) VALUES('" + user.getId() + "', '" + user.getName() + "', '" + user.getDiscriminator() + "', '" + user.getAvatarUrl() + "')");
|
||||
} else if (!getUserCaptcha.next()) {
|
||||
MySQL.updateQuery("INSERT INTO createvoice_captchas(guild_id, message_id, message_id_teamchat, user_id, code, attempts, kicks) VALUES('" + " " + "', '" + " " + "', '" + " " + "', '" + user.getId() + "', '" + " " + "', '" + 0 + "', '" + 0 + "')");
|
||||
}
|
||||
System.out.println("1");
|
||||
} catch (SQLException ex) {
|
||||
LoggerInit.logger.warning(ex.toString());
|
||||
}
|
||||
System.out.println("1");
|
||||
Date date = new Date();
|
||||
String now = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(new Date());
|
||||
System.out.println("1");
|
||||
int createdyear = e.getUser().getTimeCreated().getYear();
|
||||
int createdmonth = e.getUser().getTimeCreated().getMonthValue();
|
||||
int monthsago = date.getMonth() - createdmonth;
|
||||
if(monthsago <= 1) {
|
||||
System.out.println("3");
|
||||
ResultSet getLogChannel = MySQL.queryMySQL("SELECT channel_id FROM createvoice_teamchat WHERE guild_id = '" + Long.valueOf(e.getGuild().getId()) + "'");
|
||||
try {
|
||||
System.out.println("3");
|
||||
if(getLogChannel.next()) {
|
||||
System.out.println("3");
|
||||
Long logchannel_id = getLogChannel.getLong("channel_id");
|
||||
System.out.println("3");
|
||||
ResultSet getGuildID = MySQL.queryMySQL("SELECT guild_id FROM createvoice_teamchat WHERE channel_id ='" + logchannel_id + "'");
|
||||
if (getGuildID.next()) {
|
||||
System.out.println("3");
|
||||
Long guildID = getGuildID.getLong("guild_id");
|
||||
System.out.println("3");
|
||||
TextChannel logchannel = e.getJDA().getGuildById(guildID).getTextChannelById(logchannel_id);
|
||||
System.out.println("3");
|
||||
ResultSet getAvatarURL = MySQL.queryMySQL("SELECT avatarURL FROM createvoice_users WHERE user_id = '" + user.getId() + "'");
|
||||
if (getAvatarURL.next()) {
|
||||
System.out.println("3");
|
||||
ResultSet getUsername = MySQL.queryMySQL("SELECT user_name FROM createvoice_users WHERE user_id = '" + user.getId() + "'");
|
||||
if (getUsername.next()) {
|
||||
System.out.println("3");
|
||||
ResultSet getKicks = MySQL.queryMySQL("SELECT kicks FROM createvoice_captchas WHERE user_id = '" + user.getId() + "'");
|
||||
if (getKicks.next()) {
|
||||
System.out.println("3");
|
||||
int kicks = getKicks.getInt("kicks");
|
||||
String username = getUsername.getString("user_name");
|
||||
String URL = getAvatarURL.getString("avatarURL");
|
||||
if (URL.equalsIgnoreCase("null")) {
|
||||
System.out.println("3");
|
||||
CreateDescription.createDescriptionTitleAuthorMessageFooterSQL("Es wurde ein neuer Account gefunden. Die Person hat nun eine recaptcha erhalten und wird diese Ausfüllen müssen.\n\nVersuche: 0/3 | Kicks: " + kicks + "/3", "#FFFF00", logchannel, "http://195.90.201.89/images/default_discord_pfp.jpg", "Suspicious account found!", username, now);
|
||||
} else {
|
||||
System.out.println("4");
|
||||
CreateDescription.createDescriptionTitleAuthorMessageFooterSQL("Es wurde ein neuer Account gefunden. Die Person hat nun eine recaptcha erhalten und wird diese Ausfüllen müssen.\n\nVersuche: 0/3 | Kicks: " + kicks + "/3", "#FFFF00", logchannel, URL, "Suspicious account found!", username, now);
|
||||
}
|
||||
System.out.println("3");
|
||||
CreateCaptchaImage.create();
|
||||
CreateDescription.createDescriptionPrivateMemberMessageTitle(e.getMember(), "Wir haben festgestellt das dein Account erst vor kurzem erstellt wurde, um Bot zu verhindern haben wir für neue neu erstellte Discord Account eine recaptcha um sicher zu gehen das es kein Bot ist. Du hast insgesamt 3 Versuche diese recaptcha zu schaffen, schaffst du es nicht wirst du gekickt und du kannst es nocheinmal versuchen. Beim 3ten kick wirst du automatisch gebannt da wir davon ausgehen das du ein Bot bist. Wenn du dies verstanden hast schreibe bitte den unten zu sehenden Code.", "#F6DF13", "Verdächtiger Account", "http://195.90.201.89/images/captcha.png");
|
||||
MySQL.updateQuery("UPDATE createvoice_captchas SET guild_id = '" + e.getGuild().getId() + "', code = '" + CreateCaptchaImage.getCode() + "' WHERE user_id = '" + e.getUser().getId() + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
} catch (IOException ioException) {
|
||||
LoggerInit.logger.warning(ioException.getStackTrace().toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Year year = Year.now().minusYears(createdyear);
|
||||
@SuppressWarnings("deprecation")
|
||||
int month = date.getMonth() - createdmonth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuildMemberLeave(GuildMemberLeaveEvent e) {
|
||||
User user = e.getUser();
|
||||
MySQL.updateQuery("DELETE FROM createvoice_users WHERE user_id = '" + user.getId() + "'");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package me.lenajenichen.voicebot.listener;
|
||||
|
||||
import jdk.nashorn.internal.runtime.regexp.joni.CodeRangeBuffer;
|
||||
import me.lenajenichen.voicebot.LoggerInit;
|
||||
import me.lenajenichen.voicebot.api.CreateDescription;
|
||||
import me.lenajenichen.voicebot.mysql.MySQL;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.events.message.MessageDeleteEvent;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageDeleteEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class MessageDelete extends ListenerAdapter {
|
||||
|
||||
@Override
|
||||
public void onMessageDelete(MessageDeleteEvent e) {
|
||||
HashMap<Integer, Long> getID = new HashMap<>();
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
|
||||
Date date = new Date();
|
||||
String messageid = e.getMessageId();
|
||||
ResultSet getLogChannel = MySQL.queryMySQL("SELECT channel_id FROM createvoice_logchannel WHERE guild_id = '" + Long.valueOf(e.getGuild().getId()) + "'");
|
||||
try {
|
||||
if (getLogChannel.next()) {
|
||||
Long logChannel_id = getLogChannel.getLong("channel_id");
|
||||
ResultSet getGuildID = MySQL.queryMySQL("SELECT guild_id FROM createvoice_logchannel WHERE channel_id ='" + logChannel_id + "'");
|
||||
if (getGuildID.next()) {
|
||||
Long guildid = getGuildID.getLong("guild_id");
|
||||
ResultSet getIgnoredChannels = MySQL.queryMySQL("SELECT ignored_channel_id FROM createvoice_setup WHERE guild_id = '" + Long.valueOf(e.getGuild().getId()) + "'");
|
||||
if (getIgnoredChannels.next()) {
|
||||
List<Long> channel_id = new ArrayList<>();
|
||||
do {
|
||||
Long channelids = getIgnoredChannels.getLong("ignored_channel_id");
|
||||
channel_id.add(channelids);
|
||||
} while (getIgnoredChannels.next());
|
||||
if (!(channel_id.contains(e.getChannel().getId()))) {
|
||||
ResultSet getOldMessage = MySQL.queryMySQL("SELECT message FROM createvoice_messages WHERE message_id = '" + messageid + "'");
|
||||
if (getOldMessage.next()) {
|
||||
ResultSet getUserID = MySQL.queryMySQL("SELECT user_id FROM createvoice_messages WHERE message_id = '" + messageid + "'");
|
||||
if (getUserID.next()) {
|
||||
Long user_id = getUserID.getLong("user_id");
|
||||
ResultSet getAvatarURL = MySQL.queryMySQL("SELECT avatarURL FROM createvoice_users WHERE user_id = '" + user_id + "'");
|
||||
if(getAvatarURL.next()) {
|
||||
String url = getAvatarURL.getString("avatarURL");
|
||||
ResultSet getUsername = MySQL.queryMySQL("SELECT user_name FROM createvoice_users WHERE user_id = '" + user_id + "'");
|
||||
if(getUsername.next()) {
|
||||
String username = getUsername.getString("user_name");
|
||||
String message = getOldMessage.getString("message");
|
||||
TextChannel logchannel = e.getJDA().getGuildById(guildid).getTextChannelById(logChannel_id);
|
||||
CreateDescription.createDescriptionTitleAuthorMessageFooter("**" + message.replace("/*/", "'") + "**", "#FF0000", logchannel, url, "Deleted Message", username, simpleDateFormat.format(date) + " URL: https://discord.com/channels/" + e.getGuild().getId() + "/" + e.getChannel().getId() + "/" + e.getMessageId());
|
||||
} else {
|
||||
System.out.println("1");
|
||||
}
|
||||
} else {
|
||||
System.out.println("2");
|
||||
}
|
||||
} else {
|
||||
System.out.println("3");
|
||||
}
|
||||
} else {
|
||||
System.out.println("4");
|
||||
}
|
||||
} else {
|
||||
System.out.println("5");
|
||||
}
|
||||
} else {
|
||||
System.out.println("6");
|
||||
}
|
||||
} else {
|
||||
System.out.println("7");
|
||||
}
|
||||
} else {
|
||||
System.out.println("8");
|
||||
}
|
||||
} catch (SQLException e1) {
|
||||
LoggerInit.logger.warning(e1.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package me.lenajenichen.voicebot.listener;
|
||||
|
||||
import me.lenajenichen.voicebot.LoggerInit;
|
||||
import me.lenajenichen.voicebot.api.CreateCaptchaImage;
|
||||
import me.lenajenichen.voicebot.api.CreateDescription;
|
||||
import me.lenajenichen.voicebot.mysql.MySQL;
|
||||
import net.dv8tion.jda.api.entities.ChannelType;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.events.message.MessageUpdateEvent;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Year;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class MessageEvent extends ListenerAdapter {
|
||||
|
||||
@Override
|
||||
public void onGuildMessageReceived(GuildMessageReceivedEvent e) {
|
||||
String messageContent = e.getMessage().getContentDisplay().replace("'", "/*/");
|
||||
Long guild_id = e.getGuild().getIdLong();
|
||||
Long message_id = e.getMessageIdLong();
|
||||
String author = e.getMessage().getAuthor().getName();
|
||||
User user = e.getMessage().getMember().getUser();
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
|
||||
Date date = new Date();
|
||||
//Role role = e.getGuild().getRoleById(849635686385975364L);
|
||||
//e.getGuild().removeRoleFromMember(285452141332660226L, role).queue();
|
||||
MySQL.updateQuery("INSERT INTO createvoice_messages(guild_id, message_id, user_id, message, user, date, lastUpdateDate) VALUES('" + guild_id + "', '" + message_id + "', '" + Long.valueOf(e.getMessage().getMember().getId()) + "', '" + messageContent + "', '" + author + "', '" + date + "', '" + " " + "')");
|
||||
ResultSet getUser = MySQL.queryMySQL("SELECT user_id FROM createvoice_users WHERE user_id = '" + user.getId() + "'");
|
||||
try {
|
||||
if (!(getUser.next())) {
|
||||
MySQL.updateQuery("INSERT INTO createvoice_users(user_id, user_name, user_discriminator, avatarURL) VALUES('" + user.getId() + "', '" + user.getName() + "', '" + user.getDiscriminator() + "', '" + user.getAvatarUrl() + "')");
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
LoggerInit.logger.warning(ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuildMessageUpdate(GuildMessageUpdateEvent e) {
|
||||
String newMessageContent = e.getMessage().getContentDisplay().replace("'", "/*/");
|
||||
Long guild_id = e.getGuild().getIdLong();
|
||||
Long message_id = e.getMessageIdLong();
|
||||
String author = e.getMessage().getAuthor().getName();
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
|
||||
Date date = new Date();
|
||||
ResultSet getLogChannel = MySQL.queryMySQL("SELECT channel_id FROM createvoice_logchannel WHERE guild_id = '" + Long.valueOf(e.getGuild().getId()) + "'");
|
||||
if (!e.getAuthor().isBot()) {
|
||||
try {
|
||||
if (getLogChannel.next()) {
|
||||
ResultSet getIgnoredChannels = MySQL.queryMySQL("SELECT ignored_channel_id FROM createvoice_setup WHERE guild_id = '" + Long.valueOf(e.getGuild().getId()) + "'");
|
||||
if (getIgnoredChannels.next()) {
|
||||
List<Long> channel_id = new ArrayList<>();
|
||||
do {
|
||||
Long channelids = getIgnoredChannels.getLong("ignored_channel_id");
|
||||
channel_id.add(channelids);
|
||||
} while (getIgnoredChannels.next());
|
||||
if (!channel_id.contains(e.getChannel().getId())) {
|
||||
ResultSet oldMessageContent = MySQL.queryMySQL("SELECT message FROM createvoice_messages WHERE message_id = '" + message_id + "'");
|
||||
if (oldMessageContent.next()) {
|
||||
String message = oldMessageContent.getString("message");
|
||||
Long logChannel_id = getLogChannel.getLong("channel_id");
|
||||
TextChannel logchannel = e.getJDA().getTextChannelById(logChannel_id);
|
||||
MySQL.updateQuery("UPDATE createvoice_messages SET message ='" + newMessageContent + "', lastUpdateDate = '" + date + "' WHERE message_id ='" + message_id + "'");
|
||||
CreateDescription.createDescriptionTitleAuthorMessageFooter("Before: **" + message.replace("/*/", "'") + "**\n\n After: **" + newMessageContent.replace("/*/", "'") + "**", "#00FFFF", logchannel, e.getMessage().getMember().getUser().getAvatarUrl(), "Message Edited", author, simpleDateFormat.format(date) + " \nhttps://discord.com/channels/" + e.getGuild().getId() + "/" + e.getChannel().getId() + "/" + e.getMessageId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException e1) {
|
||||
LoggerInit.logger.warning(e1.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package me.lenajenichen.voicebot.listener;
|
||||
|
||||
import me.lenajenichen.voicebot.LoggerInit;
|
||||
import me.lenajenichen.voicebot.mysql.MySQL;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.events.user.update.UserUpdateDiscriminatorEvent;
|
||||
import net.dv8tion.jda.api.events.user.update.UserUpdateNameEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class NameUpdate extends ListenerAdapter {
|
||||
|
||||
@Override
|
||||
public void onUserUpdateName(UserUpdateNameEvent e) {
|
||||
User user = e.getUser();
|
||||
ResultSet getUsername = MySQL.queryMySQL("SELECT user_name FROM createvoice_users WHERE user_id = '" + user.getId() + "'");
|
||||
try {
|
||||
if(getUsername.next()) {
|
||||
MySQL.updateQuery("UPDATE createvoice_users SET user_name = '" + user.getName() + "'");
|
||||
} else {
|
||||
MySQL.updateQuery("INSERT INTO createvoice_users(user_id, user_name, user_discriminator, avatarURL) VALUES('" + user.getId() + "', '" + user.getName() + "', '" + user.getDiscriminator() + "', '" + user.getAvatarUrl() + "')");
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
LoggerInit.logger.warning(ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserUpdateDiscriminator(UserUpdateDiscriminatorEvent e) {
|
||||
User user = e.getUser();
|
||||
ResultSet getDiscriminator = MySQL.queryMySQL("SELECT user_discriminator FROM createvoice_users WHERE user_id = '" + user.getId() + "'");
|
||||
try {
|
||||
if(getDiscriminator.next()) {
|
||||
MySQL.updateQuery("UPDATE createvoice_users SET user_discriminator = '" + user.getDiscriminator() + "'");
|
||||
} else {
|
||||
MySQL.updateQuery("INSERT INTO createvoice_users(user_id, user_name, user_discriminator, avatarURL) VALUES('" + user.getId() + "', '" + user.getName() + "', '" + user.getDiscriminator() + "', '" + user.getAvatarUrl() + "')");
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
LoggerInit.logger.warning(ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package me.lenajenichen.voicebot.listener;
|
||||
|
||||
import me.lenajenichen.voicebot.LoggerInit;
|
||||
import me.lenajenichen.voicebot.api.CreateDescription;
|
||||
import me.lenajenichen.voicebot.main.BotMain;
|
||||
import me.lenajenichen.voicebot.mysql.MySQL;
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import net.dv8tion.jda.api.events.Event;
|
||||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceJoinEvent;
|
||||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent;
|
||||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceMoveEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class VoiceListener extends ListenerAdapter {
|
||||
|
||||
public static Map<Long, Long> tempchannels;
|
||||
|
||||
public VoiceListener() {
|
||||
this.tempchannels = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuildVoiceJoin(GuildVoiceJoinEvent e) {
|
||||
onJoin(e.getChannelJoined(), e.getEntity(), e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuildVoiceLeave(GuildVoiceLeaveEvent e) {
|
||||
onLeave(e.getChannelLeft());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuildVoiceMove(GuildVoiceMoveEvent e) {
|
||||
onLeave(e.getChannelLeft());
|
||||
onJoin(e.getChannelJoined(), e.getEntity(), e);
|
||||
}
|
||||
|
||||
public void onJoin(VoiceChannel joined, Member member, Event e) {
|
||||
ResultSet createchannel_exists = MySQL.queryMySQL("SELECT channel_id FROM createvoice_data WHERE guild_id = '" + Long.valueOf(joined.getGuild().getId()) + "'");
|
||||
try {
|
||||
if(createchannel_exists.next()) {
|
||||
Long channel_id = createchannel_exists.getLong("channel_id");
|
||||
if(joined.getIdLong() == channel_id) {
|
||||
Category cat = joined.getParent();
|
||||
VoiceChannel vc = cat.createVoiceChannel(member.getEffectiveName() + "'s Channel").complete();
|
||||
Guild guild = member.getGuild();
|
||||
vc.putPermissionOverride(guild.getPublicRole()).setDeny(Permission.VIEW_CHANNEL).queue();
|
||||
vc.putPermissionOverride(member).setAllow(Permission.MANAGE_CHANNEL).queue();
|
||||
guild.moveVoiceMember(member, vc).queue();
|
||||
MySQL.updateQuery("INSERT INTO createvoice_createdchannels(guild_id, channel_id, user_id) VALUES('" + Long.valueOf(joined.getGuild().getId()) + "', '" + vc.getIdLong() + "', '" + member.getIdLong() + "')");
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
LoggerInit.logger.warning(ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void onLeave(VoiceChannel channel) {
|
||||
if(channel.getMembers().size() <= 0) {
|
||||
ResultSet getChannel = MySQL.queryMySQL("SELECT channel_id FROM createvoice_createdchannels WHERE channel_id ='" + channel.getIdLong() + "'");
|
||||
try {
|
||||
if(getChannel.next()) {
|
||||
Long channel_id = getChannel.getLong("channel_id");
|
||||
MySQL.updateQuery("DELETE FROM createvoice_createdchannels WHERE channel_id = '" + channel_id + "'");
|
||||
channel.delete().queue();
|
||||
}
|
||||
} catch (SQLException exception) {
|
||||
LoggerInit.logger.warning(exception.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
107
src/main/java/me/lenajenichen/voicebot/main/BotMain.java
Normal file
107
src/main/java/me/lenajenichen/voicebot/main/BotMain.java
Normal file
@@ -0,0 +1,107 @@
|
||||
package me.lenajenichen.voicebot.main;
|
||||
|
||||
import me.lenajenichen.voicebot.CommandManager;
|
||||
import me.lenajenichen.voicebot.LoggerInit;
|
||||
import me.lenajenichen.voicebot.api.CreateDescription;
|
||||
import me.lenajenichen.voicebot.listener.*;
|
||||
import me.lenajenichen.voicebot.mysql.MySQL;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.OnlineStatus;
|
||||
import net.dv8tion.jda.api.entities.Activity;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class BotMain {
|
||||
|
||||
public static BotMain INSTATNCE;
|
||||
|
||||
public JDA shardManager;
|
||||
public JDABuilder jdaBuilder;
|
||||
|
||||
private CommandManager cmdMan;
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
new BotMain();
|
||||
} catch (LoginException | IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public BotMain() throws LoginException, IllegalArgumentException {
|
||||
|
||||
LoggerInit.initLogger();
|
||||
|
||||
INSTATNCE = this;
|
||||
|
||||
MySQL.createTable();
|
||||
|
||||
jdaBuilder = jdaBuilder.createDefault("ODQzNzQxNDgwNzU3NjI0ODMy.YKIRfA.mNJkqZd015aNAJhzZ4qzphhfRQg");
|
||||
jdaBuilder.setStatus(OnlineStatus.ONLINE);
|
||||
jdaBuilder.setActivity(Activity.watching("nach uwu's"));
|
||||
jdaBuilder.enableIntents(GatewayIntent.GUILD_MEMBERS);
|
||||
|
||||
this.cmdMan = new CommandManager();
|
||||
|
||||
System.out.println("1");
|
||||
jdaBuilder.addEventListeners(new CommandListener());
|
||||
System.out.println("1");
|
||||
jdaBuilder.addEventListeners(new VoiceListener());
|
||||
System.out.println("1");
|
||||
jdaBuilder.addEventListeners(new MessageDelete());
|
||||
System.out.println("1");
|
||||
jdaBuilder.addEventListeners(new MessageEvent());
|
||||
System.out.println("1");
|
||||
jdaBuilder.addEventListeners(new AvatarUpdate());
|
||||
System.out.println("1");
|
||||
jdaBuilder.addEventListeners(new CaptchaPrivateMessageEvent());
|
||||
System.out.println("1");
|
||||
jdaBuilder.addEventListeners(new GuildMemberJoin());
|
||||
System.out.println("1");
|
||||
jdaBuilder.addEventListeners(new NameUpdate());
|
||||
|
||||
shardManager = jdaBuilder.build();
|
||||
|
||||
shutdown();
|
||||
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
new Thread(() -> {
|
||||
String line = "";
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
||||
try {
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if(line.equalsIgnoreCase("exit")) {
|
||||
if(shardManager != null) {
|
||||
jdaBuilder.setStatus(OnlineStatus.OFFLINE);
|
||||
shardManager.shutdown();
|
||||
}
|
||||
reader.close();
|
||||
break;
|
||||
} else {
|
||||
System.out.println("Use 'exit' to shutdown the bot");
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
//e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public CommandManager getCmdMan() {
|
||||
return cmdMan;
|
||||
}
|
||||
|
||||
public static void sendErrorMessage(TextChannel channel) {
|
||||
CreateDescription.createDescriptionMessage("Es ist ein Fehler aufgetreten! Kontaktieren Sie bitte den Support.", "#FF0000", channel);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
91
src/main/java/me/lenajenichen/voicebot/mysql/MySQL.java
Normal file
91
src/main/java/me/lenajenichen/voicebot/mysql/MySQL.java
Normal file
@@ -0,0 +1,91 @@
|
||||
package me.lenajenichen.voicebot.mysql;
|
||||
|
||||
import me.lenajenichen.voicebot.LoggerInit;
|
||||
|
||||
import javax.swing.plaf.nimbus.State;
|
||||
import java.sql.*;
|
||||
|
||||
public class MySQL {
|
||||
|
||||
public static Connection createvoice_database;
|
||||
public static Statement stmt;
|
||||
|
||||
public static void connect()
|
||||
{
|
||||
createvoice_database = null;
|
||||
if (!isConnected()) {
|
||||
try
|
||||
{
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
createvoice_database = DriverManager.getConnection("jdbc:mysql://" + "localhost" + ":" + "3306" + "/" + "createvoice", "discordbot", "Fabi2608!=?");
|
||||
stmt = createvoice_database.createStatement();
|
||||
}
|
||||
catch (SQLException | ClassNotFoundException e)
|
||||
{
|
||||
LoggerInit.logger.warning(e.toString());
|
||||
}
|
||||
} else {
|
||||
System.out.println("Es besteht bereits eine Verbindung.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void disconnect() {
|
||||
if(isConnected()) {
|
||||
try {
|
||||
createvoice_database.close();
|
||||
} catch (SQLException e) {
|
||||
LoggerInit.logger.warning(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isConnected()
|
||||
{
|
||||
return createvoice_database != null;
|
||||
}
|
||||
public static void createTable()
|
||||
{
|
||||
try
|
||||
{
|
||||
MySQL.connect();
|
||||
createvoice_database.prepareStatement("CREATE TABLE IF NOT EXISTS createvoice_data(channel_id LONG, guild_id LONG)").executeUpdate();
|
||||
createvoice_database.prepareStatement("CREATE TABLE IF NOT EXISTS createvoice_setup(guild_id LONG, ignored_channel_id LONG, channel_name VARCHAR(101))").executeUpdate();
|
||||
createvoice_database.prepareStatement("CREATE TABLE IF NOT EXISTS createvoice_deletedmessages(id LONG, message TEXT, guild_id LONG, text_channel_id LONG, text_channel_name TEXT, user_id LONG, user_name VARCHAR (100))").executeUpdate();
|
||||
createvoice_database.prepareStatement("CREATE TABLE IF NOT EXISTS createvoice_logchannel(guild_id LONG, channel_id LONG, channel_name VARCHAR(101))").executeUpdate();
|
||||
createvoice_database.prepareStatement("CREATE TABLE IF NOT EXISTS createvoice_createdchannels(guild_id LONG, channel_id LONG, user_id LONG)").executeUpdate();
|
||||
createvoice_database.prepareStatement("CREATE TABLE IF NOT EXISTS createvoice_messages(guild_id LONG, message_id LONG, user_id LONG, message TEXT, user VARCHAR(100), date VARCHAR(30), lastUpdateDate VARCHAR(30))").executeUpdate();
|
||||
createvoice_database.prepareStatement("CREATE TABLE IF NOT EXISTS createvoice_users(user_id LONG, user_name TEXT, user_discriminator TEXT, avatarURL TEXT)").executeUpdate();
|
||||
createvoice_database.prepareStatement("CREATE TABLE IF NOT EXISTS createvoice_captchas(guild_id LONG, message_id LONG, message_id_teamchat LONG,user_id Long, code VARCHAR(5), attempts INTEGER, kicks INTEGER)").executeUpdate();
|
||||
createvoice_database.prepareStatement("CREATE TABLE IF NOT EXISTS createvoice_teamchat(guild_id LONG, channel_id LONG, channel_name TEXT)").executeUpdate();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
LoggerInit.logger.warning(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateQuery(String sqlCommand) {
|
||||
try {
|
||||
MySQL.connect();
|
||||
stmt.executeUpdate(sqlCommand);
|
||||
MySQL.disconnect();
|
||||
} catch (SQLException e) {
|
||||
LoggerInit.logger.warning(e.toString());
|
||||
MySQL.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static ResultSet queryMySQL(String sqlCommand) {
|
||||
try {
|
||||
MySQL.connect();
|
||||
//stmt = message_database.createStatement();
|
||||
return stmt.executeQuery(sqlCommand);
|
||||
} catch (SQLException e) {
|
||||
MySQL.disconnect();
|
||||
LoggerInit.logger.warning(e.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
3
src/main/resources/META-INF/MANIFEST.MF
Normal file
3
src/main/resources/META-INF/MANIFEST.MF
Normal file
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: me.lenajenichen.voicebot.main.BotMain
|
||||
|
||||
Reference in New Issue
Block a user