diff --git a/source/WarnBot/Program.cs b/source/WarnBot/Program.cs index 4c615dc..87ce46a 100644 --- a/source/WarnBot/Program.cs +++ b/source/WarnBot/Program.cs @@ -37,12 +37,12 @@ private async Task MessageReceived(SocketMessage msg) string cmd = msgSplit[0]; string user = ""; string context = ""; - string usr2ulong = ""; + ulong usr2ulong = 0; string[] replace = { "<", ">", "@" }; try { user = msgSplit[1]; - usr2ulong = user; + string tmp = user; for (int i = 2; i < msgSplit.Length; i++) { context += msgSplit[i] + " "; @@ -50,339 +50,349 @@ private async Task MessageReceived(SocketMessage msg) foreach (string e in replace) { - usr2ulong = usr2ulong.Replace(e, ""); + tmp = tmp.Replace(e, ""); } + usr2ulong = ulong.Parse(tmp); + } catch { } - var chnl = msg.Channel as SocketGuildChannel; - switch (cmd) + if (usr2ulong != 355763643964719106) { - case "/warn": - try - { - if (user != "") + var chnl = msg.Channel as SocketGuildChannel; + switch (cmd) + { + case "/warn": + try { - if ((DBConnector.PermCheck(msg.Author.Id, chnl.Guild.Id)[0] >= 1 || msg.Author.Id == chnl.Guild.Owner.Id) && ulong.Parse(usr2ulong) != msg.Author.Id) + if (user != "") { - if (context != "") + if ((DBConnector.PermCheck(msg.Author.Id, chnl.Guild.Id)[0] >= 1 || msg.Author.Id == chnl.Guild.Owner.Id) && 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 warn without a reason!"); } } else { - await msg.Channel.SendMessageAsync("You can't warn without a reason!"); + await msg.Channel.SendMessageAsync(msg.Author.Mention + " you don't have permission for this action"); } } else { - await msg.Channel.SendMessageAsync(msg.Author.Mention + " you don't have permission for this action"); + await msg.Channel.SendMessageAsync("You need to specify user when using this command!"); } } - else + catch (Exception e) { - await msg.Channel.SendMessageAsync("You need to specify user when using this command!"); + await msg.Channel.SendMessageAsync("Cannot warn user!"); + ErrorCatch(msg, e); } - } - catch (Exception e) - { - await msg.Channel.SendMessageAsync("Cannot warn user!"); - ErrorCatch(msg, e); - } - break; - case "/kick": - try - { - if (user != "") { - if ((DBConnector.PermCheck(msg.Author.Id, chnl.Guild.Id)[0] >= 1 || msg.Author.Id == chnl.Guild.Owner.Id) && ulong.Parse(usr2ulong) != msg.Author.Id) + break; + case "/kick": + try + { + if (user != "") { - DBConnector.Prepare(user, chnl.Guild.Id); - int[] info = DBConnector.Info(user, chnl.Guild.Id); - if (info[0] == 3) + if ((DBConnector.PermCheck(msg.Author.Id, chnl.Guild.Id)[0] >= 1 || msg.Author.Id == chnl.Guild.Owner.Id) && usr2ulong != msg.Author.Id) { - if (context != "") + DBConnector.Prepare(user, chnl.Guild.Id); + int[] info = DBConnector.Info(user, chnl.Guild.Id); + if (info[0] == 3) { - await chnl.GetUser(Convert.ToUInt64(usr2ulong)).KickAsync(context); - DBConnector.Kick(user, chnl.Guild.Id, context); - await msg.Channel.SendMessageAsync("Kicked " + user + " for \"" + context + "\""); + if (context != "") + { + await chnl.GetUser(usr2ulong).KickAsync(context); + DBConnector.Kick(user, chnl.Guild.Id, context); + await msg.Channel.SendMessageAsync("Kicked " + user + " for \"" + context + "\""); + } + else + { + await msg.Channel.SendMessageAsync("You can't kick without a reason!"); + } } else { - await msg.Channel.SendMessageAsync("You can't kick without a reason!"); + await msg.Channel.SendMessageAsync("User does not have 3 warnings yet!"); } } else { - await msg.Channel.SendMessageAsync("User does not have 3 warnings yet!"); + await msg.Channel.SendMessageAsync("You need to specify user when using this command!"); } } else { - await msg.Channel.SendMessageAsync("You need to specify user when using this command!"); + await msg.Channel.SendMessageAsync(msg.Author.Mention + " you don't have permission for this action"); } } - else + catch (Exception e) { - await msg.Channel.SendMessageAsync(msg.Author.Mention + " you don't have permission for this action"); + await msg.Channel.SendMessageAsync("Cannot kick user!"); + ErrorCatch(msg, e); } - } - catch (Exception e) - { - await msg.Channel.SendMessageAsync("Cannot kick user!"); - ErrorCatch(msg, e); - } - break; - case "/ban": - try - { - if (user != "") + break; + case "/ban": + try { - if ((DBConnector.PermCheck(msg.Author.Id, chnl.Guild.Id)[1] >= 1 || msg.Author.Id == chnl.Guild.Owner.Id) && ulong.Parse(usr2ulong) != msg.Author.Id) + if (user != "") { - if (context != "") + if ((DBConnector.PermCheck(msg.Author.Id, chnl.Guild.Id)[1] >= 1 || msg.Author.Id == chnl.Guild.Owner.Id) && usr2ulong != msg.Author.Id) { - int kick = DBConnector.Info(user, chnl.Guild.Id)[1]; - if (kick != 0 && (kick % 5) == 0) + if (context != "") { - DBConnector.Ban(user, chnl.Guild.Id, context); - await chnl.Guild.AddBanAsync(Convert.ToUInt64(usr2ulong), 0, context); - await msg.Channel.SendMessageAsync("Banned " + user + " for \"" + context + "\""); + 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(usr2ulong, 0, context); + await msg.Channel.SendMessageAsync("Banned " + user + " for \"" + context + "\""); + } + else + { + await msg.Channel.SendMessageAsync("User does not have number of kicks divisible by 5!"); + } } else { - await msg.Channel.SendMessageAsync("User does not have number of kicks divisible by 5!"); + await msg.Channel.SendMessageAsync("You can't ban without a reason!"); } } else { - await msg.Channel.SendMessageAsync("You can't ban without a reason!"); + await msg.Channel.SendMessageAsync(msg.Author.Mention + " you don't have permission for this action"); } } else { - await msg.Channel.SendMessageAsync(msg.Author.Mention + " you don't have permission for this action"); + await msg.Channel.SendMessageAsync("You need to specify user when using this command!"); } } - else + catch (Exception e) { - await msg.Channel.SendMessageAsync("You need to specify user when using this command!"); + await msg.Channel.SendMessageAsync("Cannot ban user!"); + ErrorCatch(msg, e); } - } - catch (Exception e) - { - await msg.Channel.SendMessageAsync("Cannot ban user!"); - ErrorCatch(msg, e); - } - break; - case "/clear": - try - { - if (user != "") + break; + case "/clear": + try { - if (DBConnector.PermCheck(msg.Author.Id, chnl.Guild.Id)[1] >= 1 || (msg.Author.Id == chnl.Guild.Owner.Id || ulong.Parse(usr2ulong) != msg.Author.Id)) + if (user != "") { - DBConnector.Clear(user, chnl.Guild.Id); - await msg.Channel.SendMessageAsync("Cleared record for " + user); + if (DBConnector.PermCheck(msg.Author.Id, chnl.Guild.Id)[1] >= 1 || (msg.Author.Id == chnl.Guild.Owner.Id || usr2ulong != msg.Author.Id)) + { + DBConnector.Clear(user, chnl.Guild.Id); + await msg.Channel.SendMessageAsync("Cleared record for " + user); + } + else + { + await msg.Channel.SendMessageAsync(msg.Author.Mention + " you don't have permission for this action"); + } } else { - await msg.Channel.SendMessageAsync(msg.Author.Mention + " you don't have permission for this action"); + await msg.Channel.SendMessageAsync("You need to specify user when using this command!"); } } - else + catch (Exception e) { - await msg.Channel.SendMessageAsync("You need to specify user when using this command!"); + await msg.Channel.SendMessageAsync("Cannot clear record for user!"); + ErrorCatch(msg, e); } - } - catch (Exception e) - { - await msg.Channel.SendMessageAsync("Cannot clear record for user!"); - ErrorCatch(msg, e); - } - break; - case "/info": - try - { - if (user != "") + break; + case "/info": + try { - DBConnector.Prepare(user, chnl.Guild.Id); - int[] info = DBConnector.Info(user, chnl.Guild.Id); - await msg.Channel.SendMessageAsync("Warnings: " + info[0] + "\nKicks: " + info[1]); + if (user != "") + { + DBConnector.Prepare(user, chnl.Guild.Id); + int[] info = DBConnector.Info(user, chnl.Guild.Id); + await msg.Channel.SendMessageAsync("Warnings: " + info[0] + "\nKicks: " + info[1]); + } + else + { + await msg.Channel.SendMessageAsync("You need to specify user when using this command!"); + } } - else + catch (Exception e) { - await msg.Channel.SendMessageAsync("You need to specify user when using this command!"); + await msg.Channel.SendMessageAsync("Cannot retreive info about user!"); + ErrorCatch(msg, e); } - } - catch (Exception e) - { - await msg.Channel.SendMessageAsync("Cannot retreive info about user!"); - ErrorCatch(msg, e); - } - 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/check .....................Total and current warning count + kicks\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 - { - if (user != "") + 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/check .....................Total and current warning count + kicks\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 { - if (msg.Author.Id == chnl.Guild.Owner.Id) + if (user != "") { - DBConnector.AddUsr(Convert.ToUInt64(usr2ulong), chnl.Guild.Id, context); - await msg.Channel.SendMessageAsync("Added user to Admins."); + if (msg.Author.Id == chnl.Guild.Owner.Id) + { + DBConnector.AddUsr(usr2ulong, chnl.Guild.Id, context); + await msg.Channel.SendMessageAsync("Added user to Admins."); + } + else + { + await msg.Channel.SendMessageAsync(msg.Author.Mention + " you don't have permission for this action"); + } } else { - await msg.Channel.SendMessageAsync(msg.Author.Mention + " you don't have permission for this action"); + await msg.Channel.SendMessageAsync("You need to specify user when using this command!"); } } - else + catch (Exception e) { - await msg.Channel.SendMessageAsync("You need to specify user when using this command!"); + await msg.Channel.SendMessageAsync("Cannot add user to Admins!"); + ErrorCatch(msg, e); } - } - catch (Exception e) - { - await msg.Channel.SendMessageAsync("Cannot add user to Admins!"); - ErrorCatch(msg, e); - } - break; - case "/rmusr": - try - { - if (user != "") + break; + case "/rmusr": + try { - if (msg.Author.Id == chnl.Guild.Owner.Id) + if (user != "") { - DBConnector.RmUsr(Convert.ToUInt64(usr2ulong), chnl.Guild.Id); - await msg.Channel.SendMessageAsync("Removed user from Admins."); + if (msg.Author.Id == chnl.Guild.Owner.Id) + { + DBConnector.RmUsr(usr2ulong, chnl.Guild.Id); + await msg.Channel.SendMessageAsync("Removed user from Admins."); + } + else + { + await msg.Channel.SendMessageAsync(msg.Author.Mention + " you don't have permission for this action"); + } } else { - await msg.Channel.SendMessageAsync(msg.Author.Mention + " you don't have permission for this action"); + await msg.Channel.SendMessageAsync("You need to specify user when using this command!"); } } - else + catch (Exception e) { - await msg.Channel.SendMessageAsync("You need to specify user when using this command!"); + await msg.Channel.SendMessageAsync("Cannot remove user from Admins!"); + ErrorCatch(msg, e); } - } - catch (Exception e) - { - await msg.Channel.SendMessageAsync("Cannot remove user from Admins!"); - ErrorCatch(msg, e); - } - break; - case "/updateusr": - try - { - if (user != "") + break; + case "/updateusr": + try { - if (msg.Author.Id == chnl.Guild.Owner.Id) + if (user != "") { - DBConnector.UpdateUsr(Convert.ToUInt64(usr2ulong), chnl.Guild.Id, context); - await msg.Channel.SendMessageAsync("Updated permissions for user."); + if (msg.Author.Id == chnl.Guild.Owner.Id) + { + DBConnector.UpdateUsr(usr2ulong, chnl.Guild.Id, context); + await msg.Channel.SendMessageAsync("Updated permissions for user."); + } + else + { + await msg.Channel.SendMessageAsync(msg.Author.Mention + " you don't have permission for this action"); + } } else { - await msg.Channel.SendMessageAsync(msg.Author.Mention + " you don't have permission for this action"); + await msg.Channel.SendMessageAsync("You need to specify user when using this command!"); } } - else + catch (Exception e) + { + await msg.Channel.SendMessageAsync("Cannot update permissions!"); + ErrorCatch(msg, e); + } + break; + case "/about": + var eb = new EmbedBuilder(); + eb.WithColor(Color.Red); + eb.WithTitle("About"); + eb.WithDescription("Programmed by Creeperman007\nUsing Discord.Net library\nGitHub repository: "); + await msg.Channel.SendMessageAsync("", false, eb); + break; + case "/example": + switch (user) { - await msg.Channel.SendMessageAsync("You need to specify user when using this command!"); + case "/ban": + await msg.Channel.SendMessageAsync("```/ban @" + msg.Author.ToString() + " Spamming```"); + break; + case "/kick": + await msg.Channel.SendMessageAsync("```/kick @" + msg.Author.ToString() + " Spamming```"); + break; + case "/warn": + await msg.Channel.SendMessageAsync("```/warn @" + msg.Author.ToString() + " Spamming```"); + break; + case "/clear": + await msg.Channel.SendMessageAsync("```/clear @" + msg.Author.ToString() + "```"); + break; + case "/info": + await msg.Channel.SendMessageAsync("```/info @" + msg.Author.ToString() + "```"); + break; + case "/addusr": + await msg.Channel.SendMessageAsync("```/addusr @" + msg.Author.ToString() + " K``` /\\ for kick only\nOR\n```/addusr @" + msg.Author.ToString() + " KB``` /\\ for kick and ban"); + break; + case "/rmusr": + await msg.Channel.SendMessageAsync("```/rmusr @" + msg.Author.ToString() + "```"); + break; + case "/updateusr": + await msg.Channel.SendMessageAsync("```/updateusr @" + msg.Author.ToString() + " K``` /\\ for kick only\nOR\n```/updateusr @" + msg.Author.ToString() + " KB``` /\\ for kick and ban"); + break; + case "/example": + await msg.Channel.SendMessageAsync("```/example /kick```"); + break; + case "/check": + await msg.Channel.SendMessageAsync("```/check @" + msg.Author.ToString() + "```"); + break; + default: + await msg.Channel.SendMessageAsync("This is not existing command, or it does not need any arguments :confused:"); + break; } - } - catch (Exception e) - { - await msg.Channel.SendMessageAsync("Cannot update permissions!"); - ErrorCatch(msg, e); - } - break; - case "/about": - var eb = new EmbedBuilder(); - eb.WithColor(Color.Red); - eb.WithTitle("About"); - eb.WithDescription("Programmed by Creeperman007\nUsing Discord.Net library\nGitHub repository: "); - await msg.Channel.SendMessageAsync("", false, eb); - break; - case "/example": - switch(user) - { - case "/ban": - await msg.Channel.SendMessageAsync("```/ban @" + msg.Author.ToString() + " Spamming```"); - break; - case "/kick": - await msg.Channel.SendMessageAsync("```/kick @" + msg.Author.ToString() + " Spamming```"); - break; - case "/warn": - await msg.Channel.SendMessageAsync("```/warn @" + msg.Author.ToString() + " Spamming```"); - break; - case "/clear": - await msg.Channel.SendMessageAsync("```/clear @" + msg.Author.ToString() + "```"); - break; - case "/info": - await msg.Channel.SendMessageAsync("```/info @" + msg.Author.ToString() + "```"); - break; - case "/addusr": - await msg.Channel.SendMessageAsync("```/addusr @" + msg.Author.ToString() + " K``` /\\ for kick only\nOR\n```/addusr @" + msg.Author.ToString() + " KB``` /\\ for kick and ban"); - break; - case "/rmusr": - await msg.Channel.SendMessageAsync("```/rmusr @" + msg.Author.ToString() + "```"); - break; - case "/updateusr": - await msg.Channel.SendMessageAsync("```/updateusr @" + msg.Author.ToString() + " K``` /\\ for kick only\nOR\n```/updateusr @" + msg.Author.ToString() + " KB``` /\\ for kick and ban"); - break; - case "/example": - await msg.Channel.SendMessageAsync("```/example /kick```"); - break; - case "/check": - await msg.Channel.SendMessageAsync("```/check @" + msg.Author.ToString() + "```"); - break; - default: - await msg.Channel.SendMessageAsync("This is not existing command, or it does not need any arguments :confused:"); - break; - } - break; - case "/check": - try - { - if (user != "") + break; + case "/check": + try { - if ((DBConnector.PermCheck(msg.Author.Id, chnl.Guild.Id)[0] >= 1 || msg.Author.Id == chnl.Guild.Owner.Id)) + if (user != "") { - DBConnector.Prepare(user, chnl.Guild.Id); - int[] info = DBConnector.Info(user, chnl.Guild.Id); - await msg.Author.SendMessageAsync("Admin check for " + user + " from **" + chnl.Guild.Name + "**\nCurrent warnings: " + info[0] + "\nTotal warnings: " + info[2] + "\nKicks: " + info[1]); + if ((DBConnector.PermCheck(msg.Author.Id, chnl.Guild.Id)[0] >= 1 || msg.Author.Id == chnl.Guild.Owner.Id)) + { + DBConnector.Prepare(user, chnl.Guild.Id); + int[] info = DBConnector.Info(user, chnl.Guild.Id); + await msg.Author.SendMessageAsync("Admin check for " + user + " from **" + chnl.Guild.Name + "**\nCurrent warnings: " + info[0] + "\nTotal warnings: " + info[2] + "\nKicks: " + info[1]); + } + else + { + await msg.Channel.SendMessageAsync(msg.Author.Mention + " you don't have permission for this action"); + } } else { - await msg.Channel.SendMessageAsync(msg.Author.Mention + " you don't have permission for this action"); + await msg.Channel.SendMessageAsync("You need to specify user when using this command!"); } } - else + catch (Exception e) { - await msg.Channel.SendMessageAsync("You need to specify user when using this command!"); + await msg.Channel.SendMessageAsync("Cannot check user!"); + ErrorCatch(msg, e); } - } - catch (Exception e) - { - await msg.Channel.SendMessageAsync("Cannot check user!"); - ErrorCatch(msg, e); - } - break; + break; + } + } + else + { + await msg.Channel.SendMessageAsync(msg.Author.Mention + " is it good idea to do this to me?"); } } }