From 597b73d38c5c879aba4db74e341339ab24483872 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Mon, 26 Sep 2016 19:23:01 +0200 Subject: [PATCH] More permission stuff. MovePerm doesn't work, RemovePerm works, permission fixes. --- .../20160926144107_second.Designer.cs | 587 ++++++++++++++++++ .../Migrations/20160926144107_second.cs | 19 + .../Administration/Commands/LogCommand.cs | 54 +- .../Gambling/Commands/DiceRollCommand.cs | 2 + .../Permissions/PermissionExtensions.cs | 3 +- .../Modules/Permissions/Permissions.cs | 64 +- .../Resources/CommandStrings.Designer.cs | 108 ++++ src/NadekoBot/Resources/CommandStrings.resx | 36 ++ src/NadekoBot/Services/CommandHandler.cs | 2 +- .../Services/Database/Models/GuildConfig.cs | 2 +- 10 files changed, 843 insertions(+), 34 deletions(-) create mode 100644 src/NadekoBot/Migrations/20160926144107_second.Designer.cs create mode 100644 src/NadekoBot/Migrations/20160926144107_second.cs diff --git a/src/NadekoBot/Migrations/20160926144107_second.Designer.cs b/src/NadekoBot/Migrations/20160926144107_second.Designer.cs new file mode 100644 index 00000000..095ee7cf --- /dev/null +++ b/src/NadekoBot/Migrations/20160926144107_second.Designer.cs @@ -0,0 +1,587 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using NadekoBot.Services.Database.Impl; + +namespace NadekoBot.Migrations +{ + [DbContext(typeof(NadekoSqliteContext))] + [Migration("20160926144107_second")] + partial class second + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.0.0-rtm-21431"); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.BlacklistItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BotConfigId"); + + b.Property("ItemId"); + + b.HasKey("Id"); + + b.HasIndex("BotConfigId"); + + b.ToTable("BlacklistItem"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.BotConfig", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BufferSize"); + + b.Property("CurrencyGenerationChance"); + + b.Property("CurrencyGenerationCooldown"); + + b.Property("CurrencyName"); + + b.Property("CurrencyPluralName"); + + b.Property("CurrencySign"); + + b.Property("DontJoinServers"); + + b.Property("ForwardMessages"); + + b.Property("ForwardToAllOwners"); + + b.Property("RemindMessageFormat"); + + b.Property("RotatingStatuses"); + + b.HasKey("Id"); + + b.ToTable("BotConfig"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.ClashCaller", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BaseDestroyed"); + + b.Property("CallUser"); + + b.Property("ClashWarId"); + + b.Property("Stars"); + + b.Property("TimeAdded"); + + b.HasKey("Id"); + + b.HasIndex("ClashWarId"); + + b.ToTable("ClashCallers"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.ClashWar", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ChannelId"); + + b.Property("EnemyClan"); + + b.Property("GuildId"); + + b.Property("Size"); + + b.Property("StartedAt"); + + b.Property("WarState"); + + b.HasKey("Id"); + + b.ToTable("ClashOfClans"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.ConvertUnit", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("InternalTrigger"); + + b.Property("Modifier"); + + b.Property("UnitType"); + + b.HasKey("Id"); + + b.ToTable("ConversionUnits"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.Currency", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Amount"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("Currency"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.Donator", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Amount"); + + b.Property("Name"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("Donators"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.EightBallResponse", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BotConfigId"); + + b.Property("Text"); + + b.HasKey("Id"); + + b.HasIndex("BotConfigId"); + + b.ToTable("EightBallResponses"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.FollowedStream", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ChannelId"); + + b.Property("GuildConfigId"); + + b.Property("GuildId"); + + b.Property("LastStatus"); + + b.Property("Type"); + + b.Property("Username"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.ToTable("FollowedStream"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.GuildConfig", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AutoAssignRoleId"); + + b.Property("AutoDeleteByeMessages"); + + b.Property("AutoDeleteGreetMessages"); + + b.Property("AutoDeleteGreetMessagesTimer"); + + b.Property("AutoDeleteSelfAssignedRoleMessages"); + + b.Property("ByeMessageChannelId"); + + b.Property("ChannelByeMessageText"); + + b.Property("ChannelGreetMessageText"); + + b.Property("DefaultMusicVolume"); + + b.Property("DeleteMessageOnCommand"); + + b.Property("DmGreetMessageText"); + + b.Property("ExclusiveSelfAssignedRoles"); + + b.Property("GenerateCurrencyChannelId"); + + b.Property("GreetMessageChannelId"); + + b.Property("GuildId"); + + b.Property("LogSettingId"); + + b.Property("SendChannelByeMessage"); + + b.Property("SendChannelGreetMessage"); + + b.Property("SendDmGreetMessage"); + + b.Property("VoicePlusTextEnabled"); + + b.HasKey("Id"); + + b.HasIndex("GuildId") + .IsUnique(); + + b.HasIndex("LogSettingId"); + + b.ToTable("GuildConfigs"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredLogChannel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ChannelId"); + + b.Property("LogSettingId"); + + b.HasKey("Id"); + + b.HasIndex("LogSettingId"); + + b.ToTable("IgnoredLogChannels"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredVoicePresenceChannel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ChannelId"); + + b.Property("LogSettingId"); + + b.HasKey("Id"); + + b.HasIndex("LogSettingId"); + + b.ToTable("IgnoredVoicePresenceCHannels"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.LogSetting", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ChannelCreated"); + + b.Property("ChannelDestroyed"); + + b.Property("ChannelId"); + + b.Property("ChannelUpdated"); + + b.Property("IsLogging"); + + b.Property("LogUserPresence"); + + b.Property("LogVoicePresence"); + + b.Property("MessageDeleted"); + + b.Property("MessageReceived"); + + b.Property("MessageUpdated"); + + b.Property("UserBanned"); + + b.Property("UserJoined"); + + b.Property("UserLeft"); + + b.Property("UserPresenceChannelId"); + + b.Property("UserUnbanned"); + + b.Property("UserUpdated"); + + b.Property("VoicePresenceChannelId"); + + b.HasKey("Id"); + + b.ToTable("LogSettings"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BotConfigId"); + + b.Property("ModuleName"); + + b.Property("Prefix"); + + b.HasKey("Id"); + + b.HasIndex("BotConfigId"); + + b.ToTable("ModulePrefixes"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.Permission", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("GuildConfigId"); + + b.Property("PrimaryTarget"); + + b.Property("PrimaryTargetId"); + + b.Property("SecondaryTarget"); + + b.Property("SecondaryTargetName"); + + b.Property("State"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.ToTable("Permission"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.PlayingStatus", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BotConfigId"); + + b.Property("Status"); + + b.HasKey("Id"); + + b.HasIndex("BotConfigId"); + + b.ToTable("PlayingStatus"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.Quote", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AuthorId"); + + b.Property("AuthorName") + .IsRequired(); + + b.Property("GuildId"); + + b.Property("Keyword") + .IsRequired(); + + b.Property("Text") + .IsRequired(); + + b.HasKey("Id"); + + b.ToTable("Quotes"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.RaceAnimal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BotConfigId"); + + b.Property("Icon"); + + b.Property("Name"); + + b.HasKey("Id"); + + b.HasIndex("BotConfigId"); + + b.ToTable("RaceAnimals"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.Reminder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ChannelId"); + + b.Property("IsPrivate"); + + b.Property("Message"); + + b.Property("ServerId"); + + b.Property("UserId"); + + b.Property("When"); + + b.HasKey("Id"); + + b.ToTable("Reminders"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.Repeater", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ChannelId"); + + b.Property("GuildId"); + + b.Property("Interval"); + + b.Property("Message"); + + b.HasKey("Id"); + + b.HasIndex("ChannelId") + .IsUnique(); + + b.ToTable("Repeaters"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.SelfAssignedRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("GuildId"); + + b.Property("RoleId"); + + b.HasKey("Id"); + + b.HasIndex("GuildId", "RoleId") + .IsUnique(); + + b.ToTable("SelfAssignableRoles"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.TypingArticle", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Author"); + + b.Property("Text"); + + b.HasKey("Id"); + + b.ToTable("TypingArticles"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.BlacklistItem", b => + { + b.HasOne("NadekoBot.Services.Database.Models.BotConfig") + .WithMany("Blacklist") + .HasForeignKey("BotConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.ClashCaller", b => + { + b.HasOne("NadekoBot.Services.Database.Models.ClashWar", "ClashWar") + .WithMany("Bases") + .HasForeignKey("ClashWarId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.EightBallResponse", b => + { + b.HasOne("NadekoBot.Services.Database.Models.BotConfig") + .WithMany("EightBallResponses") + .HasForeignKey("BotConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.FollowedStream", b => + { + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + .WithMany("FollowedStreams") + .HasForeignKey("GuildConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.GuildConfig", b => + { + b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting") + .WithMany() + .HasForeignKey("LogSettingId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredLogChannel", b => + { + b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting") + .WithMany("IgnoredChannels") + .HasForeignKey("LogSettingId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredVoicePresenceChannel", b => + { + b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting") + .WithMany("IgnoredVoicePresenceChannelIds") + .HasForeignKey("LogSettingId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b => + { + b.HasOne("NadekoBot.Services.Database.Models.BotConfig", "BotConfig") + .WithMany("ModulePrefixes") + .HasForeignKey("BotConfigId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.Permission", b => + { + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + .WithMany("Permissions") + .HasForeignKey("GuildConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.PlayingStatus", b => + { + b.HasOne("NadekoBot.Services.Database.Models.BotConfig") + .WithMany("RotatingStatusMessages") + .HasForeignKey("BotConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.RaceAnimal", b => + { + b.HasOne("NadekoBot.Services.Database.Models.BotConfig") + .WithMany("RaceAnimals") + .HasForeignKey("BotConfigId"); + }); + } + } +} diff --git a/src/NadekoBot/Migrations/20160926144107_second.cs b/src/NadekoBot/Migrations/20160926144107_second.cs new file mode 100644 index 00000000..e79f9421 --- /dev/null +++ b/src/NadekoBot/Migrations/20160926144107_second.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace NadekoBot.Migrations +{ + public partial class second : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs index e04b9a46..d9fd3d58 100644 --- a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs @@ -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) diff --git a/src/NadekoBot/Modules/Gambling/Commands/DiceRollCommand.cs b/src/NadekoBot/Modules/Gambling/Commands/DiceRollCommand.cs index 10972871..24e2b4c5 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/DiceRollCommand.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/DiceRollCommand.cs @@ -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; diff --git a/src/NadekoBot/Modules/Permissions/PermissionExtensions.cs b/src/NadekoBot/Modules/Permissions/PermissionExtensions.cs index bb131b14..30996f05 100644 --- a/src/NadekoBot/Modules/Permissions/PermissionExtensions.cs +++ b/src/NadekoBot/Modules/Permissions/PermissionExtensions.cs @@ -20,6 +20,7 @@ namespace NadekoBot.Modules.Permissions public static bool CheckPermissions(this IEnumerable permsEnumerable, IUserMessage message, Command command, out int permIndex) { + permsEnumerable = permsEnumerable.Reverse(); var perms = permsEnumerable as List ?? 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) { diff --git a/src/NadekoBot/Modules/Permissions/Permissions.cs b/src/NadekoBot/Modules/Permissions/Permissions.cs index d35c8810..cccbc0c1 100644 --- a/src/NadekoBot/Modules/Permissions/Permissions.cs +++ b/src/NadekoBot/Modules/Permissions/Permissions.cs @@ -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; diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index 8f4f90f4..ffa02391 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -383,6 +383,60 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to Sets permission for all commands from a module for a specific user.. + /// + public static string allusrcmds_desc { + get { + return ResourceManager.GetString("allusrcmds_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `;auc Searches disable @Someone`. + /// + public static string allusrcmds_summary { + get { + return ResourceManager.GetString("allusrcmds_summary", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to allusrcmds auc. + /// + public static string allusrcmds_text { + get { + return ResourceManager.GetString("allusrcmds_text", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Sets permission for all modules for a specific user.. + /// + public static string allusrmdls_desc { + get { + return ResourceManager.GetString("allusrmdls_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `;aum enable @someone`. + /// + public static string allusrmdls_summary { + get { + return ResourceManager.GetString("allusrmdls_summary", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to allusrmdls aum. + /// + public static string allusrmdls_text { + get { + return ResourceManager.GetString("allusrmdls_text", resourceCulture); + } + } + /// /// Looks up a localized string similar to Queries anilist for an anime and shows the first result.. /// @@ -4271,6 +4325,33 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to Moves permission from one position to another.. + /// + public static string moveperm_desc { + get { + return ResourceManager.GetString("moveperm_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `;mp 2 4`. + /// + public static string moveperm_summary { + get { + return ResourceManager.GetString("moveperm_summary", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to moveperm mp. + /// + public static string moveperm_text { + get { + return ResourceManager.GetString("moveperm_text", resourceCulture); + } + } + /// /// Looks up a localized string similar to Moves a song from one position to another.. /// @@ -5108,6 +5189,33 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to Removes a permission from a given position. + /// + public static string removeperm_desc { + get { + return ResourceManager.GetString("removeperm_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `;rp 1`. + /// + public static string removeperm_summary { + get { + return ResourceManager.GetString("removeperm_summary", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to removeperm rp. + /// + public static string removeperm_text { + get { + return ResourceManager.GetString("removeperm_text", resourceCulture); + } + } + /// /// Looks up a localized string similar to Removes a playing string on a given number. **Bot Owner Only!**. /// diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 31d4bda9..59917de7 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -2646,4 +2646,40 @@ listperms lp + + Sets permission for all commands from a module for a specific user. + + + `;auc Searches disable @Someone` + + + allusrcmds auc + + + Sets permission for all modules for a specific user. + + + `;aum enable @someone` + + + allusrmdls aum + + + Moves permission from one position to another. + + + `;mp 2 4` + + + moveperm mp + + + Removes a permission from a given position + + + `;rp 1` + + + removeperm rp + \ No newline at end of file diff --git a/src/NadekoBot/Services/CommandHandler.cs b/src/NadekoBot/Services/CommandHandler.cs index 03863b8a..5f6eb49f 100644 --- a/src/NadekoBot/Services/CommandHandler.cs +++ b/src/NadekoBot/Services/CommandHandler.cs @@ -137,7 +137,7 @@ namespace NadekoBot.Services } int index; if (!perms.CheckPermissions(message, cmd, out index)) - return new Tuple(null, SearchResult.FromError(CommandError.Exception, $"Permission error. Permission number {index} (`{(index != -1 ? perms[index - 1].GetCommand() : "default")}`)")); + return new Tuple(null, SearchResult.FromError(CommandError.Exception, $"Permission error. Permission number {index} (`{(index != -1 ? perms[perms.Count - index].GetCommand() : "default")}`)")); } return new Tuple(commands[i], await commands[i].Execute(message, parseResult)); diff --git a/src/NadekoBot/Services/Database/Models/GuildConfig.cs b/src/NadekoBot/Services/Database/Models/GuildConfig.cs index 33180435..30d7253a 100644 --- a/src/NadekoBot/Services/Database/Models/GuildConfig.cs +++ b/src/NadekoBot/Services/Database/Models/GuildConfig.cs @@ -43,6 +43,6 @@ namespace NadekoBot.Services.Database.Models public ulong? GenerateCurrencyChannelId { get; set; } //permissions - public List Permissions { get; set; } + public List Permissions { get; set; } = new List(); } }