From e28c705bfd96c33d6a88d33ff1fba55156fcef63 Mon Sep 17 00:00:00 2001 From: appelemac Date: Sun, 17 Jul 2016 20:42:41 +0200 Subject: [PATCH] sat --- NadekoBot/Classes/ServerSpecificConfig.cs | 15 +++++++++++++++ .../Commands/SelfAssignedRolesCommand.cs | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/NadekoBot/Classes/ServerSpecificConfig.cs b/NadekoBot/Classes/ServerSpecificConfig.cs index e7e7437e..b1458f37 100644 --- a/NadekoBot/Classes/ServerSpecificConfig.cs +++ b/NadekoBot/Classes/ServerSpecificConfig.cs @@ -97,6 +97,8 @@ namespace NadekoBot.Classes } } + + [JsonIgnore] private ulong autoAssignedRole = 0; public ulong AutoAssignedRole { @@ -122,6 +124,19 @@ namespace NadekoBot.Classes } } + [JsonIgnore] + private bool exclusiveSelfAssignedRoles = false; + public bool ExclusiveSelfAssignedRoles + { + get { return exclusiveSelfAssignedRoles; } + set + { + exclusiveSelfAssignedRoles = value; + if (!SpecificConfigurations.Instantiated) return; + OnPropertyChanged(); + } + } + public ObservableCollection ObservingStreams { get { return observingStreams; } set { diff --git a/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs b/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs index eaf59a3a..328d244b 100644 --- a/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs +++ b/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs @@ -94,6 +94,19 @@ namespace NadekoBot.Modules.Administration.Commands await e.Channel.SendMessage(msg.ToString()).ConfigureAwait(false); }); + + + cgb.CreateCommand(Module.Prefix + "togglexclsar").Alias(Module.Prefix +"tesar") + .Description("toggle whether the self-assigned roles should be exclusive") + .AddCheck(SimpleCheckers.CanManageRoles) + .Do(async e => + { + var config = SpecificConfigurations.Default.Of(e.Server.Id); + config.ExclusiveSelfAssignedRoles = !config.ExclusiveSelfAssignedRoles; + string exl = config.ExclusiveSelfAssignedRoles ? "exclusive" : "not exclusive"; + await e.Channel.SendMessage("Self assigned roles are now " + exl); + }); + cgb.CreateCommand(Module.Prefix + "iam") .Description("Adds a role to you that you choose. " + "Role must be on a list of self-assignable roles." + @@ -121,6 +134,12 @@ namespace NadekoBot.Modules.Administration.Commands await e.Channel.SendMessage($":anger:You already have {role.Name} role.").ConfigureAwait(false); return; } + var sameRoles = e.User.Roles.Where(r => config.ListOfSelfAssignableRoles.Contains(r.Id)); + if (config.ExclusiveSelfAssignedRoles && sameRoles.Any()) + { + await e.Channel.SendMessage($":anger:You already have {sameRoles.FirstOrDefault().Name} role.").ConfigureAwait(false); + return; + } try { await e.User.AddRoles(role).ConfigureAwait(false);