Skip to content
This repository has been archived by the owner on Jun 16, 2020. It is now read-only.

Commit

Permalink
Warning logic + /check
Browse files Browse the repository at this point in the history
Warnings split into current and total, and added /check command for admins
  • Loading branch information
fajnyCreeper committed Nov 10, 2017
1 parent 1fb6432 commit 7f6d4c6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
22 changes: 12 additions & 10 deletions source/WarnBot/DBConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static int WarnCount(string user, UInt64 guild)
int warns = 0;
while (reader.Read())
{
warns = Convert.ToInt32(reader["warns"]);
warns = Convert.ToInt32(reader["warnsCurrent"]);
}
conn.Close();
return warns;
Expand All @@ -64,10 +64,15 @@ public static void Warn(string user, UInt64 guild, int warns)
conn.Open();
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = conn;
cmd.CommandText = "UPDATE warnings SET warns=" + warns + " WHERE guild=" + guild + " AND user=@User";
cmd.CommandText = "UPDATE warnings SET warnsCurrent=" + warns + " WHERE guild=" + guild + " AND user=@User";
cmd.Prepare();
cmd.Parameters.AddWithValue("@User", user);
cmd.ExecuteNonQuery();
cmd.Dispose();
cmd.Connection = conn;
cmd.CommandText = "UPDATE warnings SET warnsTotal=warnsTotal+1 WHERE guild=" + guild + " AND user=@User";
cmd.Prepare();
cmd.ExecuteNonQuery();
if (conn != null)
{
conn.Close();
Expand Down Expand Up @@ -116,17 +121,14 @@ public static int[] Info(string user, UInt64 guild)
cmd.Prepare();
cmd.Parameters.AddWithValue("@User", user);
MySqlDataReader reader = cmd.ExecuteReader();
int warns = 0;
int kicks = 0;
int[] info = new int[3] { 0, 0, 0 };
while (reader.Read())
{
warns = Convert.ToInt32(reader["warns"]);
kicks = Convert.ToInt32(reader["kicks"]);
info[0] = Convert.ToInt32(reader["warnsCurrent"]);
info[1] = Convert.ToInt32(reader["kicks"]);
info[2] = Convert.ToInt32(reader["warnsTotal"]);
}
conn.Close();
int[] info = new int[2];
info[0] = warns;
info[1] = kicks;
return info;
}
public static void Clear(string user, UInt64 guild)
Expand All @@ -136,7 +138,7 @@ public static void Clear(string user, UInt64 guild)
conn.Open();
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = conn;
cmd.CommandText = "UPDATE warnings SET warns=0 WHERE guild=" + guild + " AND user=@User";
cmd.CommandText = "UPDATE warnings SET warnsCurrent=0 WHERE guild=" + guild + " AND user=@User";
cmd.Prepare();
cmd.Parameters.AddWithValue("@User", user);
cmd.ExecuteNonQuery();
Expand Down
34 changes: 32 additions & 2 deletions source/WarnBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private async Task MessageReceived(SocketMessage msg)
}
else
{
await msg.Channel.SendMessageAsync("You can't ban without a reason!");
await msg.Channel.SendMessageAsync("You can't warn without a reason!");
}
}
else
Expand Down Expand Up @@ -231,7 +231,7 @@ private async Task MessageReceived(SocketMessage msg)
}
break;
case "/help":
await msg.Channel.SendMessageAsync("```Everyone:\n/about............................About this bot\n/example </command>...............Shows example of specified command\n/info <user>......................Shows warnings and kicks\n\nAdmins:\n/ban <user> <reason>..............Bans person\n/clear <user>.....................Clears warning count\n/kick <user> <reason>.............Kicks person\n/warn <user> <reason>...Give person warning\n\nOwner:\n/addusr <user> <K|KB>.............Adds user to Admins\n/rmusr <user> <K|KB>..............Remove user from Admins\n/updateusr <user> <K|KB> .........Updates permissions for user\n..................................K=Kick, KB=Kick and Ban```");
await msg.Channel.SendMessageAsync("```Everyone:\n/about............................About this bot\n/example </command>...............Shows example of specified command\n/info <user>......................Shows warnings and kicks\n\nAdmins:\n/ban <user> <reason>..............Bans person\n/clear <user>.....................Clears warning count\n/check <user>.....................Total and current warning count + kicks\n/kick <user> <reason>.............Kicks person\n/warn <user> <reason[optional]>...Give person warning\n\nOwner:\n/addusr <user> <K|KB>.............Adds user to Admins\n/rmusr <user> <K|KB>..............Remove user from Admins\n/updateusr <user> <K|KB> .........Updates permissions for user\n..................................K=Kick, KB=Kick and Ban```");
break;
case "/addusr":
try
Expand Down Expand Up @@ -348,11 +348,41 @@ private async Task MessageReceived(SocketMessage msg)
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 != "")
{
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("You need to specify user when using this command!");
}
}
catch (Exception e)
{
await msg.Channel.SendMessageAsync("Cannot check user!");
ErrorCatch(msg, e);
}
break;
}
}
}
Expand Down

0 comments on commit 7f6d4c6

Please sign in to comment.