Adds bedtime command
This commit is contained in:
parent
9fd8908ffe
commit
1493480a66
|
@ -141,24 +141,6 @@ namespace DeukBot4.MessageHandlers.CommandHandler
|
|||
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;
|
||||
if (request.Parameters.Length == 1)
|
||||
{
|
||||
|
@ -191,11 +173,47 @@ namespace DeukBot4.MessageHandlers.CommandHandler
|
|||
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)
|
||||
span = TimeSpan.FromMinutes(5);
|
||||
await Task.Delay(span);
|
||||
await user.RemoveRoleAsync(silencedRole);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue