diff --git a/NadekoBot/Classes/ServerSpecificConfig.cs b/NadekoBot/Classes/ServerSpecificConfig.cs index 66f43fe1..a8efee5d 100644 --- a/NadekoBot/Classes/ServerSpecificConfig.cs +++ b/NadekoBot/Classes/ServerSpecificConfig.cs @@ -95,6 +95,17 @@ namespace NadekoBot.Classes } } + [JsonIgnore] + private ulong autoAssignedRole = 0; + public ulong AutoAssignedRole { + get { return autoAssignedRole; } + set { + autoAssignedRole = value; + if (!SpecificConfigurations.Instantiated) return; + OnPropertyChanged(); + } + } + [JsonIgnore] private ObservableCollection observingStreams; public ObservableCollection ObservingStreams { diff --git a/NadekoBot/Modules/Administration/AdministrationModule.cs b/NadekoBot/Modules/Administration/AdministrationModule.cs index e3a749d1..42bb0c6f 100644 --- a/NadekoBot/Modules/Administration/AdministrationModule.cs +++ b/NadekoBot/Modules/Administration/AdministrationModule.cs @@ -29,6 +29,7 @@ namespace NadekoBot.Modules.Administration commands.Add(new Remind(this)); commands.Add(new InfoCommands(this)); commands.Add(new CustomReactionsCommands(this)); + commands.Add(new AutoAssignRole(this)); } public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Administration; @@ -910,6 +911,7 @@ namespace NadekoBot.Modules.Administration await e.Channel.SendMessage(":ok:"); }); + }); } diff --git a/NadekoBot/Modules/Administration/Commands/AutoAssignRole.cs b/NadekoBot/Modules/Administration/Commands/AutoAssignRole.cs new file mode 100644 index 00000000..5894e340 --- /dev/null +++ b/NadekoBot/Modules/Administration/Commands/AutoAssignRole.cs @@ -0,0 +1,71 @@ +using Discord.Commands; +using NadekoBot.Classes; +using NadekoBot.Modules.Permissions.Classes; +using System; +using System.Linq; + +namespace NadekoBot.Modules.Administration.Commands +{ + class AutoAssignRole : DiscordCommand + { + public AutoAssignRole(DiscordModule module) : base(module) + { + NadekoBot.Client.UserJoined += (s, e) => + { + try + { + var config = SpecificConfigurations.Default.Of(e.Server.Id); + + var role = e.Server.Roles.Where(r => r.Id == config.AutoAssignedRole).FirstOrDefault(); + + if (role == null) + return; + + e.User.AddRoles(role); + } + catch (Exception ex) + { + Console.WriteLine($"aar exception. {ex}"); + } + }; + } + + internal override void Init(CommandGroupBuilder cgb) + { + cgb.CreateCommand(Module.Prefix + "aar") + .Alias(Module.Prefix + "autoassignrole") + .Description($"Automaticaly assigns a specified role to every user who joins the server. Type `.aar` to disable, `.aar Role Name` to enable") + .Parameter("role", ParameterType.Unparsed) + .AddCheck(new SimpleCheckers.ManageRoles()) + .Do(async e => + { + if (!e.Server.CurrentUser.ServerPermissions.ManageRoles) + { + await e.Channel.SendMessage("I do not have the permission to manage roles."); + } + var r = e.GetArg("role")?.Trim(); + + var config = SpecificConfigurations.Default.Of(e.Server.Id); + + if (string.IsNullOrWhiteSpace(r)) //if role is not specified, disable + { + config.AutoAssignedRole = 0; + + await e.Channel.SendMessage("`Auto assign role on user join is now disabled.`"); + return; + } + var role = e.Server.FindRoles(r).FirstOrDefault(); + + if (role == null) + { + await e.Channel.SendMessage("💢 `Role not found.`"); + return; + } + + config.AutoAssignedRole = role.Id; + await e.Channel.SendMessage("`Auto assigned role is set.`"); + + }); + } + } +} diff --git a/NadekoBot/NadekoBot.csproj b/NadekoBot/NadekoBot.csproj index d9923776..4ccc018f 100644 --- a/NadekoBot/NadekoBot.csproj +++ b/NadekoBot/NadekoBot.csproj @@ -120,6 +120,7 @@ + diff --git a/NadekoBot/bin/Debug/data/config_example.json b/NadekoBot/bin/Debug/data/config_example.json index 09fe148d..87fb3c50 100644 --- a/NadekoBot/bin/Debug/data/config_example.json +++ b/NadekoBot/bin/Debug/data/config_example.json @@ -2,6 +2,7 @@ "DontJoinServers": false, "ForwardMessages": true, "IsRotatingStatus": false, + "RemindMessageFormat": "❗⏰**I've been told to remind you to '%message%' now by %user%.**⏰❗", "CustomReactions": { "\\o\\": [ "/o/"