2017-09-30 01:38:10 +02:00
|
|
|
|
using System;
|
2017-09-30 17:26:24 +02:00
|
|
|
|
using System.Text;
|
2017-09-30 01:38:10 +02:00
|
|
|
|
using System.Threading.Tasks;
|
2017-09-15 22:56:03 +02:00
|
|
|
|
using Discord;
|
2017-09-14 22:11:19 +02:00
|
|
|
|
using Discord.Commands;
|
2017-09-27 22:48:09 +02:00
|
|
|
|
using Discord.WebSocket;
|
2017-09-30 01:38:10 +02:00
|
|
|
|
using Geekbot.net.Lib;
|
2017-09-27 22:48:09 +02:00
|
|
|
|
using Serilog;
|
2017-09-14 22:11:19 +02:00
|
|
|
|
using StackExchange.Redis;
|
|
|
|
|
|
2017-10-02 21:57:48 +02:00
|
|
|
|
namespace Geekbot.net.Commands
|
2017-09-14 22:11:19 +02:00
|
|
|
|
{
|
|
|
|
|
[Group("admin")]
|
2017-10-27 00:18:58 +02:00
|
|
|
|
[RequireUserPermission(GuildPermission.Administrator)]
|
|
|
|
|
public class Admin : ModuleBase
|
2017-09-14 22:11:19 +02:00
|
|
|
|
{
|
2017-09-30 01:38:10 +02:00
|
|
|
|
private readonly IDatabase _redis;
|
|
|
|
|
private readonly DiscordSocketClient _client;
|
|
|
|
|
private readonly IErrorHandler _errorHandler;
|
2017-09-27 22:48:09 +02:00
|
|
|
|
|
2017-10-27 00:18:58 +02:00
|
|
|
|
public Admin(IDatabase redis, DiscordSocketClient client, IErrorHandler errorHandler)
|
2017-09-14 22:11:19 +02:00
|
|
|
|
{
|
2017-09-30 01:38:10 +02:00
|
|
|
|
_redis = redis;
|
|
|
|
|
_client = client;
|
|
|
|
|
_errorHandler = errorHandler;
|
2017-09-14 22:11:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-15 22:56:03 +02:00
|
|
|
|
[Command("welcome", RunMode = RunMode.Async)]
|
2017-10-12 16:34:10 +02:00
|
|
|
|
[Remarks(CommandCategories.Admin)]
|
2017-09-15 22:56:03 +02:00
|
|
|
|
[Summary("Set a Welcome Message (use '$user' to mention the new joined user).")]
|
|
|
|
|
public async Task SetWelcomeMessage([Remainder] [Summary("message")] string welcomeMessage)
|
2017-09-14 22:11:19 +02:00
|
|
|
|
{
|
2017-09-30 01:38:10 +02:00
|
|
|
|
_redis.HashSet($"{Context.Guild.Id}:Settings", new HashEntry[] { new HashEntry("WelcomeMsg", welcomeMessage) });
|
2017-09-14 22:11:19 +02:00
|
|
|
|
var formatedMessage = welcomeMessage.Replace("$user", Context.User.Mention);
|
|
|
|
|
await ReplyAsync("Welcome message has been changed\r\nHere is an example of how it would look:\r\n" +
|
2017-09-15 22:56:03 +02:00
|
|
|
|
formatedMessage);
|
2017-09-14 22:11:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-30 17:26:24 +02:00
|
|
|
|
[Command("modchannel", RunMode = RunMode.Async)]
|
2017-10-12 16:34:10 +02:00
|
|
|
|
[Remarks(CommandCategories.Admin)]
|
|
|
|
|
[Summary("Set a channel for moderation purposes")]
|
2017-10-19 22:01:42 +02:00
|
|
|
|
public async Task selectModChannel([Summary("#Channel")] ISocketMessageChannel channel)
|
2017-09-30 17:26:24 +02:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
sb.AppendLine("Successfully saved mod channel, you can now do the following");
|
|
|
|
|
sb.AppendLine("- `!admin showleave true` - send message to mod channel when someone leaves");
|
|
|
|
|
sb.AppendLine("- `!admin showdel true` - send message to mod channel when someone deletes a message");
|
|
|
|
|
await channel.SendMessageAsync(sb.ToString());
|
|
|
|
|
_redis.HashSet($"{Context.Guild.Id}:Settings", new HashEntry[] {new HashEntry("ModChannel", channel.Id.ToString())});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
_errorHandler.HandleCommandException(e, Context, "That channel doesn't seem to be valid");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Command("showleave", RunMode = RunMode.Async)]
|
2017-10-12 16:34:10 +02:00
|
|
|
|
[Remarks(CommandCategories.Admin)]
|
2017-09-30 17:26:24 +02:00
|
|
|
|
[Summary("Notify modchannel when someone leaves")]
|
|
|
|
|
public async Task showLeave([Summary("true/false")] bool enabled)
|
|
|
|
|
{
|
2017-10-19 22:01:42 +02:00
|
|
|
|
var modChannelId = ulong.Parse(_redis.HashGet($"{Context.Guild.Id}:Settings", "ModChannel"));
|
2017-09-30 17:26:24 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var modChannel = (ISocketMessageChannel) _client.GetChannel(modChannelId);
|
|
|
|
|
if (enabled)
|
|
|
|
|
{
|
|
|
|
|
await modChannel.SendMessageAsync("Saved - now sending messages here when someone leaves");
|
|
|
|
|
_redis.HashSet($"{Context.Guild.Id}:Settings", new HashEntry[] {new HashEntry("ShowLeave", true)});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await modChannel.SendMessageAsync("Saved - stopping sending messages here when someone leaves");
|
|
|
|
|
_redis.HashSet($"{Context.Guild.Id}:Settings", new HashEntry[] {new HashEntry("ShowLeave", false)});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
_errorHandler.HandleCommandException(e, Context, "Modchannel doesn't seem to exist, please set one with `!admin modchannel [channelId]`");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Command("showdel", RunMode = RunMode.Async)]
|
2017-10-12 16:34:10 +02:00
|
|
|
|
[Remarks(CommandCategories.Admin)]
|
|
|
|
|
[Summary("Notify modchannel when someone deletes a message")]
|
2017-09-30 17:26:24 +02:00
|
|
|
|
public async Task showDelete([Summary("true/false")] bool enabled)
|
|
|
|
|
{
|
2017-10-19 22:01:42 +02:00
|
|
|
|
var modChannelId = ulong.Parse(_redis.HashGet($"{Context.Guild.Id}:Settings", "ModChannel"));
|
2017-09-30 17:26:24 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var modChannel = (ISocketMessageChannel) _client.GetChannel(modChannelId);
|
|
|
|
|
if (enabled)
|
|
|
|
|
{
|
|
|
|
|
await modChannel.SendMessageAsync("Saved - now sending messages here when someone deletes a message");
|
|
|
|
|
_redis.HashSet($"{Context.Guild.Id}:Settings", new HashEntry[] {new HashEntry("ShowDelete", true)});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await modChannel.SendMessageAsync("Saved - stopping sending messages here when someone deletes a message");
|
|
|
|
|
_redis.HashSet($"{Context.Guild.Id}:Settings", new HashEntry[] {new HashEntry("ShowDelete", false)});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
_errorHandler.HandleCommandException(e, Context, "Modchannel doesn't seem to exist, please set one with `!admin modchannel [channelId]`");
|
2017-09-30 01:38:10 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-14 22:11:19 +02:00
|
|
|
|
}
|
2017-04-14 22:18:22 +02:00
|
|
|
|
}
|