Make modchannel command easier and some random stuff

This commit is contained in:
Runebaas 2017-10-19 22:01:42 +02:00
parent 2eca82e899
commit 75c699e25b
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
4 changed files with 12 additions and 18 deletions

View file

@ -123,16 +123,10 @@ namespace Geekbot.net.Commands
[Command("modchannel", RunMode = RunMode.Async)] [Command("modchannel", RunMode = RunMode.Async)]
[Remarks(CommandCategories.Admin)] [Remarks(CommandCategories.Admin)]
[Summary("Set a channel for moderation purposes")] [Summary("Set a channel for moderation purposes")]
public async Task selectModChannel([Summary("ChannelId")] ulong channelId) public async Task selectModChannel([Summary("#Channel")] ISocketMessageChannel channel)
{ {
try 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(); var sb = new StringBuilder();
sb.AppendLine("Successfully saved mod channel, you can now do the following"); 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 showleave true` - send message to mod channel when someone leaves");
@ -152,7 +146,7 @@ namespace Geekbot.net.Commands
[Summary("Notify modchannel when someone leaves")] [Summary("Notify modchannel when someone leaves")]
public async Task showLeave([Summary("true/false")] bool enabled) public async Task showLeave([Summary("true/false")] bool enabled)
{ {
var modChannelId = (ulong)_redis.HashGet($"{Context.Guild.Id}:Settings", "ModChannel"); var modChannelId = ulong.Parse(_redis.HashGet($"{Context.Guild.Id}:Settings", "ModChannel"));
try try
{ {
var modChannel = (ISocketMessageChannel) _client.GetChannel(modChannelId); var modChannel = (ISocketMessageChannel) _client.GetChannel(modChannelId);
@ -179,7 +173,7 @@ namespace Geekbot.net.Commands
[Summary("Notify modchannel when someone deletes a message")] [Summary("Notify modchannel when someone deletes a message")]
public async Task showDelete([Summary("true/false")] bool enabled) public async Task showDelete([Summary("true/false")] bool enabled)
{ {
var modChannelId = (ulong)_redis.HashGet($"{Context.Guild.Id}:Settings", "ModChannel"); var modChannelId = ulong.Parse(_redis.HashGet($"{Context.Guild.Id}:Settings", "ModChannel"));
try try
{ {
var modChannel = (ISocketMessageChannel) _client.GetChannel(modChannelId); var modChannel = (ISocketMessageChannel) _client.GetChannel(modChannelId);

View file

@ -69,7 +69,7 @@ namespace Geekbot.net.Commands
} }
if (guildUser.RoleIds.Contains(roleId)) if (guildUser.RoleIds.Contains(roleId))
{ {
guildUser.RemoveRoleAsync(role); await guildUser.RemoveRoleAsync(role);
await ReplyAsync($"Removed you from {role.Name}"); await ReplyAsync($"Removed you from {role.Name}");
return; return;
} }

View file

@ -105,10 +105,10 @@ namespace Geekbot.net
var sendLeftEnabled = _redis.HashGet($"{user.Guild.Id}:Settings", "ShowLeave"); var sendLeftEnabled = _redis.HashGet($"{user.Guild.Id}:Settings", "ShowLeave");
if (sendLeftEnabled.ToString() == "1") if (sendLeftEnabled.ToString() == "1")
{ {
var modChannel = _redis.HashGet($"{user.Guild.Id}:Settings", "ModChannel"); var modChannel = ulong.Parse(_redis.HashGet($"{user.Guild.Id}:Settings", "ModChannel"));
if (!string.IsNullOrEmpty(modChannel)) if (!string.IsNullOrEmpty(modChannel.ToString()))
{ {
var modChannelSocket = (ISocketMessageChannel) await _client.GetChannelAsync((ulong)modChannel); var modChannelSocket = (ISocketMessageChannel) await _client.GetChannelAsync(modChannel);
await modChannelSocket.SendMessageAsync($"{user.Username}#{user.Discriminator} left the server"); await modChannelSocket.SendMessageAsync($"{user.Username}#{user.Discriminator} left the server");
} }
} }
@ -132,15 +132,15 @@ namespace Geekbot.net
var sendLeftEnabled = _redis.HashGet($"{guild.Id}:Settings", "ShowDelete"); var sendLeftEnabled = _redis.HashGet($"{guild.Id}:Settings", "ShowDelete");
if (sendLeftEnabled.ToString() == "1") if (sendLeftEnabled.ToString() == "1")
{ {
var modChannel = _redis.HashGet($"{guild.Id}:Settings", "ModChannel"); var modChannel = ulong.Parse(_redis.HashGet($"{guild.Id}:Settings", "ModChannel"));
if (!string.IsNullOrEmpty(modChannel)) if (!string.IsNullOrEmpty(modChannel.ToString()) && modChannel != channel.Id)
{ {
var modChannelSocket = (ISocketMessageChannel) await _client.GetChannelAsync((ulong)modChannel); var modChannelSocket = (ISocketMessageChannel) await _client.GetChannelAsync(modChannel);
var sb = new StringBuilder(); var sb = new StringBuilder();
if (message.Value != null) if (message.Value != null)
{ {
sb.AppendLine( sb.AppendLine(
$"{message.Value.Author.Username}#{message.Value.Author.Discriminator} deleted the following message from <#{channel.Id}>"); $"The following message from {message.Value.Author.Username}#{message.Value.Author.Discriminator} was deleted in <#{channel.Id}>");
sb.AppendLine(message.Value.Content); sb.AppendLine(message.Value.Content);
} }
else else

View file

@ -182,7 +182,7 @@ namespace Geekbot.net
return true; return true;
} }
private async Task startWebApi() private void startWebApi()
{ {
logger.Information("[API] Starting Webserver"); logger.Information("[API] Starting Webserver");
var webApiUrl = new Uri("http://localhost:12995"); var webApiUrl = new Uri("http://localhost:12995");