2017-10-27 00:18:58 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.Commands;
|
2017-10-30 18:35:08 +01:00
|
|
|
|
using Discord.WebSocket;
|
2017-10-27 00:18:58 +02:00
|
|
|
|
using Geekbot.net.Lib;
|
2017-10-30 18:35:08 +01:00
|
|
|
|
using StackExchange.Redis;
|
2017-10-27 00:18:58 +02:00
|
|
|
|
|
|
|
|
|
namespace Geekbot.net.Commands
|
|
|
|
|
{
|
|
|
|
|
[Group("mod")]
|
|
|
|
|
[RequireUserPermission(GuildPermission.KickMembers)]
|
|
|
|
|
[RequireUserPermission(GuildPermission.ManageMessages)]
|
|
|
|
|
[RequireUserPermission(GuildPermission.ManageRoles)]
|
|
|
|
|
public class Mod : ModuleBase
|
|
|
|
|
{
|
|
|
|
|
private readonly IUserRepository _userRepository;
|
|
|
|
|
private readonly IErrorHandler _errorHandler;
|
2017-10-30 18:35:08 +01:00
|
|
|
|
private readonly IDatabase _redis;
|
|
|
|
|
private readonly DiscordSocketClient _client;
|
2017-10-27 00:18:58 +02:00
|
|
|
|
|
2017-10-30 18:35:08 +01:00
|
|
|
|
public Mod(IUserRepository userRepositry, IErrorHandler errorHandler, IDatabase redis, DiscordSocketClient client)
|
2017-10-27 00:18:58 +02:00
|
|
|
|
{
|
|
|
|
|
_userRepository = userRepositry;
|
|
|
|
|
_errorHandler = errorHandler;
|
2017-10-30 18:35:08 +01:00
|
|
|
|
_redis = redis;
|
|
|
|
|
_client = client;
|
2017-10-27 00:18:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Command("namehistory", RunMode = RunMode.Async)]
|
|
|
|
|
[Remarks(CommandCategories.Admin)]
|
|
|
|
|
[Summary("See past usernames of an user")]
|
|
|
|
|
public async Task usernameHistory([Summary("@user")] IUser user)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var userRepo = _userRepository.Get(user.Id);
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
sb.AppendLine($":bust_in_silhouette: {user.Username} has been known as:");
|
|
|
|
|
foreach (var name in userRepo.UsedNames)
|
|
|
|
|
{
|
|
|
|
|
sb.AppendLine($"- `{name}`");
|
|
|
|
|
}
|
|
|
|
|
await ReplyAsync(sb.ToString());
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2017-10-30 18:35:08 +01:00
|
|
|
|
_errorHandler.HandleCommandException(e, Context, $"I don't have enough permissions to give {user.Username} that role");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Command("kick", RunMode = RunMode.Async)]
|
|
|
|
|
[Remarks(CommandCategories.Admin)]
|
|
|
|
|
[Summary("Ban a user")]
|
2017-10-30 20:43:07 +01:00
|
|
|
|
public async Task kick([Summary("@user")] IUser userNormal, [Summary("reason"), Remainder] string reason = "none")
|
2017-10-30 18:35:08 +01:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var user = (IGuildUser)userNormal;
|
2017-10-30 20:43:07 +01:00
|
|
|
|
if (reason == "none")
|
2017-10-30 18:35:08 +01:00
|
|
|
|
{
|
|
|
|
|
reason = "No reason provided";
|
|
|
|
|
}
|
|
|
|
|
await user.GetOrCreateDMChannelAsync().Result.SendMessageAsync(
|
|
|
|
|
$"You have been kicked from {Context.Guild.Name} for the following reason: \"{reason}\"");
|
2017-10-30 20:43:07 +01:00
|
|
|
|
await user.KickAsync();
|
2017-10-30 18:35:08 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var modChannelId = ulong.Parse(_redis.HashGet($"{Context.Guild.Id}:Settings", "ModChannel"));
|
|
|
|
|
var modChannel = (ISocketMessageChannel) _client.GetChannel(modChannelId);
|
|
|
|
|
var eb = new EmbedBuilder();
|
2017-10-30 20:43:07 +01:00
|
|
|
|
eb.Title = ":x: User Kicked";
|
2017-10-30 18:35:08 +01:00
|
|
|
|
eb.AddInlineField("User", user.Username);
|
|
|
|
|
eb.AddInlineField("By Mod", Context.User.Username);
|
|
|
|
|
eb.AddField("Reason", reason);
|
|
|
|
|
await modChannel.SendMessageAsync("", false, eb.Build());
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
await ReplyAsync($"{user.Username} was kicked for the following reason: \"{reason}\"");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
_errorHandler.HandleCommandException(e, Context, "I don't have enough permissions to kick someone");
|
2017-10-27 00:18:58 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|