From 1fb64324b4cd24be5bff4333abe74cca5d32e5d5 Mon Sep 17 00:00:00 2001 From: Creeperman007 Date: Tue, 17 Oct 2017 17:11:23 +0200 Subject: [PATCH] Updated reason inserting for Kick and added reason for ban --- source/WarnBot/DBConnector.cs | 18 +++++++++++++++++- source/WarnBot/Program.cs | 26 +++++++++++++++++--------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/source/WarnBot/DBConnector.cs b/source/WarnBot/DBConnector.cs index 068d312..fc4eb92 100644 --- a/source/WarnBot/DBConnector.cs +++ b/source/WarnBot/DBConnector.cs @@ -80,7 +80,23 @@ public static void Kick(string user, UInt64 guild, string reason) conn.Open(); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn; - cmd.CommandText = "UPDATE warnings SET kicks=kicks+1, reason=\"" + reason + "\" WHERE guild=" + guild + " AND user=@User"; + cmd.CommandText = "UPDATE warnings SET kicks=kicks+1, kickReason=\"" + reason + "\" WHERE guild=" + guild + " AND user=@User"; + cmd.Prepare(); + cmd.Parameters.AddWithValue("@User", user); + cmd.ExecuteNonQuery(); + if (conn != null) + { + conn.Close(); + } + } + public static void Ban(string user, UInt64 guild, string reason) + { + MySqlConnection conn = null; + conn = new MySqlConnection(cs); + conn.Open(); + MySqlCommand cmd = new MySqlCommand(); + cmd.Connection = conn; + cmd.CommandText = "UPDATE warnings SET banReason=\"" + reason + "\" WHERE guild=" + guild + " AND user=@User"; cmd.Prepare(); cmd.Parameters.AddWithValue("@User", user); cmd.ExecuteNonQuery(); diff --git a/source/WarnBot/Program.cs b/source/WarnBot/Program.cs index 3d83d20..8604520 100644 --- a/source/WarnBot/Program.cs +++ b/source/WarnBot/Program.cs @@ -64,17 +64,24 @@ private async Task MessageReceived(SocketMessage msg) { if ((DBConnector.PermCheck(msg.Author.Id, chnl.Guild.Id)[0] >= 1 || msg.Author.Id == chnl.Guild.Owner.Id) && ulong.Parse(usr2ulong) != msg.Author.Id) { - DBConnector.Prepare(user, chnl.Guild.Id); - int count = DBConnector.WarnCount(user, chnl.Guild.Id) + 1; - if (count > 3) + if (context != "") { - count = 1; + DBConnector.Prepare(user, chnl.Guild.Id); + int count = DBConnector.WarnCount(user, chnl.Guild.Id) + 1; + if (count > 3) + { + count = 1; + } + DBConnector.Warn(user, chnl.Guild.Id, count); + await msg.Channel.SendMessageAsync("Warned: " + user + "\nReason: " + context + "\nWarning " + count + "/3"); + if (count == 3) + { + await msg.Channel.SendMessageAsync("User now can be kicked!"); + } } - DBConnector.Warn(user, chnl.Guild.Id, count); - await msg.Channel.SendMessageAsync("Warned: " + user + "\nReason: " + context + "\nWarning " + count + "/3"); - if (count == 3) + else { - await msg.Channel.SendMessageAsync("User now can be kicked!"); + await msg.Channel.SendMessageAsync("You can't ban without a reason!"); } } else @@ -147,6 +154,7 @@ private async Task MessageReceived(SocketMessage msg) int kick = DBConnector.Info(user, chnl.Guild.Id)[1]; if (kick != 0 && (kick % 5) == 0) { + DBConnector.Ban(user, chnl.Guild.Id, context); await chnl.Guild.AddBanAsync(Convert.ToUInt64(usr2ulong), 0, context); await msg.Channel.SendMessageAsync("Banned " + user + " for \"" + context + "\""); } @@ -223,7 +231,7 @@ private async Task MessageReceived(SocketMessage msg) } break; case "/help": - await msg.Channel.SendMessageAsync("```Everyone:\n/about............................About this bot\n/example ...............Shows example of specified command\n/info ......................Shows warnings and kicks\n\nAdmins:\n/ban ..............Bans person\n/clear .....................Clears warning count\n/kick .............Kicks person\n/warn ...Give person warning\n\nOwner:\n/addusr .............Adds user to Admins\n/rmusr ..............Remove user from Admins\n/updateusr .........Updates permissions for user\n..................................K=Kick, KB=Kick and Ban```"); + await msg.Channel.SendMessageAsync("```Everyone:\n/about............................About this bot\n/example ...............Shows example of specified command\n/info ......................Shows warnings and kicks\n\nAdmins:\n/ban ..............Bans person\n/clear .....................Clears warning count\n/kick .............Kicks person\n/warn ...Give person warning\n\nOwner:\n/addusr .............Adds user to Admins\n/rmusr ..............Remove user from Admins\n/updateusr .........Updates permissions for user\n..................................K=Kick, KB=Kick and Ban```"); break; case "/addusr": try