Ability to notify mods when user left or deleted message

This commit is contained in:
Runebaas 2017-09-30 17:26:24 +02:00
parent 5771fcddba
commit 8d08b87d09
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
4 changed files with 166 additions and 9 deletions

View file

@ -1,10 +1,10 @@
using System;
using System.Text;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using Geekbot.net.Lib;
using Google.Apis.YouTube.v3.Data;
using Serilog;
using StackExchange.Redis;
@ -75,10 +75,20 @@ namespace Geekbot.net.Modules
[Summary("Set the game that the bot is playing")]
public async Task popUserRepoCommand()
{
var botOwner = Context.Guild.GetUserAsync(ulong.Parse(_redis.StringGet("botOwner"))).Result;
if (!Context.User.Id.ToString().Equals(botOwner.Id.ToString()))
try
{
await ReplyAsync($"Sorry, only the botowner can do this ({botOwner.Username}#{botOwner.Discriminator})");
var botOwner = Context.Guild.GetUserAsync(ulong.Parse(_redis.StringGet("botOwner"))).Result;
if (!Context.User.Id.ToString().Equals(botOwner.Id.ToString()))
{
await ReplyAsync(
$"Sorry, only the botowner can do this ({botOwner.Username}#{botOwner.Discriminator})");
return;
}
}
catch (Exception e)
{
await ReplyAsync(
$"Sorry, only the botowner can do this");
return;
}
var success = 0;
@ -101,8 +111,85 @@ namespace Geekbot.net.Modules
}
catch (Exception e)
{
await ReplyAsync("Couldn't complete User Repository, see console for more info");
_errorHandler.HandleCommandException(e, Context);
_errorHandler.HandleCommandException(e, Context, "Couldn't complete User Repository, see console for more info");
}
}
[RequireUserPermission(GuildPermission.Administrator)]
[Command("modchannel", RunMode = RunMode.Async)]
[Summary("Set the game that the bot is playing")]
public async Task selectModChannel([Summary("ChannelId")] ulong channelId)
{
try
{
var channel = (ISocketMessageChannel)_client.GetChannel(channelId);
if (string.IsNullOrEmpty(channel.Name))
{
await ReplyAsync("I couldn't find that channel...");
return;
}
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");
}
}
[RequireUserPermission(GuildPermission.Administrator)]
[Command("showleave", RunMode = RunMode.Async)]
[Summary("Notify modchannel when someone leaves")]
public async Task showLeave([Summary("true/false")] bool enabled)
{
var modChannelId = (ulong)_redis.HashGet($"{Context.Guild.Id}:Settings", "ModChannel");
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]`");
}
}
[RequireUserPermission(GuildPermission.Administrator)]
[Command("showdel", RunMode = RunMode.Async)]
[Summary("Notify modchannel when someone leaves")]
public async Task showDelete([Summary("true/false")] bool enabled)
{
var modChannelId = (ulong)_redis.HashGet($"{Context.Guild.Id}:Settings", "ModChannel");
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]`");
}
}
}