diff --git a/src/NadekoBot/Migrations/20160922170157_perms.Designer.cs b/src/NadekoBot/Migrations/20160922170157_perms.Designer.cs deleted file mode 100644 index 737b3c23..00000000 --- a/src/NadekoBot/Migrations/20160922170157_perms.Designer.cs +++ /dev/null @@ -1,587 +0,0 @@ -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("20160922170157_perms")] - partial class perms - { - 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.Designer.cs b/src/NadekoBot/Migrations/20160926144107_second.Designer.cs deleted file mode 100644 index 095ee7cf..00000000 --- a/src/NadekoBot/Migrations/20160926144107_second.Designer.cs +++ /dev/null @@ -1,587 +0,0 @@ -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 deleted file mode 100644 index e79f9421..00000000 --- a/src/NadekoBot/Migrations/20160926144107_second.cs +++ /dev/null @@ -1,19 +0,0 @@ -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/Migrations/20160927023659_moar perms.cs b/src/NadekoBot/Migrations/20160927023659_moar perms.cs deleted file mode 100644 index b360ca7f..00000000 --- a/src/NadekoBot/Migrations/20160927023659_moar perms.cs +++ /dev/null @@ -1,106 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace NadekoBot.Migrations -{ - public partial class moarperms : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Permission_GuildConfigs_GuildConfigId", - table: "Permission"); - - migrationBuilder.DropIndex( - name: "IX_Permission_GuildConfigId", - table: "Permission"); - - migrationBuilder.DropColumn( - name: "GuildConfigId", - table: "Permission"); - - migrationBuilder.AddColumn( - name: "NextId", - table: "Permission", - nullable: true); - - migrationBuilder.AddColumn( - name: "RootPermissionId", - table: "GuildConfigs", - nullable: true); - - migrationBuilder.CreateIndex( - name: "IX_Permission_NextId", - table: "Permission", - column: "NextId", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_GuildConfigs_RootPermissionId", - table: "GuildConfigs", - column: "RootPermissionId"); - - migrationBuilder.AddForeignKey( - name: "FK_GuildConfigs_Permission_RootPermissionId", - table: "GuildConfigs", - column: "RootPermissionId", - principalTable: "Permission", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - - migrationBuilder.AddForeignKey( - name: "FK_Permission_Permission_NextId", - table: "Permission", - column: "NextId", - principalTable: "Permission", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_GuildConfigs_Permission_RootPermissionId", - table: "GuildConfigs"); - - migrationBuilder.DropForeignKey( - name: "FK_Permission_Permission_NextId", - table: "Permission"); - - migrationBuilder.DropIndex( - name: "IX_Permission_NextId", - table: "Permission"); - - migrationBuilder.DropIndex( - name: "IX_GuildConfigs_RootPermissionId", - table: "GuildConfigs"); - - migrationBuilder.DropColumn( - name: "NextId", - table: "Permission"); - - migrationBuilder.DropColumn( - name: "RootPermissionId", - table: "GuildConfigs"); - - migrationBuilder.AddColumn( - name: "GuildConfigId", - table: "Permission", - nullable: true); - - migrationBuilder.CreateIndex( - name: "IX_Permission_GuildConfigId", - table: "Permission", - column: "GuildConfigId"); - - migrationBuilder.AddForeignKey( - name: "FK_Permission_GuildConfigs_GuildConfigId", - table: "Permission", - column: "GuildConfigId", - principalTable: "GuildConfigs", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - } - } -} diff --git a/src/NadekoBot/Migrations/20160927023659_moar perms.Designer.cs b/src/NadekoBot/Migrations/20160930001917_first.Designer.cs similarity index 99% rename from src/NadekoBot/Migrations/20160927023659_moar perms.Designer.cs rename to src/NadekoBot/Migrations/20160930001917_first.Designer.cs index d05622cc..dd4fabf1 100644 --- a/src/NadekoBot/Migrations/20160927023659_moar perms.Designer.cs +++ b/src/NadekoBot/Migrations/20160930001917_first.Designer.cs @@ -8,8 +8,8 @@ using NadekoBot.Services.Database.Impl; namespace NadekoBot.Migrations { [DbContext(typeof(NadekoSqliteContext))] - [Migration("20160927023659_moar perms")] - partial class moarperms + [Migration("20160930001917_first")] + partial class first { protected override void BuildTargetModel(ModelBuilder modelBuilder) { @@ -237,6 +237,8 @@ namespace NadekoBot.Migrations b.Property("LogSettingId"); + b.Property("PermissionRole"); + b.Property("RootPermissionId"); b.Property("SendChannelByeMessage"); @@ -245,6 +247,8 @@ namespace NadekoBot.Migrations b.Property("SendDmGreetMessage"); + b.Property("VerbosePermissions"); + b.Property("VoicePlusTextEnabled"); b.HasKey("Id"); diff --git a/src/NadekoBot/Migrations/20160922170157_perms.cs b/src/NadekoBot/Migrations/20160930001917_first.cs similarity index 95% rename from src/NadekoBot/Migrations/20160922170157_perms.cs rename to src/NadekoBot/Migrations/20160930001917_first.cs index e892e494..400ac665 100644 --- a/src/NadekoBot/Migrations/20160922170157_perms.cs +++ b/src/NadekoBot/Migrations/20160930001917_first.cs @@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace NadekoBot.Migrations { - public partial class perms : Migration + public partial class first : Migration { protected override void Up(MigrationBuilder migrationBuilder) { @@ -122,6 +122,30 @@ namespace NadekoBot.Migrations table.PrimaryKey("PK_LogSettings", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Permission", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Autoincrement", true), + NextId = table.Column(nullable: true), + PrimaryTarget = table.Column(nullable: false), + PrimaryTargetId = table.Column(nullable: false), + SecondaryTarget = table.Column(nullable: false), + SecondaryTargetName = table.Column(nullable: true), + State = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Permission", x => x.Id); + table.ForeignKey( + name: "FK_Permission_Permission_NextId", + column: x => x.NextId, + principalTable: "Permission", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + migrationBuilder.CreateTable( name: "Quotes", columns: table => new @@ -326,44 +350,6 @@ namespace NadekoBot.Migrations onDelete: ReferentialAction.Cascade); }); - migrationBuilder.CreateTable( - name: "GuildConfigs", - columns: table => new - { - Id = table.Column(nullable: false) - .Annotation("Autoincrement", true), - AutoAssignRoleId = table.Column(nullable: false), - AutoDeleteByeMessages = table.Column(nullable: false), - AutoDeleteGreetMessages = table.Column(nullable: false), - AutoDeleteGreetMessagesTimer = table.Column(nullable: false), - AutoDeleteSelfAssignedRoleMessages = table.Column(nullable: false), - ByeMessageChannelId = table.Column(nullable: false), - ChannelByeMessageText = table.Column(nullable: true), - ChannelGreetMessageText = table.Column(nullable: true), - DefaultMusicVolume = table.Column(nullable: false), - DeleteMessageOnCommand = table.Column(nullable: false), - DmGreetMessageText = table.Column(nullable: true), - ExclusiveSelfAssignedRoles = table.Column(nullable: false), - GenerateCurrencyChannelId = table.Column(nullable: true), - GreetMessageChannelId = table.Column(nullable: false), - GuildId = table.Column(nullable: false), - LogSettingId = table.Column(nullable: true), - SendChannelByeMessage = table.Column(nullable: false), - SendChannelGreetMessage = table.Column(nullable: false), - SendDmGreetMessage = table.Column(nullable: false), - VoicePlusTextEnabled = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_GuildConfigs", x => x.Id); - table.ForeignKey( - name: "FK_GuildConfigs_LogSettings_LogSettingId", - column: x => x.LogSettingId, - principalTable: "LogSettings", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - migrationBuilder.CreateTable( name: "IgnoredLogChannels", columns: table => new @@ -404,6 +390,53 @@ namespace NadekoBot.Migrations onDelete: ReferentialAction.Restrict); }); + migrationBuilder.CreateTable( + name: "GuildConfigs", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Autoincrement", true), + AutoAssignRoleId = table.Column(nullable: false), + AutoDeleteByeMessages = table.Column(nullable: false), + AutoDeleteGreetMessages = table.Column(nullable: false), + AutoDeleteGreetMessagesTimer = table.Column(nullable: false), + AutoDeleteSelfAssignedRoleMessages = table.Column(nullable: false), + ByeMessageChannelId = table.Column(nullable: false), + ChannelByeMessageText = table.Column(nullable: true), + ChannelGreetMessageText = table.Column(nullable: true), + DefaultMusicVolume = table.Column(nullable: false), + DeleteMessageOnCommand = table.Column(nullable: false), + DmGreetMessageText = table.Column(nullable: true), + ExclusiveSelfAssignedRoles = table.Column(nullable: false), + GenerateCurrencyChannelId = table.Column(nullable: true), + GreetMessageChannelId = table.Column(nullable: false), + GuildId = table.Column(nullable: false), + LogSettingId = table.Column(nullable: true), + PermissionRole = table.Column(nullable: true), + RootPermissionId = table.Column(nullable: true), + SendChannelByeMessage = table.Column(nullable: false), + SendChannelGreetMessage = table.Column(nullable: false), + SendDmGreetMessage = table.Column(nullable: false), + VerbosePermissions = table.Column(nullable: false), + VoicePlusTextEnabled = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_GuildConfigs", x => x.Id); + table.ForeignKey( + name: "FK_GuildConfigs_LogSettings_LogSettingId", + column: x => x.LogSettingId, + principalTable: "LogSettings", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_GuildConfigs_Permission_RootPermissionId", + column: x => x.RootPermissionId, + principalTable: "Permission", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + migrationBuilder.CreateTable( name: "FollowedStream", columns: table => new @@ -428,30 +461,6 @@ namespace NadekoBot.Migrations onDelete: ReferentialAction.Restrict); }); - migrationBuilder.CreateTable( - name: "Permission", - columns: table => new - { - Id = table.Column(nullable: false) - .Annotation("Autoincrement", true), - GuildConfigId = table.Column(nullable: true), - PrimaryTarget = table.Column(nullable: false), - PrimaryTargetId = table.Column(nullable: false), - SecondaryTarget = table.Column(nullable: false), - SecondaryTargetName = table.Column(nullable: true), - State = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Permission", x => x.Id); - table.ForeignKey( - name: "FK_Permission_GuildConfigs_GuildConfigId", - column: x => x.GuildConfigId, - principalTable: "GuildConfigs", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - migrationBuilder.CreateIndex( name: "IX_BlacklistItem_BotConfigId", table: "BlacklistItem", @@ -495,6 +504,11 @@ namespace NadekoBot.Migrations table: "GuildConfigs", column: "LogSettingId"); + migrationBuilder.CreateIndex( + name: "IX_GuildConfigs_RootPermissionId", + table: "GuildConfigs", + column: "RootPermissionId"); + migrationBuilder.CreateIndex( name: "IX_IgnoredLogChannels_LogSettingId", table: "IgnoredLogChannels", @@ -511,9 +525,10 @@ namespace NadekoBot.Migrations column: "BotConfigId"); migrationBuilder.CreateIndex( - name: "IX_Permission_GuildConfigId", + name: "IX_Permission_NextId", table: "Permission", - column: "GuildConfigId"); + column: "NextId", + unique: true); migrationBuilder.CreateIndex( name: "IX_PlayingStatus_BotConfigId", @@ -570,9 +585,6 @@ namespace NadekoBot.Migrations migrationBuilder.DropTable( name: "ModulePrefixes"); - migrationBuilder.DropTable( - name: "Permission"); - migrationBuilder.DropTable( name: "PlayingStatus"); @@ -605,6 +617,9 @@ namespace NadekoBot.Migrations migrationBuilder.DropTable( name: "LogSettings"); + + migrationBuilder.DropTable( + name: "Permission"); } } } diff --git a/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs b/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs index 039c2090..210b97e9 100644 --- a/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs +++ b/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs @@ -236,6 +236,8 @@ namespace NadekoBot.Migrations b.Property("LogSettingId"); + b.Property("PermissionRole"); + b.Property("RootPermissionId"); b.Property("SendChannelByeMessage"); @@ -244,6 +246,8 @@ namespace NadekoBot.Migrations b.Property("SendDmGreetMessage"); + b.Property("VerbosePermissions"); + b.Property("VoicePlusTextEnabled"); b.HasKey("Id"); diff --git a/src/NadekoBot/Modules/Permissions/PermissionExtensions.cs b/src/NadekoBot/Modules/Permissions/PermissionExtensions.cs index 7fded44f..70905eaf 100644 --- a/src/NadekoBot/Modules/Permissions/PermissionExtensions.cs +++ b/src/NadekoBot/Modules/Permissions/PermissionExtensions.cs @@ -1,5 +1,6 @@ using Discord; using Discord.Commands; +using NadekoBot.Services; using NadekoBot.Services.Database; using NadekoBot.Services.Database.Models; using System; @@ -21,7 +22,6 @@ 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++) @@ -50,13 +50,14 @@ namespace NadekoBot.Modules.Permissions public static bool? CheckPermission(this Permission perm, IUserMessage message, Command command) { if (!((perm.SecondaryTarget == SecondaryPermissionType.Command && - perm.SecondaryTargetName == command.Text.ToLowerInvariant()) || - ((perm.SecondaryTarget == SecondaryPermissionType.Module || perm.SecondaryTarget == SecondaryPermissionType.AllCommands) && - perm.SecondaryTargetName == command.Module.Name.ToLowerInvariant()) || - perm.SecondaryTarget == SecondaryPermissionType.AllModules || - (perm.SecondaryTarget == SecondaryPermissionType.AllCommands && perm.SecondaryTargetName == command.Module.Name.ToLowerInvariant()))) + perm.SecondaryTargetName.ToLowerInvariant() == command.Text.ToLowerInvariant()) || + (perm.SecondaryTarget == SecondaryPermissionType.Module && + perm.SecondaryTargetName.ToLowerInvariant() == command.Module.Name.ToLowerInvariant()) || + perm.SecondaryTarget == SecondaryPermissionType.AllModules)) return null; + var guildUser = message.Author as IGuildUser; + switch (perm.PrimaryTarget) { case PrimaryPermissionType.User: @@ -67,13 +68,16 @@ namespace NadekoBot.Modules.Permissions if (perm.PrimaryTargetId == message.Channel.Id) return perm.State; break; - case PrimaryPermissionType.Role: - var guildUser = message.Author as IGuildUser; + case PrimaryPermissionType.Role: if (guildUser == null) break; if (guildUser.Roles.Any(r => r.Id == perm.PrimaryTargetId)) return perm.State; break; + case PrimaryPermissionType.Server: + if (guildUser == null) + break; + return perm.State; } return null; } @@ -92,6 +96,9 @@ namespace NadekoBot.Modules.Permissions case PrimaryPermissionType.Role: com += "r"; break; + case PrimaryPermissionType.Server: + com += "s"; + break; } switch (perm.SecondaryTarget) @@ -102,9 +109,6 @@ namespace NadekoBot.Modules.Permissions case SecondaryPermissionType.Command: com += "c"; break; - case SecondaryPermissionType.AllCommands: - com = "a" + com + "c"; - break; case SecondaryPermissionType.AllModules: com = "a" + com + "m"; break; @@ -122,22 +126,19 @@ namespace NadekoBot.Modules.Permissions case PrimaryPermissionType.Role: com += $"<@&{perm.PrimaryTargetId}>"; break; + case PrimaryPermissionType.Server: + break; } return NadekoBot.ModulePrefixes[typeof(Permissions).Name] + com; } - public static void Add(this Permission perm, Permission toAdd) + public static void Prepend(this Permission perm, Permission toAdd) { - var last = perm; - while (last.Next != null) - { - last = last.Next; - } + perm = perm.GetRoot(); - toAdd.Previous = last; - last.Next = toAdd; - toAdd.Next = null; + perm.Previous = toAdd; + toAdd.Next = perm; } public static void Insert(this Permission perm, int index, Permission toAdd) @@ -174,16 +175,9 @@ namespace NadekoBot.Modules.Permissions public static Permission RemoveAt(this Permission perm, int index) { - if (index < 0) + if (index <= 0) //can't really remove at 0, that means deleting the element right now. Just use perm.Next if its 0 throw new IndexOutOfRangeException(); - if (index == 0) - { - perm.Next.Previous = null; - perm.Next = null; - return perm; - } - var toRemove = perm; var i = 0; while (i != index) @@ -195,7 +189,8 @@ namespace NadekoBot.Modules.Permissions } toRemove.Previous.Next = toRemove.Next; - toRemove.Next.Previous = toRemove.Previous; + if (toRemove.Next != null) + toRemove.Next.Previous = toRemove.Previous; return toRemove; } diff --git a/src/NadekoBot/Modules/Permissions/Permissions.cs b/src/NadekoBot/Modules/Permissions/Permissions.cs index 3c4e7c2e..b7648c80 100644 --- a/src/NadekoBot/Modules/Permissions/Permissions.cs +++ b/src/NadekoBot/Modules/Permissions/Permissions.cs @@ -21,6 +21,22 @@ namespace NadekoBot.Modules.Permissions { } + [LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias] + [RequireContext(ContextType.Guild)] + public async Task Verbose(IUserMessage msg, PermissionAction action) + { + var channel = (ITextChannel)msg.Channel; + + using (var uow = DbHandler.UnitOfWork()) + { + var config = uow.GuildConfigs.For(channel.Guild.Id); + config.VerbosePermissions = action.Value; + await uow.CompleteAsync().ConfigureAwait(false); + } + + await channel.SendMessageAsync("I will " + (action.Value ? "now" : "no longer") + " show permission warnings.").ConfigureAwait(false); + } + [LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias] [RequireContext(ContextType.Guild)] public async Task ListPerms(IUserMessage msg) @@ -30,10 +46,10 @@ namespace NadekoBot.Modules.Permissions string toSend = ""; using (var uow = DbHandler.UnitOfWork()) { - var perms = uow.GuildConfigs.For(channel.Guild.Id).RootPermission.AsEnumerable().Reverse(); + var perms = uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission; var i = 1; - toSend = String.Join("\n", perms.Select(p => $"`{(i++)}.` {p.GetCommand()}")); + toSend = String.Join("\n", perms.AsEnumerable().Select(p => $"`{(i++)}.` {p.GetCommand()}")); } if (string.IsNullOrWhiteSpace(toSend)) @@ -47,16 +63,36 @@ namespace NadekoBot.Modules.Permissions public async Task RemovePerm(IUserMessage imsg, int index) { var channel = (ITextChannel)imsg.Channel; + index -= 1; try { Permission p; using (var uow = DbHandler.UnitOfWork()) { - var perms = uow.GuildConfigs.For(channel.Guild.Id).RootPermission; - p = perms.RemoveAt(perms.Count() - index); + var perms = uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission; + if (index == perms.Count() - 1) + { + return; + } + else if (index == 0) + { + p = perms; + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = perms.Next; + } + else + { + p = perms.RemoveAt(index); + } await uow.CompleteAsync().ConfigureAwait(false); } - await channel.SendMessageAsync($"`Removed permission \"{p.GetCommand()}\" from position #{index}.`").ConfigureAwait(false); + + using (var uow2 = DbHandler.UnitOfWork()) + { + uow2._context.Remove(p); + uow2._context.SaveChanges(); + } + + await channel.SendMessageAsync($"{imsg.Author.Mention} removed permission **{p.GetCommand()}** from position #{index + 1}.").ConfigureAwait(false); } catch (ArgumentOutOfRangeException) { @@ -68,24 +104,31 @@ namespace NadekoBot.Modules.Permissions [RequireContext(ContextType.Guild)] public async Task MovePerm(IUserMessage imsg, int from, int to) { + from -= 1; + to -= 1; var channel = (ITextChannel)imsg.Channel; - if (!(from == to || from < 1 || to < 1)) + if (!(from == to || from < 0 || to < 0)) { try { Permission toInsert; using (var uow = DbHandler.UnitOfWork()) { - var perms = uow.GuildConfigs.For(channel.Guild.Id).RootPermission; - var count = perms.Count(); - toInsert = perms.RemoveAt(count - from); + var perms = uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission; + if (from == 0) + toInsert = perms; + else + toInsert = perms.RemoveAt(from); if (from < to) to -= 1; - perms.Insert(count - to, toInsert); - uow.GuildConfigs.For(channel.Guild.Id).RootPermission = perms; + var last = perms.Count() - 1; + if (from == last || to == last) + throw new IndexOutOfRangeException(); + perms.Insert(to, toInsert); + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = perms.GetRoot(); await uow.CompleteAsync().ConfigureAwait(false); } - await channel.SendMessageAsync($"`Moved permission \"{toInsert.GetCommand()}\" from #{from} to #{to}.`").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) @@ -95,6 +138,52 @@ namespace NadekoBot.Modules.Permissions await channel.SendMessageAsync("`Invalid index(es) specified.`").ConfigureAwait(false); } + [LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias] + [RequireContext(ContextType.Guild)] + public async Task SrvrCmd(IUserMessage imsg, Command command, PermissionAction action) + { + var channel = (ITextChannel)imsg.Channel; + + using (var uow = DbHandler.UnitOfWork()) + { + var newPerm = new Permission + { + PrimaryTarget = PrimaryPermissionType.Server, + PrimaryTargetId = 0, + SecondaryTarget = SecondaryPermissionType.Command, + SecondaryTargetName = command.Text.ToLowerInvariant(), + State = action.Value, + }; + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Prepend(newPerm); + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = newPerm; + await uow.CompleteAsync().ConfigureAwait(false); + } + await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{command.Text}` command on this server.").ConfigureAwait(false); + } + + [LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias] + [RequireContext(ContextType.Guild)] + public async Task SrvrMdl(IUserMessage imsg, Module module, PermissionAction action) + { + var channel = (ITextChannel)imsg.Channel; + + using (var uow = DbHandler.UnitOfWork()) + { + var newPerm = new Permission + { + PrimaryTarget = PrimaryPermissionType.Server, + PrimaryTargetId = 0, + SecondaryTarget = SecondaryPermissionType.Module, + SecondaryTargetName = module.Name.ToLowerInvariant(), + State = action.Value, + }; + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Prepend(newPerm); + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = newPerm; + await uow.CompleteAsync().ConfigureAwait(false); + } + await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{module.Name}` module on this server.").ConfigureAwait(false); + } + [LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias] [RequireContext(ContextType.Guild)] public async Task UsrCmd(IUserMessage imsg, Command command, PermissionAction action, IGuildUser user) @@ -103,14 +192,16 @@ namespace NadekoBot.Modules.Permissions using (var uow = DbHandler.UnitOfWork()) { - uow.GuildConfigs.For(channel.Guild.Id).RootPermission.Add(new Permission + var newPerm = new Permission { PrimaryTarget = PrimaryPermissionType.User, PrimaryTargetId = user.Id, SecondaryTarget = SecondaryPermissionType.Command, SecondaryTargetName = command.Text.ToLowerInvariant(), State = action.Value, - }); + }; + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Prepend(newPerm); + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = newPerm; await uow.CompleteAsync().ConfigureAwait(false); } await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{command.Text}` command for `{user}` user.").ConfigureAwait(false); @@ -124,14 +215,16 @@ namespace NadekoBot.Modules.Permissions using (var uow = DbHandler.UnitOfWork()) { - uow.GuildConfigs.For(channel.Guild.Id).RootPermission.Add(new Permission + var newPerm = new Permission { PrimaryTarget = PrimaryPermissionType.User, PrimaryTargetId = user.Id, SecondaryTarget = SecondaryPermissionType.Module, SecondaryTargetName = module.Name.ToLowerInvariant(), State = action.Value, - }); + }; + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Prepend(newPerm); + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = newPerm; await uow.CompleteAsync().ConfigureAwait(false); } await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{module.Name}` module for `{user}` user.").ConfigureAwait(false); @@ -145,14 +238,16 @@ namespace NadekoBot.Modules.Permissions using (var uow = DbHandler.UnitOfWork()) { - uow.GuildConfigs.For(channel.Guild.Id).RootPermission.Add(new Permission + var newPerm = new Permission { PrimaryTarget = PrimaryPermissionType.Role, PrimaryTargetId = role.Id, SecondaryTarget = SecondaryPermissionType.Command, SecondaryTargetName = command.Text.ToLowerInvariant(), State = action.Value, - }); + }; + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Prepend(newPerm); + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = newPerm; await uow.CompleteAsync().ConfigureAwait(false); } await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{command.Text}` command for `{role}` role.").ConfigureAwait(false); @@ -166,14 +261,16 @@ namespace NadekoBot.Modules.Permissions using (var uow = DbHandler.UnitOfWork()) { - uow.GuildConfigs.For(channel.Guild.Id).RootPermission.Add(new Permission + var newPerm = new Permission { PrimaryTarget = PrimaryPermissionType.Role, PrimaryTargetId = role.Id, SecondaryTarget = SecondaryPermissionType.Module, SecondaryTargetName = module.Name.ToLowerInvariant(), State = action.Value, - }); + }; + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Prepend(newPerm); + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = newPerm; await uow.CompleteAsync().ConfigureAwait(false); } await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{module.Name}` module for `{role}` role.").ConfigureAwait(false); @@ -184,18 +281,25 @@ namespace NadekoBot.Modules.Permissions public async Task ChnlCmd(IUserMessage imsg, Command command, PermissionAction action, ITextChannel chnl) { var channel = (ITextChannel)imsg.Channel; - - using (var uow = DbHandler.UnitOfWork()) + try { - uow.GuildConfigs.For(channel.Guild.Id).RootPermission.Add(new Permission + using (var uow = DbHandler.UnitOfWork()) { - PrimaryTarget = PrimaryPermissionType.Channel, - PrimaryTargetId = chnl.Id, - SecondaryTarget = SecondaryPermissionType.Command, - SecondaryTargetName = command.Text.ToLowerInvariant(), - State = action.Value, - }); - await uow.CompleteAsync().ConfigureAwait(false); + var newPerm = new Permission + { + PrimaryTarget = PrimaryPermissionType.Channel, + PrimaryTargetId = chnl.Id, + SecondaryTarget = SecondaryPermissionType.Command, + SecondaryTargetName = command.Text.ToLowerInvariant(), + State = action.Value, + }; + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Prepend(newPerm); + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = newPerm; + await uow.CompleteAsync().ConfigureAwait(false); + } + } + catch (Exception ex) { + Console.WriteLine(ex); } await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{command.Text}` command for `{chnl}` channel.").ConfigureAwait(false); } @@ -208,14 +312,16 @@ namespace NadekoBot.Modules.Permissions using (var uow = DbHandler.UnitOfWork()) { - uow.GuildConfigs.For(channel.Guild.Id).RootPermission.Add(new Permission + var newPerm = new Permission { PrimaryTarget = PrimaryPermissionType.Channel, PrimaryTargetId = chnl.Id, SecondaryTarget = SecondaryPermissionType.Module, SecondaryTargetName = module.Name.ToLowerInvariant(), State = action.Value, - }); + }; + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Prepend(newPerm); + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = newPerm; await uow.CompleteAsync().ConfigureAwait(false); } await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{module.Name}` module for `{chnl}` channel.").ConfigureAwait(false); @@ -229,14 +335,16 @@ namespace NadekoBot.Modules.Permissions using (var uow = DbHandler.UnitOfWork()) { - uow.GuildConfigs.For(channel.Guild.Id).RootPermission.Add(new Permission + var newPerm = new Permission { PrimaryTarget = PrimaryPermissionType.Channel, PrimaryTargetId = chnl.Id, SecondaryTarget = SecondaryPermissionType.AllModules, SecondaryTargetName = "*", State = action.Value, - }); + }; + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Prepend(newPerm); + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = newPerm; await uow.CompleteAsync().ConfigureAwait(false); } await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL MODULES` for `{chnl}` channel.").ConfigureAwait(false); @@ -250,14 +358,16 @@ namespace NadekoBot.Modules.Permissions using (var uow = DbHandler.UnitOfWork()) { - uow.GuildConfigs.For(channel.Guild.Id).RootPermission.Add(new Permission + var newPerm = new Permission { PrimaryTarget = PrimaryPermissionType.Role, PrimaryTargetId = role.Id, SecondaryTarget = SecondaryPermissionType.AllModules, SecondaryTargetName = "*", State = action.Value, - }); + }; + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Prepend(newPerm); + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = newPerm; await uow.CompleteAsync().ConfigureAwait(false); } await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL MODULES` for `{role}` role.").ConfigureAwait(false); @@ -271,14 +381,16 @@ namespace NadekoBot.Modules.Permissions using (var uow = DbHandler.UnitOfWork()) { - uow.GuildConfigs.For(channel.Guild.Id).RootPermission.Add(new Permission + var newPerm = new Permission { PrimaryTarget = PrimaryPermissionType.User, PrimaryTargetId = user.Id, SecondaryTarget = SecondaryPermissionType.AllModules, SecondaryTargetName = "*", State = action.Value, - }); + }; + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Prepend(newPerm); + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = newPerm; await uow.CompleteAsync().ConfigureAwait(false); } await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL MODULES` for `{user}` user.").ConfigureAwait(false); @@ -286,66 +398,89 @@ namespace NadekoBot.Modules.Permissions [LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias] [RequireContext(ContextType.Guild)] - public async Task AllChnlCmds(IUserMessage imsg, Module module, PermissionAction action, ITextChannel chnl) + public async Task AllSrvrMdls(IUserMessage imsg, PermissionAction action, IUser user) { var channel = (ITextChannel)imsg.Channel; using (var uow = DbHandler.UnitOfWork()) { - uow.GuildConfigs.For(channel.Guild.Id).RootPermission.Add(new Permission + var newPerm = new Permission { - PrimaryTarget = PrimaryPermissionType.Channel, - PrimaryTargetId = chnl.Id, - SecondaryTarget = SecondaryPermissionType.AllCommands, - SecondaryTargetName = module.Name.ToLowerInvariant(), + PrimaryTarget = PrimaryPermissionType.Server, + PrimaryTargetId = 0, + SecondaryTarget = SecondaryPermissionType.AllModules, + SecondaryTargetName = "*", State = action.Value, - }); + }; + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Prepend(newPerm); + uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission = newPerm; await uow.CompleteAsync().ConfigureAwait(false); } - await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL COMMANDS` from `{module.Name}` module for `{chnl}` channel.").ConfigureAwait(false); + await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL MODULES` on this server.").ConfigureAwait(false); } - [LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias] - [RequireContext(ContextType.Guild)] - public async Task AllRoleCmds(IUserMessage imsg, Module module, PermissionAction action, IRole role) - { - var channel = (ITextChannel)imsg.Channel; + //[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias] + //[RequireContext(ContextType.Guild)] + //public async Task AllChnlCmds(IUserMessage imsg, Module module, PermissionAction action, ITextChannel chnl) + //{ + // var channel = (ITextChannel)imsg.Channel; - using (var uow = DbHandler.UnitOfWork()) - { - uow.GuildConfigs.For(channel.Guild.Id).RootPermission.Add(new Permission - { - PrimaryTarget = PrimaryPermissionType.Role, - PrimaryTargetId = role.Id, - SecondaryTarget = SecondaryPermissionType.AllCommands, - SecondaryTargetName = module.Name.ToLowerInvariant(), - State = action.Value, - }); - await uow.CompleteAsync().ConfigureAwait(false); - } - await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL COMMANDS` from `{module.Name}` module for `{role}` role.").ConfigureAwait(false); - } + // using (var uow = DbHandler.UnitOfWork()) + // { + // uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Add(new Permission + // { + // PrimaryTarget = PrimaryPermissionType.Channel, + // PrimaryTargetId = chnl.Id, + // SecondaryTarget = SecondaryPermissionType.AllCommands, + // SecondaryTargetName = module.Name.ToLowerInvariant(), + // State = action.Value, + // }); + // await uow.CompleteAsync().ConfigureAwait(false); + // } + // await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL COMMANDS` from `{module.Name}` module for `{chnl}` channel.").ConfigureAwait(false); + //} - [LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias] - [RequireContext(ContextType.Guild)] - public async Task AllUsrCmds(IUserMessage imsg, Module module, PermissionAction action, IUser user) - { - var channel = (ITextChannel)imsg.Channel; + //[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias] + //[RequireContext(ContextType.Guild)] + //public async Task AllRoleCmds(IUserMessage imsg, Module module, PermissionAction action, IRole role) + //{ + // var channel = (ITextChannel)imsg.Channel; - using (var uow = DbHandler.UnitOfWork()) - { - uow.GuildConfigs.For(channel.Guild.Id).RootPermission.Add(new Permission - { - PrimaryTarget = PrimaryPermissionType.User, - PrimaryTargetId = user.Id, - SecondaryTarget = SecondaryPermissionType.AllCommands, - SecondaryTargetName = module.Name.ToLowerInvariant(), - State = action.Value, - }); - await uow.CompleteAsync().ConfigureAwait(false); - } - await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL COMMANDS` from `{module.Name}` module for `{user}` user.").ConfigureAwait(false); - } + // using (var uow = DbHandler.UnitOfWork()) + // { + // uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Add(new Permission + // { + // PrimaryTarget = PrimaryPermissionType.Role, + // PrimaryTargetId = role.Id, + // SecondaryTarget = SecondaryPermissionType.AllCommands, + // SecondaryTargetName = module.Name.ToLowerInvariant(), + // State = action.Value, + // }); + // await uow.CompleteAsync().ConfigureAwait(false); + // } + // await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL COMMANDS` from `{module.Name}` module for `{role}` role.").ConfigureAwait(false); + //} + + //[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias] + //[RequireContext(ContextType.Guild)] + //public async Task AllUsrCmds(IUserMessage imsg, Module module, PermissionAction action, IUser user) + //{ + // var channel = (ITextChannel)imsg.Channel; + + // using (var uow = DbHandler.UnitOfWork()) + // { + // uow.GuildConfigs.PermissionsFor(channel.Guild.Id).RootPermission.Add(new Permission + // { + // PrimaryTarget = PrimaryPermissionType.User, + // PrimaryTargetId = user.Id, + // SecondaryTarget = SecondaryPermissionType.AllCommands, + // SecondaryTargetName = module.Name.ToLowerInvariant(), + // State = action.Value, + // }); + // await uow.CompleteAsync().ConfigureAwait(false); + // } + // await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL COMMANDS` from `{module.Name}` module for `{user}` user.").ConfigureAwait(false); + //} } } diff --git a/src/NadekoBot/Services/CommandHandler.cs b/src/NadekoBot/Services/CommandHandler.cs index c884c476..fc7b586c 100644 --- a/src/NadekoBot/Services/CommandHandler.cs +++ b/src/NadekoBot/Services/CommandHandler.cs @@ -11,6 +11,8 @@ using Discord.Commands; using NadekoBot.Services.Database; using NadekoBot.Services.Database.Models; using NadekoBot.Modules.Permissions; +using Microsoft.Data.Sqlite; +using Discord.Net; namespace NadekoBot.Services { @@ -44,41 +46,66 @@ namespace NadekoBot.Services var sw = new Stopwatch(); sw.Start(); - var t = await ExecuteCommand(usrMsg, usrMsg.Content, guild, usrMsg.Author, MultiMatchHandling.Best); - var command = t.Item1; - var result = t.Item2; - sw.Stop(); - var channel = (usrMsg.Channel as ITextChannel); - if (result.IsSuccess) + try { - CommandExecuted(this, new CommandExecutedEventArgs(usrMsg, command)); - _log.Info("Command Executed after {4}s\n\t" + - "User: {0}\n\t" + - "Server: {1}\n\t" + - "Channel: {2}\n\t" + - "Message: {3}", - usrMsg.Author + " [" + usrMsg.Author.Id + "]", // {0} - (channel == null ? "PRIVATE" : channel.Guild.Name + " [" + channel.Guild.Id + "]"), // {1} - (channel == null ? "PRIVATE" : channel.Name + " [" + channel.Id + "]"), // {2} - usrMsg.Content, // {3} - sw.Elapsed.TotalSeconds // {4} - ); + var t = await ExecuteCommand(usrMsg, usrMsg.Content, guild, usrMsg.Author, MultiMatchHandling.Best); + var command = t.Item1; + var result = t.Item2; + sw.Stop(); + var channel = (usrMsg.Channel as ITextChannel); + if (result.IsSuccess) + { + CommandExecuted(this, new CommandExecutedEventArgs(usrMsg, command)); + _log.Info("Command Executed after {4}s\n\t" + + "User: {0}\n\t" + + "Server: {1}\n\t" + + "Channel: {2}\n\t" + + "Message: {3}", + usrMsg.Author + " [" + usrMsg.Author.Id + "]", // {0} + (channel == null ? "PRIVATE" : channel.Guild.Name + " [" + channel.Guild.Id + "]"), // {1} + (channel == null ? "PRIVATE" : channel.Name + " [" + channel.Id + "]"), // {2} + usrMsg.Content, // {3} + sw.Elapsed.TotalSeconds // {4} + ); + } + else if (!result.IsSuccess && result.Error != CommandError.UnknownCommand) + { + _log.Warn("Command Errored after {5}s\n\t" + + "User: {0}\n\t" + + "Server: {1}\n\t" + + "Channel: {2}\n\t" + + "Message: {3}\n\t" + + "Error: {4}", + usrMsg.Author + " [" + usrMsg.Author.Id + "]", // {0} + (channel == null ? "PRIVATE" : channel.Guild.Name + " [" + channel.Guild.Id + "]"), // {1} + (channel == null ? "PRIVATE" : channel.Name + " [" + channel.Id + "]"), // {2} + usrMsg.Content,// {3} + result.ErrorReason, // {4} + sw.Elapsed.TotalSeconds // {5} + ); + if (guild != null && command != null && result.Error == CommandError.Exception) + { + bool verbose; + using (var uow = DbHandler.UnitOfWork()) + { + verbose = uow.GuildConfigs.For(guild.Id).VerbosePermissions; + } + if (verbose) + await msg.Channel.SendMessageAsync(":warning: " + result.ErrorReason).ConfigureAwait(false); + } + } } - else if (!result.IsSuccess && result.Error != CommandError.UnknownCommand) + catch (InvalidOperationException ex) { - _log.Warn("Command Errored after {5}s\n\t" + - "User: {0}\n\t" + - "Server: {1}\n\t" + - "Channel: {2}\n\t" + - "Message: {3}\n\t" + - "Error: {4}", - usrMsg.Author + " [" + usrMsg.Author.Id + "]", // {0} - (channel == null ? "PRIVATE" : channel.Guild.Name + " [" + channel.Guild.Id + "]"), // {1} - (channel == null ? "PRIVATE" : channel.Name + " [" + channel.Id + "]"), // {2} - usrMsg.Content,// {3} - result.ErrorReason, // {4} - sw.Elapsed.TotalSeconds // {5} - ); + Console.WriteLine(ex); + } + catch (SqliteException ex) + { + Console.WriteLine(ex.InnerException); + } + catch (HttpException ex) + { + Console.WriteLine(ex); } }); @@ -133,11 +160,14 @@ namespace NadekoBot.Services { using (var uow = DbHandler.UnitOfWork()) { - rootPerm = uow.GuildConfigs.For(guild.Id).RootPermission; + rootPerm = uow.GuildConfigs.PermissionsFor(guild.Id).RootPermission; } int index; if (!rootPerm.AsEnumerable().CheckPermissions(message, cmd, out index)) - return new Tuple(null, SearchResult.FromError(CommandError.Exception, $"Permission error. Permission number {index} (`{(index != -1 ? rootPerm.GetAt(rootPerm.Count() - index).GetCommand() : "default")}`)")); + { + var returnMsg = $"Permission number #{index} **{rootPerm.GetAt(index).GetCommand()}** is preventing this action."; + return new Tuple(cmd, SearchResult.FromError(CommandError.Exception, returnMsg)); + } } 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 7ae9b0d0..8f96a284 100644 --- a/src/NadekoBot/Services/Database/Models/GuildConfig.cs +++ b/src/NadekoBot/Services/Database/Models/GuildConfig.cs @@ -43,14 +43,8 @@ namespace NadekoBot.Services.Database.Models public ulong? GenerateCurrencyChannelId { get; set; } //permissions - public Permission RootPermission { get; set; } = new Permission() - { - Next = null, - Previous = null, - PrimaryTarget = PrimaryPermissionType.Role, - PrimaryTargetId = 0, - SecondaryTarget = SecondaryPermissionType.AllModules, - SecondaryTargetName = "*", - }; + public Permission RootPermission { get; set; } + public bool VerbosePermissions { get; set; } + public string PermissionRole { get; set; } = "Nadeko"; } } diff --git a/src/NadekoBot/Services/Database/Models/Permission.cs b/src/NadekoBot/Services/Database/Models/Permission.cs index ea20f61b..aed70fa5 100644 --- a/src/NadekoBot/Services/Database/Models/Permission.cs +++ b/src/NadekoBot/Services/Database/Models/Permission.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -18,20 +19,50 @@ namespace NadekoBot.Services.Database.Models public string SecondaryTargetName { get; set; } public bool State { get; set; } + + [NotMapped] + private static Permission AllowAllPerm => new Permission() + { + PrimaryTarget = PrimaryPermissionType.Server, + PrimaryTargetId = 0, + SecondaryTarget = SecondaryPermissionType.AllModules, + SecondaryTargetName = "*", + State = true, + }; + [NotMapped] + private static Permission BlockNsfwPerm => new Permission() + { + PrimaryTarget = PrimaryPermissionType.Server, + PrimaryTargetId = 0, + SecondaryTarget = SecondaryPermissionType.Module, + SecondaryTargetName = "nsfw", + State = false, + }; + + public static Permission GetDefaultRoot() + { + var root = AllowAllPerm; + var blockNsfw = BlockNsfwPerm; + + root.Previous = blockNsfw; + blockNsfw.Next = root; + + return blockNsfw; + } } public enum PrimaryPermissionType { User, Channel, - Role + Role, + Server } public enum SecondaryPermissionType { Module, Command, - AllCommands, AllModules } } diff --git a/src/NadekoBot/Services/Database/NadekoContext.cs b/src/NadekoBot/Services/Database/NadekoContext.cs index b5ead5f0..6d71f8cc 100644 --- a/src/NadekoBot/Services/Database/NadekoContext.cs +++ b/src/NadekoBot/Services/Database/NadekoContext.cs @@ -186,6 +186,7 @@ namespace NadekoBot.Services.Database permissionEntity .HasOne(p => p.Next) .WithOne(p => p.Previous); + #endregion #region LogSettings diff --git a/src/NadekoBot/Services/Database/Repositories/IGuildConfigRepository.cs b/src/NadekoBot/Services/Database/Repositories/IGuildConfigRepository.cs index 82767a80..7303eda2 100644 --- a/src/NadekoBot/Services/Database/Repositories/IGuildConfigRepository.cs +++ b/src/NadekoBot/Services/Database/Repositories/IGuildConfigRepository.cs @@ -11,6 +11,7 @@ namespace NadekoBot.Services.Database.Repositories public interface IGuildConfigRepository : IRepository { GuildConfig For(ulong guildId); + GuildConfig PermissionsFor(ulong guildId); IEnumerable GetAllFollowedStreams(); } } diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/GuildConfigRepository.cs b/src/NadekoBot/Services/Database/Repositories/Impl/GuildConfigRepository.cs index 17133bf4..1066397b 100644 --- a/src/NadekoBot/Services/Database/Repositories/Impl/GuildConfigRepository.cs +++ b/src/NadekoBot/Services/Database/Repositories/Impl/GuildConfigRepository.cs @@ -19,6 +19,10 @@ namespace NadekoBot.Services.Database.Repositories.Impl .ThenInclude(ls => ls.IgnoredChannels) .Include(gc => gc.LogSetting) .ThenInclude(ls => ls.IgnoredVoicePresenceChannelIds) + .Include(gc => gc.RootPermission) + .ThenInclude(gc => gc.Previous) + .Include(gc => gc.RootPermission) + .ThenInclude(gc => gc.Next) .ToList(); /// @@ -29,16 +33,45 @@ namespace NadekoBot.Services.Database.Repositories.Impl public GuildConfig For(ulong guildId) { var config = _set.Include(gc => gc.FollowedStreams) - .Include(gc => gc.RootPermission) .Include(gc => gc.LogSetting) - .ThenInclude(ls=>ls.IgnoredChannels) - .FirstOrDefault(c => c.GuildId == guildId); + .ThenInclude(ls => ls.IgnoredChannels) + .Include(gc => gc.LogSetting) + .ThenInclude(ls => ls.IgnoredVoicePresenceChannelIds) + .FirstOrDefault(c => c.GuildId == guildId); if (config == null) { _set.Add((config = new GuildConfig { - GuildId = guildId + GuildId = guildId, + RootPermission = Permission.GetDefaultRoot(), + })); + _context.SaveChanges(); + } + return config; + } + + public GuildConfig PermissionsFor(ulong guildId) + { + var query = _set.Include(gc => gc.RootPermission); + + //todo this is possibly a disaster for performance + //What i could do instead is count the number of permissions in the permission table for this guild + // and make a for loop with those. + // or just select permissions for this guild and manually chain them + for (int i = 0; i < 60; i++) + { + query = query.ThenInclude(gc => gc.Next); + } + + var config = query.FirstOrDefault(c => c.GuildId == guildId); + + if (config == null) + { + _set.Add((config = new GuildConfig + { + GuildId = guildId, + RootPermission = Permission.GetDefaultRoot(), })); _context.SaveChanges(); } diff --git a/src/NadekoBot/project.json b/src/NadekoBot/project.json index a795d571..9ae6cbdd 100644 --- a/src/NadekoBot/project.json +++ b/src/NadekoBot/project.json @@ -23,7 +23,6 @@ "Microsoft.Extensions.PlatformAbstractions": "1.0.0", "Newtonsoft.Json": "9.0.1", "Microsoft.Extensions.DependencyInjection": "1.0.0", - "Discord.Net.Commands": "1.0.0-dev", "System.Resources.ResourceWriter": "4.0.0-beta-22816", "Google.Apis.YouTube.v3": "1.15.0.582", "Google.Apis.Urlshortener.v1": "1.15.0.138", @@ -35,7 +34,9 @@ "Microsoft.EntityFrameworkCore.Design": "1.0.0-preview2-final", "Microsoft.EntityFrameworkCore.Sqlite": "1.0.0", "CoreCLR-NCalc": "2.1.0", - "ImageProcessorCore": "1.0.0-alpha1045" + "ImageProcessorCore": "1.0.0-alpha1045", + "Discord.Net.Commands": "1.0.0-beta-*", + "Discord.Net": "1.0.0-beta-*" }, "tools": { "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final" diff --git a/src/NadekoBot/project.lock.json b/src/NadekoBot/project.lock.json index 9c9ca106..76da98a3 100644 --- a/src/NadekoBot/project.lock.json +++ b/src/NadekoBot/project.lock.json @@ -9096,7 +9096,8 @@ "projectFileDependencyGroups": { "": [ "CoreCLR-NCalc >= 2.1.0", - "Discord.Net.Commands >= 1.0.0-dev", + "Discord.Net >= 1.0.0-beta-*", + "Discord.Net.Commands >= 1.0.0-beta-*", "Google.Apis.Customsearch.v1 >= 1.16.0.466", "Google.Apis.Urlshortener.v1 >= 1.15.0.138", "Google.Apis.YouTube.v3 >= 1.15.0.582",