This repository has been archived by the owner on Jun 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Creeperman007/in-dev
New framework
- Loading branch information
Showing
7 changed files
with
289 additions
and
375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,231 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using DSharpPlus; | ||
using DSharpPlus.CommandsNext; | ||
using DSharpPlus.CommandsNext.Attributes; | ||
using DSharpPlus.EventArgs; | ||
using DSharpPlus.Entities; | ||
|
||
namespace WarnBot | ||
{ | ||
class Commands | ||
{ | ||
[Command("warn"), Description("Warns a user.")] | ||
public async Task Warn(CommandContext ctx, [Description("Mention of user.")] DiscordUser usr, [RemainingText, Description("Reason")] string reason) | ||
{ | ||
try | ||
{ | ||
if (!usr.IsCurrent || (usr.Id != ctx.Guild.Owner.Id)) | ||
{ | ||
if ((DBConnector.PermCheck(ctx.Member.Id, ctx.Guild.Id)[0] > 1 || ctx.Member.IsOwner) && usr.Id != ctx.Member.Id) | ||
{ | ||
DBConnector.Prepare(usr.Id, ctx.Guild.Id); | ||
int count = DBConnector.WarnCount(usr.Id, ctx.Guild.Id) + 1; | ||
if (count > 3) | ||
count = 1; | ||
DBConnector.Warn(usr.Id, ctx.Guild.Id, count); | ||
await ctx.RespondAsync(String.Format("Warned: {0}\nReason: {1}\nWarning {2}/3", usr.Mention, reason, count)); | ||
if (count == 3) | ||
await ctx.RespondAsync("User can now be kicked!"); | ||
} | ||
} | ||
else | ||
await ctx.RespondAsync("Whoah, you can't use the command on this person!"); | ||
} | ||
catch (Exception e) | ||
{ | ||
ErrorCatch(ctx, e); | ||
} | ||
} | ||
|
||
[Command("kick"), Description("Kicks a person.")] | ||
public async Task Kick(CommandContext ctx, [Description("Mention of user.")] DiscordUser usr, [RemainingText, Description("Reason")] string reason) | ||
{ | ||
try | ||
{ | ||
if (!usr.IsCurrent || (usr.Id != ctx.Guild.Owner.Id)) | ||
{ | ||
if ((DBConnector.PermCheck(ctx.Member.Id, ctx.Guild.Id)[0] > 1 || ctx.Member.IsOwner) && usr.Id != ctx.Member.Id) | ||
{ | ||
DBConnector.Prepare(usr.Id, ctx.Guild.Id); | ||
int info = DBConnector.Info(usr.Id, ctx.Guild.Id)[0]; | ||
if (info == 3) | ||
{ | ||
await ctx.Guild.GetMemberAsync(usr.Id).Result.RemoveAsync(reason); | ||
DBConnector.Kick(usr.Id, ctx.Guild.Id, reason); | ||
await ctx.RespondAsync(String.Format("Kicked {0} for {1}", usr.Username, reason)); | ||
} | ||
else | ||
await ctx.RespondAsync("User does not have three warnings yet!"); | ||
} | ||
} | ||
else | ||
await ctx.RespondAsync("Whoah, you can't use the command on this person!"); | ||
} | ||
catch (Exception e) | ||
{ | ||
ErrorCatch(ctx, e); | ||
} | ||
} | ||
|
||
[Command("ban"), Description("Bans a person.")] | ||
public async Task Ban(CommandContext ctx, [Description("Mention of user.")] DiscordUser usr, [RemainingText, Description("Reason")] string reason) | ||
{ | ||
try | ||
{ | ||
if (!usr.IsCurrent || (usr.Id != ctx.Guild.Owner.Id)) | ||
{ | ||
if ((DBConnector.PermCheck(ctx.Member.Id, ctx.Guild.Id)[0] > 1 || ctx.Member.IsOwner) && usr.Id != ctx.Member.Id) | ||
{ | ||
DBConnector.Prepare(usr.Id, ctx.Guild.Id); | ||
int kick = DBConnector.Info(usr.Id, ctx.Guild.Id)[1]; | ||
if (kick != 0 && (kick % 5) == 0) | ||
{ | ||
await ctx.Guild.GetMemberAsync(usr.Id).Result.BanAsync(0, reason); | ||
DBConnector.Ban(usr.Id, ctx.Guild.Id, reason); | ||
await ctx.RespondAsync(String.Format("Banned {0} for {1}", usr.Username, reason)); | ||
} | ||
else | ||
await ctx.RespondAsync("User does not have number of kicks divisible by 5!"); | ||
} | ||
} | ||
else | ||
await ctx.RespondAsync("Whoah, you can't use the command on this person!"); | ||
} | ||
catch (Exception e) | ||
{ | ||
ErrorCatch(ctx, e); | ||
} | ||
} | ||
|
||
[Command("clear"), Description("Clears warnings count.")] | ||
public async Task Clear(CommandContext ctx, [Description("Mention of user.")] DiscordUser usr) | ||
{ | ||
try | ||
{ | ||
if (!usr.IsCurrent || (usr.Id != ctx.Guild.Owner.Id)) | ||
{ | ||
if ((DBConnector.PermCheck(ctx.Member.Id, ctx.Guild.Id)[0] > 1 || ctx.Member.IsOwner) && usr.Id != ctx.Member.Id) | ||
{ | ||
DBConnector.Clear(usr.Id, ctx.Guild.Id); | ||
await ctx.RespondAsync("Cleared record for " + usr.Mention); | ||
} | ||
} | ||
else | ||
await ctx.RespondAsync("Whoah, you can't use the command on this person!"); | ||
} | ||
catch (Exception e) | ||
{ | ||
ErrorCatch(ctx, e); | ||
} | ||
} | ||
|
||
[Command("info"), Description("Shows warnings and kicks.")] | ||
public async Task Info(CommandContext ctx, [Description("Mention of user.")] DiscordUser usr) | ||
{ | ||
try | ||
{ | ||
if (!usr.IsCurrent || (usr.Id != ctx.Guild.Owner.Id)) | ||
{ | ||
DBConnector.Prepare(usr.Id, ctx.Guild.Id); | ||
int[] info = DBConnector.Info(usr.Id, ctx.Guild.Id); | ||
await ctx.RespondAsync(String.Format("Warnings: {0}\nKicks: {1}", info[0], info[1])); | ||
} | ||
else | ||
await ctx.RespondAsync("Whoah, you can't use the command on this person!"); | ||
} | ||
catch (Exception e) | ||
{ | ||
ErrorCatch(ctx, e); | ||
} | ||
} | ||
|
||
[Command("addusr"), Description("Adds user to Admins.")] | ||
public async Task AddUsr(CommandContext ctx, [Description("Mention of user.")] DiscordUser usr, [Description("K - Kick or KB - Kick and Ban.")] string perms) | ||
{ | ||
try | ||
{ | ||
if (!usr.IsCurrent || (usr.Id != ctx.Guild.Owner.Id)) | ||
{ | ||
if (ctx.Member.IsOwner) | ||
{ | ||
DBConnector.AddUsr(usr.Id, ctx.Guild.Id, perms); | ||
await ctx.RespondAsync("Added user to Admins."); | ||
} | ||
} | ||
else | ||
await ctx.RespondAsync("Whoah, you can't use the command on this person!"); | ||
} | ||
catch (Exception e) | ||
{ | ||
ErrorCatch(ctx, e); | ||
} | ||
} | ||
|
||
[Command("rmusr"), Description("Removes user from Admins.")] | ||
public async Task RmUsr(CommandContext ctx, [Description("Mention of user.")] DiscordUser usr) | ||
{ | ||
try | ||
{ | ||
if (!usr.IsCurrent || (usr.Id != ctx.Guild.Owner.Id)) | ||
{ | ||
if (ctx.Member.IsOwner) | ||
{ | ||
DBConnector.RmUsr(usr.Id, ctx.Guild.Id); | ||
await ctx.RespondAsync("Removed user from Admins."); | ||
} | ||
} | ||
else | ||
await ctx.RespondAsync("Whoah, you can't use the command on this person!"); | ||
} | ||
catch (Exception e) | ||
{ | ||
ErrorCatch(ctx, e); | ||
} | ||
} | ||
|
||
[Command("updateusr"), Description("Updates permissions.")] | ||
public async Task UpdateUsr(CommandContext ctx, [Description("Mention of user.")] DiscordUser usr, [Description("K - Kick or KB - Kick and Ban.")] string perms) | ||
{ | ||
try | ||
{ | ||
if (!usr.IsCurrent || (usr.Id != ctx.Guild.Owner.Id)) | ||
{ | ||
if (ctx.Member.IsOwner) | ||
{ | ||
DBConnector.UpdateUsr(usr.Id, ctx.Guild.Id, perms); | ||
await ctx.RespondAsync("Updated permissions for user."); | ||
} | ||
} | ||
else | ||
await ctx.RespondAsync("Whoah, you can't use the command on this person!"); | ||
} | ||
catch (Exception e) | ||
{ | ||
ErrorCatch(ctx, e); | ||
} | ||
} | ||
|
||
[Command("about"), Description("About this bot")] | ||
public async Task About(CommandContext ctx) | ||
{ | ||
var eb = new DiscordEmbedBuilder | ||
{ | ||
Color = new DiscordColor("#FF0000"), | ||
Title = "About", | ||
Description = "Programmed by Creeperman007\nUsing DSharpPlus library\nGitHub repository: <http://github.com/Creeperman007/WarnBot>" | ||
}; | ||
await ctx.RespondAsync(embed: eb); | ||
} | ||
|
||
private async void ErrorCatch(CommandContext ctx, Exception e) | ||
{ | ||
await ctx.Member.SendMessageAsync("Internal error occured!"); | ||
await ctx.Member.SendMessageAsync("Go to <https://github.com/Creeperman007/WarnBot/issues> open new issue and paste text below and how you got this error"); | ||
await ctx.Member.SendMessageAsync("```" + e + "```"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.