dm users when banned, show command exceptions better

This commit is contained in:
Deukhoofd 2018-08-12 13:11:20 +02:00
parent e28af98c6c
commit a898e69b58
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
3 changed files with 24 additions and 3 deletions

View File

@ -73,7 +73,15 @@ namespace DeukBot4.MessageHandlers.CommandHandler
$"User is trying to use blocked command in PM: {message.Author.Username}");
return;
}
await req.Item1.Command.Invoke(req.Item1);
try
{
await req.Item1.Command.Invoke(req.Item1);
}
catch (Exception e)
{
await Logger.Log("An error occured: \n" + e);
}
break;
case CommandRequest.RequestCode.UnknownCommand:
var permission = await PermissionValidator.GetUserPermissionLevel(message);

View File

@ -96,6 +96,21 @@ namespace DeukBot4.MessageHandlers.CommandHandler
reason = request.Parameters[1].AsString();
}
string desc = "No reason was given.";
if (!string.IsNullOrWhiteSpace(reason))
{
desc = "The given reason was: " + desc;
}
var eb = new EmbedBuilder();
eb.Color = Color.Gold;
eb.Title = "You were banned from " + channel.Guild.Name;
eb.Description = desc;
eb.Author = new EmbedAuthorBuilder();
eb.Author.Name = request.OriginalMessage.Author.Username;
eb.Author.IconUrl = request.OriginalMessage.Author.GetAvatarUrl();
eb.Timestamp = request.OriginalMessage.Timestamp;
user.SendMessageAsync("", embed: eb.Build());
// and ban
await channel.Guild.AddBanAsync(user, 0, reason);
await request.SendMessageAsync($"User was banned: {user.Username}");

View File

@ -1,8 +1,6 @@
using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Discord.Net.Udp;
namespace DeukBot4.MessageHandlers.CommandHandler.RequestStructure
{