Adds bedtime command

This commit is contained in:
Deukhoofd 2018-10-22 10:49:07 +02:00
parent 9fd8908ffe
commit 1493480a66
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
1 changed files with 36 additions and 18 deletions

View File

@ -141,24 +141,6 @@ namespace DeukBot4.MessageHandlers.CommandHandler
return; return;
} }
var silencedRoleId = ServerSettingHandler.GetSettings(channel.GuildId).MutedRoleId;
if (silencedRoleId == 0)
{
await request.SendMessageAsync(
"No silenced role has been set. The server owner should do ``!silencedrole {role id}`` to set one first.");
return;
}
var silencedRole = channel.Guild.GetRole(silencedRoleId);
if (silencedRole == null)
{
await request.SendSimpleEmbed( "Silence",
"Can't find the silenced role. Has it been deleted?");
return;
}
await user.AddRoleAsync(silencedRole);
TimeSpan span; TimeSpan span;
if (request.Parameters.Length == 1) if (request.Parameters.Length == 1)
{ {
@ -191,11 +173,47 @@ namespace DeukBot4.MessageHandlers.CommandHandler
return; return;
} }
} }
var msg = await SilenceUser(user, span);
if (msg != null)
{
request.SendSimpleEmbed("Silence", msg);
}
}
[Command("bedtime", PermissionLevel.Helper)]
[CommandParameters(ParameterMatcher.ParameterType.User)]
[BlockUsageInPm, RequireParameterMatch]
public async Task Bedtime(CommandRequest request)
{
var guildChannel = (IGuildChannel)request.OriginalMessage.Channel;
var user = await request.Parameters[0].AsDiscordGuildUser(guildChannel.Guild);
var msg = await SilenceUser(user, TimeSpan.FromHours(6));
if (msg != null)
{
request.SendSimpleEmbed("Silence", msg);
}
}
private async Task<string> SilenceUser(IGuildUser user, TimeSpan span)
{
var silencedRoleId = ServerSettingHandler.GetSettings(user.GuildId).MutedRoleId;
if (silencedRoleId == 0)
{
return
"No silenced role has been set. The server owner should do ``!silencedrole {role id}`` to set one first.";
}
var silencedRole = user.Guild.GetRole(silencedRoleId);
if (silencedRole == null)
{
return "Can't find the silenced role. Has it been deleted?";
}
await user.AddRoleAsync(silencedRole);
if (span.Seconds <= 0) if (span.Seconds <= 0)
span = TimeSpan.FromMinutes(5); span = TimeSpan.FromMinutes(5);
await Task.Delay(span); await Task.Delay(span);
await user.RemoveRoleAsync(silencedRole); await user.RemoveRoleAsync(silencedRole);
return null;
} }
} }
} }