Added auto assigned role on user join. (.aar)
This commit is contained in:
parent
d722e02f39
commit
f507650dde
@ -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<StreamNotificationConfig> observingStreams;
|
||||
public ObservableCollection<StreamNotificationConfig> ObservingStreams {
|
||||
|
@ -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:");
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
71
NadekoBot/Modules/Administration/Commands/AutoAssignRole.cs
Normal file
71
NadekoBot/Modules/Administration/Commands/AutoAssignRole.cs
Normal file
@ -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.`");
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -120,6 +120,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Modules\Administration\Commands\AutoAssignRole.cs" />
|
||||
<Compile Include="Modules\Administration\Commands\CustomReactionsCommands.cs" />
|
||||
<Compile Include="Modules\ClashOfClans\ClashOfClans.cs" />
|
||||
<Compile Include="Classes\DBHandler.cs" />
|
||||
|
@ -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/"
|
||||
|
Loading…
Reference in New Issue
Block a user