Auto assign roles
This commit is contained in:
@@ -15,7 +15,6 @@ using NadekoBot.Services.Database;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
//todo fix delmsgoncmd
|
||||
//todo DB
|
||||
namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
[Module(".", AppendSpace = false)]
|
||||
@@ -47,9 +46,9 @@ namespace NadekoBot.Modules.Administration
|
||||
Config conf;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
conf = uow.Configs.For(channel.Guild.Id);
|
||||
conf = uow.GuildConfigs.For(channel.Guild.Id);
|
||||
conf.DeleteMessageOnCommand = !conf.DeleteMessageOnCommand;
|
||||
uow.Configs.Update(conf);
|
||||
uow.GuildConfigs.Update(conf);
|
||||
await uow.CompleteAsync();
|
||||
}
|
||||
if (conf.DeleteMessageOnCommand)
|
||||
@@ -381,8 +380,8 @@ namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
//todo actually print info about created channel
|
||||
await channel.Guild.CreateVoiceChannelAsync(channelName).ConfigureAwait(false);
|
||||
await channel.SendMessageAsync($"Created voice channel **{channelName}**.").ConfigureAwait(false);
|
||||
var ch = await channel.Guild.CreateVoiceChannelAsync(channelName).ConfigureAwait(false);
|
||||
await channel.SendMessageAsync($"Created voice channel **{ch.Name}**, id `{ch.Id}`.").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
||||
@@ -391,7 +390,7 @@ namespace NadekoBot.Modules.Administration
|
||||
public async Task DelTxtChanl(IMessage imsg, [Remainder] ITextChannel channel)
|
||||
{
|
||||
await channel.DeleteAsync().ConfigureAwait(false);
|
||||
await channel.SendMessageAsync($"Removed text channel **{channel.Name}**.").ConfigureAwait(false);
|
||||
await channel.SendMessageAsync($"Removed text channel **{channel.Name}**, id `{channel.Id}`.").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
||||
@@ -402,7 +401,7 @@ namespace NadekoBot.Modules.Administration
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
//todo actually print info about created channel
|
||||
var txtCh = await channel.Guild.CreateTextChannelAsync(channelName).ConfigureAwait(false);
|
||||
await channel.SendMessageAsync($"Added text channel **{channelName}**.").ConfigureAwait(false);
|
||||
await channel.SendMessageAsync($"Added text channel **{txtCh.Name}**, id `{txtCh.Id}`.").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
||||
@@ -413,7 +412,6 @@ namespace NadekoBot.Modules.Administration
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
topic = topic ?? "";
|
||||
await (channel as ITextChannel).ModifyAsync(c => c.Topic = topic);
|
||||
//await (channel).ModifyAsync(c => c).ConfigureAwait(false);
|
||||
await channel.SendMessageAsync(":ok: **New channel topic set.**").ConfigureAwait(false);
|
||||
|
||||
}
|
@@ -1,54 +0,0 @@
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Attributes;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
//todo DB
|
||||
public partial class Administration
|
||||
{
|
||||
[Group]
|
||||
public class AutoAssignRole
|
||||
{
|
||||
public AutoAssignRole()
|
||||
{
|
||||
var _client = NadekoBot.Client;
|
||||
_client.UserJoined += (user) =>
|
||||
{
|
||||
//var config = SpecificConfigurations.Default.Of(e.Server.Id);
|
||||
|
||||
//var role = e.Server.Roles.Where(r => r.Id == config.AutoAssignedRole).FirstOrDefault();
|
||||
|
||||
//if (role == null)
|
||||
// return;
|
||||
|
||||
//imsg.Author.AddRoles(role);
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
}
|
||||
|
||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
//[RequirePermission(GuildPermission.ManageRoles)]
|
||||
//public async Task AutoAssignRole(IMessage imsg, IRole role)
|
||||
//{
|
||||
// var channel = (ITextChannel)imsg.Channel;
|
||||
|
||||
// var config = SpecificConfigurations.Default.Of(e.Server.Id);
|
||||
|
||||
// if (string.IsNullOrWhiteSpace(r)) //if role is not specified, disable
|
||||
// {
|
||||
// config.AutoAssignedRole = 0;
|
||||
|
||||
// await channel.SendMessageAsync("`Auto assign role on user join is now disabled.`").ConfigureAwait(false);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// config.AutoAssignedRole = role.Id;
|
||||
// await channel.SendMessageAsync("`Auto assigned role is set.`").ConfigureAwait(false);
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,71 @@
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Attributes;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
public partial class Administration
|
||||
{
|
||||
[Group]
|
||||
public class AutoAssignRoleCommands
|
||||
{
|
||||
public AutoAssignRoleCommands()
|
||||
{
|
||||
var _client = NadekoBot.Client;
|
||||
_client.UserJoined += async (user) =>
|
||||
{
|
||||
Config conf;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
conf = uow.GuildConfigs.For(user.Guild.Id);
|
||||
}
|
||||
var aarType = conf.AutoAssignRoleId.GetType();
|
||||
|
||||
if (conf.AutoAssignRoleId == 0)
|
||||
return;
|
||||
|
||||
var role = user.Guild.Roles.Where(r => r.Id == conf.AutoAssignRoleId).FirstOrDefault();
|
||||
|
||||
if (role != null)
|
||||
await user.AddRolesAsync(role);
|
||||
};
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[RequirePermission(GuildPermission.ManageRoles)]
|
||||
public async Task AutoAssignRole(IMessage imsg, [Remainder] IRole role = null)
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
|
||||
Config conf;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
conf = uow.GuildConfigs.For(channel.Guild.Id);
|
||||
if (role == null)
|
||||
conf.AutoAssignRoleId = 0;
|
||||
else
|
||||
conf.AutoAssignRoleId = role.Id;
|
||||
|
||||
uow.GuildConfigs.Update(conf);
|
||||
await uow.CompleteAsync();
|
||||
}
|
||||
|
||||
if (role == null)
|
||||
{
|
||||
await channel.SendMessageAsync("`Auto assign role on user join is now disabled.`").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
await channel.SendMessageAsync("`Auto assigned role is set.`").ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user