NadekoBot/NadekoBot.Core/Modules/Administration/AutoAssignRoleCommands.cs

47 lines
1.5 KiB
C#
Raw Normal View History

2016-08-24 22:39:02 +00:00
using Discord;
using Discord.Commands;
using NadekoBot.Extensions;
using NadekoBot.Core.Services;
2016-08-24 22:39:02 +00:00
using System.Linq;
using System.Threading.Tasks;
2017-07-17 19:42:36 +00:00
using NadekoBot.Common.Attributes;
using NadekoBot.Modules.Administration.Services;
2016-08-24 22:39:02 +00:00
namespace NadekoBot.Modules.Administration
{
public partial class Administration
{
[Group]
2017-07-15 16:34:34 +00:00
public class AutoAssignRoleCommands : NadekoSubmodule<AutoAssignRoleService>
2016-08-24 22:39:02 +00:00
{
private readonly DbService _db;
2016-10-18 01:03:46 +00:00
2017-07-15 16:34:34 +00:00
public AutoAssignRoleCommands(DbService db)
2016-08-24 22:39:02 +00:00
{
_db = db;
2016-08-24 22:39:02 +00:00
}
[NadekoCommand, Usage, Description, Aliases]
2016-08-24 22:39:02 +00:00
[RequireContext(ContextType.Guild)]
2016-12-16 18:43:57 +00:00
[RequireUserPermission(GuildPermission.ManageRoles)]
public async Task AutoAssignRole([Remainder] IRole role = null)
2016-08-24 22:39:02 +00:00
{
var guser = (IGuildUser)Context.User;
if (role != null)
if (Context.User.Id != guser.Guild.OwnerId && guser.GetRoles().Max(x => x.Position) <= role.Position)
return;
2016-08-24 22:39:02 +00:00
if (role == null)
{
_service.DisableAar(Context.Guild.Id);
2017-02-14 15:55:59 +00:00
await ReplyConfirmLocalized("aar_disabled").ConfigureAwait(false);
2016-08-24 22:39:02 +00:00
return;
}
_service.EnableAar(Context.Guild.Id, role.Id);
2017-02-14 15:55:59 +00:00
await ReplyConfirmLocalized("aar_enabled").ConfigureAwait(false);
2016-08-24 22:39:02 +00:00
}
}
}
}