More permission stuff. MovePerm doesn't work, RemovePerm works, permission fixes.
This commit is contained in:
@@ -60,7 +60,7 @@ namespace NadekoBot.Modules.Administration
|
||||
}, null, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10));
|
||||
|
||||
|
||||
_client.MessageReceived += _client_MessageReceived;
|
||||
//_client.MessageReceived += _client_MessageReceived;
|
||||
_client.MessageUpdated += _client_MessageUpdated;
|
||||
_client.MessageDeleted += _client_MessageDeleted;
|
||||
_client.UserBanned += _client_UserBanned;
|
||||
@@ -408,37 +408,37 @@ namespace NadekoBot.Modules.Administration
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private Task _client_MessageReceived(IMessage imsg)
|
||||
{
|
||||
var msg = imsg as IUserMessage;
|
||||
if (msg == null || msg.IsAuthor())
|
||||
return Task.CompletedTask;
|
||||
// private Task _client_MessageReceived(IMessage imsg)
|
||||
// {
|
||||
// var msg = imsg as IUserMessage;
|
||||
// if (msg == null || msg.IsAuthor())
|
||||
// return Task.CompletedTask;
|
||||
|
||||
var channel = msg.Channel as ITextChannel;
|
||||
if (channel == null)
|
||||
return Task.CompletedTask;
|
||||
// var channel = msg.Channel as ITextChannel;
|
||||
// if (channel == null)
|
||||
// return Task.CompletedTask;
|
||||
|
||||
LogSetting logSetting;
|
||||
if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting)
|
||||
|| !logSetting.IsLogging
|
||||
|| !logSetting.MessageReceived)
|
||||
return Task.CompletedTask;
|
||||
// LogSetting logSetting;
|
||||
// if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting)
|
||||
// || !logSetting.IsLogging
|
||||
// || !logSetting.MessageReceived)
|
||||
// return Task.CompletedTask;
|
||||
|
||||
ITextChannel logChannel;
|
||||
if ((logChannel = TryGetLogChannel(channel.Guild, logSetting)) == null || logChannel.Id == imsg.Channel.Id)
|
||||
return Task.CompletedTask;
|
||||
// ITextChannel logChannel;
|
||||
// if ((logChannel = TryGetLogChannel(channel.Guild, logSetting)) == null || logChannel.Id == imsg.Channel.Id)
|
||||
// return Task.CompletedTask;
|
||||
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
var str = $@"🕔`{prettyCurrentTime}` **New Message** `#{channel.Name}`
|
||||
👤`{msg.Author.Username}`: {msg.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator)}";
|
||||
if (msg.Attachments.Any())
|
||||
str += $"{Environment.NewLine}`Attachements`: {string.Join(", ", msg.Attachments.Select(a => a.ProxyUrl))}";
|
||||
await logChannel.SendMessageAsync(str).ConfigureAwait(false);
|
||||
});
|
||||
// var task = Task.Run(async () =>
|
||||
// {
|
||||
// var str = $@"🕔`{prettyCurrentTime}` **New Message** `#{channel.Name}`
|
||||
//👤`{msg.Author.Username}`: {msg.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator)}";
|
||||
// if (msg.Attachments.Any())
|
||||
// str += $"{Environment.NewLine}`Attachements`: {string.Join(", ", msg.Attachments.Select(a => a.ProxyUrl))}";
|
||||
// await logChannel.SendMessageAsync(str).ConfigureAwait(false);
|
||||
// });
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
// return Task.CompletedTask;
|
||||
// }
|
||||
|
||||
private enum LogChannelType { Text, Voice, UserPresence };
|
||||
private ITextChannel TryGetLogChannel(IGuild guild, LogSetting logSetting, LogChannelType logChannelType = LogChannelType.Text)
|
||||
|
@@ -46,6 +46,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
//todo merge into internallDndRoll and internalRoll
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[Priority(1)]
|
||||
public async Task Roll(IUserMessage umsg, string arg)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
@@ -76,6 +77,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[Priority(2)]
|
||||
public async Task Roll(IUserMessage umsg, int num)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
|
@@ -20,6 +20,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
|
||||
public static bool CheckPermissions(this IEnumerable<Permission> permsEnumerable, IUserMessage message, Command command, out int permIndex)
|
||||
{
|
||||
permsEnumerable = permsEnumerable.Reverse();
|
||||
var perms = permsEnumerable as List<Permission> ?? permsEnumerable.ToList();
|
||||
|
||||
for (int i = 0; i < perms.Count; i++)
|
||||
@@ -107,7 +108,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
com = "a" + com + "m";
|
||||
break;
|
||||
}
|
||||
com += " " + perm.SecondaryTargetName + " " + (perm.State ? "enable" : "disable") + " ";
|
||||
com += " " + (perm.SecondaryTargetName != "*" ? perm.SecondaryTargetName + " " : "") + (perm.State ? "enable" : "disable") + " ";
|
||||
|
||||
switch (perm.PrimaryTarget)
|
||||
{
|
||||
|
@@ -10,6 +10,7 @@ using NadekoBot.Services;
|
||||
using Discord;
|
||||
using NadekoBot.Services.Database;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using Discord.API;
|
||||
|
||||
namespace NadekoBot.Modules.Permissions
|
||||
{
|
||||
@@ -29,7 +30,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
string toSend = "";
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
var perms = uow.GuildConfigs.For(channel.Guild.Id).Permissions;
|
||||
var perms = uow.GuildConfigs.For(channel.Guild.Id).Permissions.AsEnumerable().Reverse();
|
||||
|
||||
var i = 1;
|
||||
toSend = String.Join("\n", perms.Select(p => $"`{(i++)}.` {p.GetCommand()}"));
|
||||
@@ -41,6 +42,61 @@ namespace NadekoBot.Modules.Permissions
|
||||
await channel.SendMessageAsync(toSend).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task RemovePerm(IUserMessage imsg, int index)
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
try
|
||||
{
|
||||
Permission p;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
var perms = uow.GuildConfigs.For(channel.Guild.Id).Permissions.AsEnumerable().ToList();
|
||||
p = perms[perms.Count - index];
|
||||
perms.RemoveAt(perms.Count - index);
|
||||
uow.GuildConfigs.For(channel.Guild.Id).Permissions = perms;
|
||||
await uow.CompleteAsync().ConfigureAwait(false);
|
||||
}
|
||||
await channel.SendMessageAsync($"`Removed permission \"{p.GetCommand()}\" from position #{index}.`").ConfigureAwait(false);
|
||||
}
|
||||
catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
await channel.SendMessageAsync("`No command on that index found.`").ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task MovePerm(IUserMessage imsg, int from, int to)
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
if (!(from == to || from < 1 || to < 1))
|
||||
{
|
||||
try
|
||||
{
|
||||
Permission toInsert;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
var perms = uow.GuildConfigs.For(channel.Guild.Id).Permissions.AsEnumerable().ToList();
|
||||
toInsert = perms[perms.Count - from];
|
||||
perms.RemoveAt(perms.Count - from);
|
||||
uow.GuildConfigs.For(channel.Guild.Id).Permissions = perms;
|
||||
if (from < to)
|
||||
to -= 1;
|
||||
perms.Insert(perms.Count - to, toInsert);
|
||||
await uow.CompleteAsync().ConfigureAwait(false);
|
||||
}
|
||||
await channel.SendMessageAsync($"`Moved permission \"{toInsert.GetCommand()}\" from #{from} to #{to}.`").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
catch (Exception e) when (e is ArgumentOutOfRangeException || e is IndexOutOfRangeException)
|
||||
{
|
||||
}
|
||||
}
|
||||
await channel.SendMessageAsync("`Invalid index(es) specified.`").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task UsrCmd(IUserMessage imsg, Command command, PermissionAction action, IGuildUser user)
|
||||
@@ -211,7 +267,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task AllUserMdls(IUserMessage imsg, PermissionAction action, IUser user)
|
||||
public async Task AllUsrMdls(IUserMessage imsg, PermissionAction action, IUser user)
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
|
||||
@@ -242,7 +298,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
{
|
||||
PrimaryTarget = PrimaryPermissionType.Channel,
|
||||
PrimaryTargetId = chnl.Id,
|
||||
SecondaryTarget = SecondaryPermissionType.Command,
|
||||
SecondaryTarget = SecondaryPermissionType.AllCommands,
|
||||
SecondaryTargetName = module.Name.ToLowerInvariant(),
|
||||
State = action.Value,
|
||||
});
|
||||
@@ -274,7 +330,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task AllUserCmds(IUserMessage imsg, Module module, PermissionAction action, IUser user)
|
||||
public async Task AllUsrCmds(IUserMessage imsg, Module module, PermissionAction action, IUser user)
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
|
||||
|
Reference in New Issue
Block a user