diff --git a/src/NadekoBot/Migrations/20161224032833_logsettings.Designer.cs b/src/NadekoBot/Migrations/20161224032833_logsettings.Designer.cs new file mode 100644 index 00000000..a2691bdb --- /dev/null +++ b/src/NadekoBot/Migrations/20161224032833_logsettings.Designer.cs @@ -0,0 +1,855 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using NadekoBot.Services.Database; +using NadekoBot.Services.Database.Models; +using NadekoBot.Modules.Music.Classes; + +namespace NadekoBot.Migrations +{ + [DbContext(typeof(NadekoContext))] + [Migration("20161224032833_logsettings")] + partial class logsettings + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.1.0-rtm-22752"); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.BlacklistItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BotConfigId"); + + b.Property("ItemId"); + + b.Property("Type"); + + 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("DMHelpString"); + + b.Property("ForwardMessages"); + + b.Property("ForwardToAllOwners"); + + b.Property("HelpString"); + + b.Property("MigrationVersion"); + + 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("SequenceNumber"); + + 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.CommandCooldown", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("CommandName"); + + b.Property("GuildConfigId"); + + b.Property("Seconds"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.ToTable("CommandCooldown"); + }); + + 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.CurrencyTransaction", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Amount"); + + b.Property("Reason"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.ToTable("CurrencyTransactions"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.CustomReaction", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("GuildId"); + + b.Property("IsRegex"); + + b.Property("OwnerOnly"); + + b.Property("Response"); + + b.Property("Trigger"); + + b.HasKey("Id"); + + b.ToTable("CustomReactions"); + }); + + 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.FilterChannelId", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ChannelId"); + + b.Property("GuildConfigId"); + + b.Property("GuildConfigId1"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.HasIndex("GuildConfigId1"); + + b.ToTable("FilterChannelId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.FilteredWord", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("GuildConfigId"); + + b.Property("Word"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.ToTable("FilteredWord"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.FollowedStream", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ChannelId"); + + b.Property("GuildConfigId"); + + b.Property("GuildId"); + + b.Property("Type"); + + b.Property("Username"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.ToTable("FollowedStream"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.GCChannelId", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ChannelId"); + + b.Property("GuildConfigId"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.ToTable("GCChannelId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.GuildConfig", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AutoAssignRoleId"); + + b.Property("AutoDeleteByeMessages"); + + b.Property("AutoDeleteByeMessagesTimer"); + + b.Property("AutoDeleteGreetMessages"); + + b.Property("AutoDeleteGreetMessagesTimer"); + + b.Property("AutoDeleteSelfAssignedRoleMessages"); + + b.Property("ByeMessageChannelId"); + + b.Property("ChannelByeMessageText"); + + b.Property("ChannelGreetMessageText"); + + b.Property("CleverbotEnabled"); + + b.Property("DefaultMusicVolume"); + + b.Property("DeleteMessageOnCommand"); + + b.Property("DmGreetMessageText"); + + b.Property("ExclusiveSelfAssignedRoles"); + + b.Property("FilterInvites"); + + b.Property("FilterWords"); + + b.Property("GreetMessageChannelId"); + + b.Property("GuildId"); + + b.Property("LogSettingId"); + + b.Property("MuteRoleName"); + + b.Property("PermissionRole"); + + b.Property("RootPermissionId"); + + b.Property("SendChannelByeMessage"); + + b.Property("SendChannelGreetMessage"); + + b.Property("SendDmGreetMessage"); + + b.Property("VerbosePermissions"); + + b.Property("VoicePlusTextEnabled"); + + b.HasKey("Id"); + + b.HasIndex("GuildId") + .IsUnique(); + + b.HasIndex("LogSettingId"); + + b.HasIndex("RootPermissionId"); + + 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("ChannelCreatedId"); + + b.Property("ChannelDestroyed"); + + b.Property("ChannelDestroyedId"); + + b.Property("ChannelId"); + + b.Property("ChannelUpdated"); + + b.Property("ChannelUpdatedId"); + + b.Property("IsLogging"); + + b.Property("LogOtherId"); + + b.Property("LogUserPresence"); + + b.Property("LogUserPresenceId"); + + b.Property("LogVoicePresence"); + + b.Property("LogVoicePresenceId"); + + b.Property("LogVoicePresenceTTSId"); + + b.Property("MessageDeleted"); + + b.Property("MessageDeletedId"); + + b.Property("MessageUpdated"); + + b.Property("MessageUpdatedId"); + + b.Property("UserBanned"); + + b.Property("UserBannedId"); + + b.Property("UserJoined"); + + b.Property("UserJoinedId"); + + b.Property("UserLeft"); + + b.Property("UserLeftId"); + + b.Property("UserMutedId"); + + b.Property("UserPresenceChannelId"); + + b.Property("UserUnbanned"); + + b.Property("UserUnbannedId"); + + b.Property("UserUpdated"); + + b.Property("UserUpdatedId"); + + 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.MusicPlaylist", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Author"); + + b.Property("AuthorId"); + + b.Property("Name"); + + b.HasKey("Id"); + + b.ToTable("MusicPlaylists"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.MutedUserId", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("GuildConfigId"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("GuildConfigId"); + + b.ToTable("MutedUserId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.Permission", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("NextId"); + + b.Property("PrimaryTarget"); + + b.Property("PrimaryTargetId"); + + b.Property("SecondaryTarget"); + + b.Property("SecondaryTargetName"); + + b.Property("State"); + + b.HasKey("Id"); + + b.HasIndex("NextId") + .IsUnique(); + + 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.PlaylistSong", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("MusicPlaylistId"); + + b.Property("Provider"); + + b.Property("ProviderType"); + + b.Property("Query"); + + b.Property("Title"); + + b.Property("Uri"); + + b.HasKey("Id"); + + b.HasIndex("MusicPlaylistId"); + + b.ToTable("PlaylistSong"); + }); + + 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.UserPokeTypes", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("UserId"); + + b.Property("type"); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("PokeGame"); + }); + + 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.CommandCooldown", b => + { + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + .WithMany("CommandCooldowns") + .HasForeignKey("GuildConfigId"); + }); + + 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.FilterChannelId", b => + { + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + .WithMany("FilterInvitesChannelIds") + .HasForeignKey("GuildConfigId"); + + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + .WithMany("FilterWordsChannelIds") + .HasForeignKey("GuildConfigId1"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.FilteredWord", b => + { + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + .WithMany("FilteredWords") + .HasForeignKey("GuildConfigId"); + }); + + 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.GCChannelId", b => + { + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + .WithMany("GenerateCurrencyChannelIds") + .HasForeignKey("GuildConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.GuildConfig", b => + { + b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting") + .WithMany() + .HasForeignKey("LogSettingId"); + + b.HasOne("NadekoBot.Services.Database.Models.Permission", "RootPermission") + .WithMany() + .HasForeignKey("RootPermissionId"); + }); + + 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") + .WithMany("ModulePrefixes") + .HasForeignKey("BotConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.MutedUserId", b => + { + b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + .WithMany("MutedUsers") + .HasForeignKey("GuildConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.Permission", b => + { + b.HasOne("NadekoBot.Services.Database.Models.Permission", "Next") + .WithOne("Previous") + .HasForeignKey("NadekoBot.Services.Database.Models.Permission", "NextId"); + }); + + 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.PlaylistSong", b => + { + b.HasOne("NadekoBot.Services.Database.Models.MusicPlaylist") + .WithMany("Songs") + .HasForeignKey("MusicPlaylistId") + .OnDelete(DeleteBehavior.Cascade); + }); + + 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/20161224032833_logsettings.cs b/src/NadekoBot/Migrations/20161224032833_logsettings.cs new file mode 100644 index 00000000..609e8d24 --- /dev/null +++ b/src/NadekoBot/Migrations/20161224032833_logsettings.cs @@ -0,0 +1,150 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace NadekoBot.Migrations +{ + public partial class logsettings : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ChannelCreatedId", + table: "LogSettings", + nullable: true); + + migrationBuilder.AddColumn( + name: "ChannelDestroyedId", + table: "LogSettings", + nullable: true); + + migrationBuilder.AddColumn( + name: "ChannelUpdatedId", + table: "LogSettings", + nullable: true); + + migrationBuilder.AddColumn( + name: "LogOtherId", + table: "LogSettings", + nullable: true); + + migrationBuilder.AddColumn( + name: "LogUserPresenceId", + table: "LogSettings", + nullable: true); + + migrationBuilder.AddColumn( + name: "LogVoicePresenceId", + table: "LogSettings", + nullable: true); + + migrationBuilder.AddColumn( + name: "LogVoicePresenceTTSId", + table: "LogSettings", + nullable: true); + + migrationBuilder.AddColumn( + name: "MessageDeletedId", + table: "LogSettings", + nullable: true); + + migrationBuilder.AddColumn( + name: "MessageUpdatedId", + table: "LogSettings", + nullable: true); + + migrationBuilder.AddColumn( + name: "UserBannedId", + table: "LogSettings", + nullable: true); + + migrationBuilder.AddColumn( + name: "UserJoinedId", + table: "LogSettings", + nullable: true); + + migrationBuilder.AddColumn( + name: "UserLeftId", + table: "LogSettings", + nullable: true); + + migrationBuilder.AddColumn( + name: "UserMutedId", + table: "LogSettings", + nullable: true); + + migrationBuilder.AddColumn( + name: "UserUnbannedId", + table: "LogSettings", + nullable: true); + + migrationBuilder.AddColumn( + name: "UserUpdatedId", + table: "LogSettings", + nullable: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "ChannelCreatedId", + table: "LogSettings"); + + migrationBuilder.DropColumn( + name: "ChannelDestroyedId", + table: "LogSettings"); + + migrationBuilder.DropColumn( + name: "ChannelUpdatedId", + table: "LogSettings"); + + migrationBuilder.DropColumn( + name: "LogOtherId", + table: "LogSettings"); + + migrationBuilder.DropColumn( + name: "LogUserPresenceId", + table: "LogSettings"); + + migrationBuilder.DropColumn( + name: "LogVoicePresenceId", + table: "LogSettings"); + + migrationBuilder.DropColumn( + name: "LogVoicePresenceTTSId", + table: "LogSettings"); + + migrationBuilder.DropColumn( + name: "MessageDeletedId", + table: "LogSettings"); + + migrationBuilder.DropColumn( + name: "MessageUpdatedId", + table: "LogSettings"); + + migrationBuilder.DropColumn( + name: "UserBannedId", + table: "LogSettings"); + + migrationBuilder.DropColumn( + name: "UserJoinedId", + table: "LogSettings"); + + migrationBuilder.DropColumn( + name: "UserLeftId", + table: "LogSettings"); + + migrationBuilder.DropColumn( + name: "UserMutedId", + table: "LogSettings"); + + migrationBuilder.DropColumn( + name: "UserUnbannedId", + table: "LogSettings"); + + migrationBuilder.DropColumn( + name: "UserUpdatedId", + table: "LogSettings"); + } + } +} diff --git a/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs b/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs index 6b7ef481..022480a4 100644 --- a/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs +++ b/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs @@ -423,34 +423,64 @@ namespace NadekoBot.Migrations b.Property("ChannelCreated"); + b.Property("ChannelCreatedId"); + b.Property("ChannelDestroyed"); + b.Property("ChannelDestroyedId"); + b.Property("ChannelId"); b.Property("ChannelUpdated"); + b.Property("ChannelUpdatedId"); + b.Property("IsLogging"); + b.Property("LogOtherId"); + b.Property("LogUserPresence"); + b.Property("LogUserPresenceId"); + b.Property("LogVoicePresence"); + b.Property("LogVoicePresenceId"); + + b.Property("LogVoicePresenceTTSId"); + b.Property("MessageDeleted"); + b.Property("MessageDeletedId"); + b.Property("MessageUpdated"); + b.Property("MessageUpdatedId"); + b.Property("UserBanned"); + b.Property("UserBannedId"); + b.Property("UserJoined"); + b.Property("UserJoinedId"); + b.Property("UserLeft"); + b.Property("UserLeftId"); + + b.Property("UserMutedId"); + b.Property("UserPresenceChannelId"); b.Property("UserUnbanned"); + b.Property("UserUnbannedId"); + b.Property("UserUpdated"); + b.Property("UserUpdatedId"); + b.Property("VoicePresenceChannelId"); b.HasKey("Id"); diff --git a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs index 1a44e3b4..e2a49b11 100644 --- a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs @@ -4,6 +4,7 @@ using Discord.WebSocket; using Microsoft.EntityFrameworkCore; using NadekoBot.Attributes; using NadekoBot.Extensions; +using NadekoBot.Modules.Permissions; using NadekoBot.Services; using NadekoBot.Services.Database.Models; using NLog; @@ -88,11 +89,11 @@ namespace NadekoBot.Modules.Administration { LogSetting logSetting; if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting) - || !logSetting.IsLogging) + || (logSetting.UserMutedId == null)) return Task.CompletedTask; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(usr.Guild, logSetting)) == null) + if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)) == null) return Task.CompletedTask; var task = Task.Run(async () => @@ -120,11 +121,11 @@ namespace NadekoBot.Modules.Administration { LogSetting logSetting; if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting) - || !logSetting.IsLogging) + || (logSetting.UserMutedId == null)) return Task.CompletedTask; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(usr.Guild, logSetting)) == null) + if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)) == null) return Task.CompletedTask; var task = Task.Run(async () => @@ -155,10 +156,10 @@ namespace NadekoBot.Modules.Administration LogSetting logSetting; if (!GuildLogSettings.TryGetValue(users.First().Guild.Id, out logSetting) - || !logSetting.IsLogging) + || (logSetting.LogOtherId == null)) return; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(users.First().Guild, logSetting)) == null) + if ((logChannel = TryGetLogChannel(users.First().Guild, logSetting, LogType.Other)) == null) return; var punishment = ""; @@ -177,7 +178,7 @@ namespace NadekoBot.Modules.Administration punishment = "⛔️ BANNED"; //punishment = "BANNED"; } - await logChannel.SendMessageAsync(String.Join("\n",users.Select(user=>$"‼️ {Format.Bold(user.ToString())} got **{punishment}** due to __**{protection}**__ protection on **{user.Guild.Name}** server."))) + await logChannel.SendMessageAsync(String.Join("\n", users.Select(user => $"‼️ {Format.Bold(user.ToString())} got **{punishment}** due to __**{protection}**__ protection on **{user.Guild.Name}** server."))) //await logChannel.SendMessageAsync(String.Join("\n",users.Select(user=>$"{Format.Bold(user.ToString())} was **{punishment}** due to `{protection}` protection on **{user.Guild.Name}** server."))) .ConfigureAwait(false); } @@ -186,12 +187,11 @@ namespace NadekoBot.Modules.Administration { LogSetting logSetting; if (!GuildLogSettings.TryGetValue(before.Guild.Id, out logSetting) - || !logSetting.IsLogging - || !logSetting.UserUpdated) + || (logSetting.UserUpdatedId == null)) return Task.CompletedTask; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(before.Guild, logSetting)) == null) + if ((logChannel = TryGetLogChannel(before.Guild, logSetting, LogType.UserUpdated)) == null) return Task.CompletedTask; var task = Task.Run(async () => @@ -204,7 +204,7 @@ namespace NadekoBot.Modules.Administration str += $"👤__**{before.Username}#{before.Discriminator}**__ **| Name Changed |** 🆔 `{before.Id}`\n\t\t`New:` **{after.ToString()}**"; else if (before.Nickname != after.Nickname) str += $"👤__**{before.Username}#{before.Discriminator}**__ **| Nickname Changed |** 🆔 `{before.Id}`\n\t\t`Old:` **{before.Nickname}#{before.Discriminator}**\n\t\t`New:` **{after.Nickname}#{after.Discriminator}**"; - //str += $"**Nickname Changed**`{before.Username}#{before.Discriminator}`\n\t\t`Old:` {before.Nickname}#{before.Discriminator}\n\t\t`New:` {after.Nickname}#{after.Discriminator}"; + //str += $"**Nickname Changed**`{before.Username}#{before.Discriminator}`\n\t\t`Old:` {before.Nickname}#{before.Discriminator}\n\t\t`New:` {after.Nickname}#{after.Discriminator}"; else if (before.AvatarUrl != after.AvatarUrl) //str += $"**Avatar Changed**👤`{before.Username}#{before.Discriminator}`\n\t {await _google.ShortenUrl(before.AvatarUrl)} `=>` {await _google.ShortenUrl(after.AvatarUrl)}"; str += $"👤__**{before.Username}#{before.Discriminator}**__ **| Avatar Changed |** 🆔 `{before.Id}`\n\t🖼 {await _google.ShortenUrl(before.AvatarUrl)} `=>` {await _google.ShortenUrl(after.AvatarUrl)}"; @@ -242,13 +242,12 @@ namespace NadekoBot.Modules.Administration LogSetting logSetting; if (!GuildLogSettings.TryGetValue(before.Guild.Id, out logSetting) - || !logSetting.IsLogging - || !logSetting.ChannelUpdated + || (logSetting.ChannelUpdatedId == null) || logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == after.Id)) return Task.CompletedTask; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(before.Guild, logSetting)) == null) + if ((logChannel = TryGetLogChannel(before.Guild, logSetting, LogType.ChannelUpdated)) == null) return Task.CompletedTask; var task = Task.Run(async () => @@ -280,13 +279,12 @@ namespace NadekoBot.Modules.Administration LogSetting logSetting; if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out logSetting) - || !logSetting.IsLogging - || !logSetting.ChannelDestroyed - || logSetting.IgnoredChannels.Any(ilc=>ilc.ChannelId == ch.Id)) + || (logSetting.ChannelDestroyedId == null) + || logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == ch.Id)) return Task.CompletedTask; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(ch.Guild, logSetting)) == null) + if ((logChannel = TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelDestroyed)) == null) return Task.CompletedTask; var task = Task.Run(async () => @@ -305,12 +303,11 @@ namespace NadekoBot.Modules.Administration LogSetting logSetting; if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out logSetting) - || !logSetting.IsLogging - || !logSetting.ChannelCreated) + || (logSetting.ChannelCreatedId == null)) return Task.CompletedTask; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(ch.Guild, logSetting)) == null) + if ((logChannel = TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelCreated)) == null) return Task.CompletedTask; var task = Task.Run(async () => @@ -335,28 +332,28 @@ namespace NadekoBot.Modules.Administration LogSetting logSetting; if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting) - || !logSetting.LogVoicePresence) + || (logSetting.LogVoicePresenceId == null)) return Task.CompletedTask; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogChannelType.Voice)) == null) + if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.VoicePresence)) == null) return Task.CompletedTask; - string str = null; - if (beforeVch?.Guild == afterVch?.Guild) - { - str = $"🎙`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__ moved from **{beforeVch.Name}** to **{afterVch.Name}** voice channel."; - } - else if (beforeVch == null) - { - str = $"🎙`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__ has joined **{afterVch.Name}** voice channel."; - } - else if (afterVch == null) - { - str = $"🎙`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__ has left **{beforeVch.Name}** voice channel."; - } - if(str != null) - UserPresenceUpdates.AddOrUpdate(logChannel, new List() { str }, (id, list) => { list.Add(str); return list; }); + string str = null; + if (beforeVch?.Guild == afterVch?.Guild) + { + str = $"🎙`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__ moved from **{beforeVch.Name}** to **{afterVch.Name}** voice channel."; + } + else if (beforeVch == null) + { + str = $"🎙`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__ has joined **{afterVch.Name}** voice channel."; + } + else if (afterVch == null) + { + str = $"🎙`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__ has left **{beforeVch.Name}** voice channel."; + } + if (str != null) + UserPresenceUpdates.AddOrUpdate(logChannel, new List() { str }, (id, list) => { list.Add(str); return list; }); return Task.CompletedTask; } @@ -365,12 +362,12 @@ namespace NadekoBot.Modules.Administration { LogSetting logSetting; if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting) - || !logSetting.LogUserPresence + || (logSetting.LogUserPresenceId == null) || before.Status == after.Status) return Task.CompletedTask; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogChannelType.UserPresence)) == null) + if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserPresence)) == null) return Task.CompletedTask; string str; if (before.Status != after.Status) @@ -387,12 +384,11 @@ namespace NadekoBot.Modules.Administration { LogSetting logSetting; if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting) - || !logSetting.IsLogging - || !logSetting.UserLeft) + || (logSetting.UserLeftId == null)) return Task.CompletedTask; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(usr.Guild, logSetting)) == null) + if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserLeft)) == null) return Task.CompletedTask; var task = Task.Run(async () => @@ -407,12 +403,11 @@ namespace NadekoBot.Modules.Administration { LogSetting logSetting; if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting) - || !logSetting.IsLogging - || !logSetting.UserJoined) + || (logSetting.UserJoinedId == null)) return Task.CompletedTask; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(usr.Guild, logSetting)) == null) + if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogType.UserJoined)) == null) return Task.CompletedTask; var task = Task.Run(async () => @@ -427,17 +422,16 @@ namespace NadekoBot.Modules.Administration { LogSetting logSetting; if (!GuildLogSettings.TryGetValue(guild.Id, out logSetting) - || !logSetting.IsLogging - || !logSetting.UserUnbanned) + || (logSetting.UserUnbannedId == null)) return Task.CompletedTask; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(guild, logSetting)) == null) + if ((logChannel = TryGetLogChannel(guild, logSetting, LogType.UserUnbanned)) == null) return Task.CompletedTask; var task = Task.Run(async () => { - try { await logChannel.SendMessageAsync($"❕🕘`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__♻️ **| USER UN-BANNED |** 🆔 `{usr.Id}`").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } + try { await logChannel.SendMessageAsync($"❕🕘`{prettyCurrentTime}`👤__**{usr.Username}#{usr.Discriminator}**__♻️ **| USER UN-BANNED |** 🆔 `{usr.Id}`").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } }); return Task.CompletedTask; @@ -447,12 +441,11 @@ namespace NadekoBot.Modules.Administration { LogSetting logSetting; if (!GuildLogSettings.TryGetValue(guild.Id, out logSetting) - || !logSetting.IsLogging - || !logSetting.UserBanned) + || (logSetting.UserBannedId == null)) return Task.CompletedTask; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(guild, logSetting)) == null) + if ((logChannel = TryGetLogChannel(guild, logSetting, LogType.UserBanned)) == null) return Task.CompletedTask; var task = Task.Run(async () => @@ -475,13 +468,12 @@ namespace NadekoBot.Modules.Administration LogSetting logSetting; if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting) - || !logSetting.IsLogging - || !logSetting.MessageDeleted + || (logSetting.MessageDeletedId == null) || logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == channel.Id)) return Task.CompletedTask; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(channel.Guild, logSetting)) == null || logChannel.Id == msg.Id) + if ((logChannel = TryGetLogChannel(channel.Guild, logSetting, LogType.MessageDeleted)) == null || logChannel.Id == msg.Id) return Task.CompletedTask; var task = Task.Run(async () => @@ -519,19 +511,18 @@ namespace NadekoBot.Modules.Administration LogSetting logSetting; if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting) - || !logSetting.IsLogging - || !logSetting.MessageUpdated + || (logSetting.MessageUpdatedId == null) || logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == channel.Id)) return Task.CompletedTask; ITextChannel logChannel; - if ((logChannel = TryGetLogChannel(channel.Guild, logSetting)) == null || logChannel.Id == after.Channel.Id) + if ((logChannel = TryGetLogChannel(channel.Guild, logSetting, LogType.MessageUpdated)) == null || logChannel.Id == after.Channel.Id) return Task.CompletedTask; var task = Task.Run(async () => { //try { await logChannel.SendMessageAsync($@"🕔`{prettyCurrentTime}` **Message** 📝 `#{channel.Name}` -//👤`{before.Author.Username}` + //👤`{before.Author.Username}` try { await logChannel.SendMessageAsync($@"🕔`{prettyCurrentTime}`👤__**{before.Author.Username}#{before.Author.Discriminator}**__ **| 📝 Edited Message |** 🆔 `{before.Author.Id}` #⃣ `{channel.Name}` `Old:` {before.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator).SanitizeMentions()} **`New:`** {after.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator).SanitizeMentions()}").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } @@ -540,70 +531,175 @@ namespace NadekoBot.Modules.Administration return Task.CompletedTask; } - private enum LogChannelType { Text, Voice, UserPresence }; - private static ITextChannel TryGetLogChannel(IGuild guild, LogSetting logSetting, LogChannelType logChannelType = LogChannelType.Text) + public enum LogType { - ulong id = 0; + Other, + MessageUpdated, + MessageDeleted, + UserJoined, + UserLeft, + UserBanned, + UserUnbanned, + UserUpdated, + ChannelCreated, + ChannelDestroyed, + ChannelUpdated, + UserPresence, + VoicePresence, + VoicePresenceTTS, + UserMuted + }; + + private static ITextChannel TryGetLogChannel(IGuild guild, LogSetting logSetting, LogType logChannelType) + { + ulong? id = null; switch (logChannelType) { - case LogChannelType.Text: - id = logSetting.ChannelId; + case LogType.Other: + id = logSetting.LogOtherId; break; - case LogChannelType.Voice: - id = logSetting.VoicePresenceChannelId; + case LogType.MessageUpdated: + id = logSetting.MessageUpdatedId; break; - case LogChannelType.UserPresence: - id = logSetting.UserPresenceChannelId; + case LogType.MessageDeleted: + id = logSetting.MessageDeletedId; + break; + case LogType.UserJoined: + id = logSetting.UserJoinedId; + break; + case LogType.UserLeft: + id = logSetting.UserLeftId; + break; + case LogType.UserBanned: + id = logSetting.UserBannedId; + break; + case LogType.UserUnbanned: + id = logSetting.UserUnbannedId; + break; + case LogType.UserUpdated: + id = logSetting.UserUpdatedId; + break; + case LogType.ChannelCreated: + id = logSetting.ChannelCreatedId; + break; + case LogType.ChannelDestroyed: + id = logSetting.ChannelDestroyedId; + break; + case LogType.ChannelUpdated: + id = logSetting.ChannelUpdatedId; + break; + case LogType.UserPresence: + id = logSetting.LogUserPresenceId; + break; + case LogType.VoicePresence: + id = logSetting.LogVoicePresenceId; + break; + case LogType.VoicePresenceTTS: + id = logSetting.LogVoicePresenceTTSId; + break; + case LogType.UserMuted: + id = logSetting.UserMutedId; + break; + default: break; } - var channel = guild.GetTextChannel(id); + + if (!id.HasValue) + { + UnsetLogSetting(guild.Id, logChannelType); + return null; + } + var channel = guild.GetTextChannel(id.Value); if (channel == null) - using (var uow = DbHandler.UnitOfWork()) - { - var newLogSetting = uow.GuildConfigs.For(guild.Id).LogSetting; - switch (logChannelType) - { - case LogChannelType.Text: - logSetting.IsLogging = false; - break; - case LogChannelType.Voice: - logSetting.LogVoicePresence = false; - break; - case LogChannelType.UserPresence: - logSetting.LogUserPresence = false; - break; - } - GuildLogSettings.AddOrUpdate(guild.Id, newLogSetting, (gid, old) => newLogSetting); - uow.Complete(); - return null; - } + { + UnsetLogSetting(guild.Id, logChannelType); + return null; + } else return channel; } + private static void UnsetLogSetting(ulong guildId, LogType logChannelType) + { + using (var uow = DbHandler.UnitOfWork()) + { + var newLogSetting = uow.GuildConfigs.LogSettingsFor(guildId).LogSetting; + switch (logChannelType) + { + case LogType.Other: + break; + case LogType.MessageUpdated: + break; + case LogType.MessageDeleted: + break; + case LogType.UserJoined: + break; + case LogType.UserLeft: + break; + case LogType.UserBanned: + break; + case LogType.UserUnbanned: + break; + case LogType.UserUpdated: + break; + case LogType.ChannelCreated: + break; + case LogType.ChannelDestroyed: + break; + case LogType.ChannelUpdated: + break; + case LogType.UserPresence: + break; + case LogType.VoicePresence: + break; + case LogType.VoicePresenceTTS: + break; + default: + break; + } + GuildLogSettings.AddOrUpdate(guildId, newLogSetting, (gid, old) => newLogSetting); + uow.Complete(); + } + } + + public enum EnableDisable + { + Enable, + Disable + } + [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [RequirePermission(GuildPermission.Administrator)] [OwnerOnly] - public async Task LogServer(IUserMessage msg) + public async Task LogServer(IUserMessage msg, PermissionAction action) { var channel = (ITextChannel)msg.Channel; LogSetting logSetting; using (var uow = DbHandler.UnitOfWork()) { - logSetting = uow.GuildConfigs.For(channel.Guild.Id).LogSetting; + logSetting = uow.GuildConfigs.LogSettingsFor(channel.Guild.Id).LogSetting; GuildLogSettings.AddOrUpdate(channel.Guild.Id, (id) => logSetting, (id, old) => logSetting); - logSetting.IsLogging = !logSetting.IsLogging; - if (logSetting.IsLogging) - logSetting.ChannelId = channel.Id; - await uow.CompleteAsync(); + logSetting.LogOtherId = + logSetting.MessageUpdatedId = + logSetting.MessageDeletedId = + logSetting.UserJoinedId = + logSetting.UserLeftId = + logSetting.UserBannedId = + logSetting.UserUnbannedId = + logSetting.UserUpdatedId = + logSetting.ChannelCreatedId = + logSetting.ChannelDestroyedId = + logSetting.ChannelUpdatedId = + logSetting.LogUserPresenceId = + logSetting.LogVoicePresenceId = + logSetting.LogVoicePresenceTTSId = (action.Value ? channel.Id : (ulong?)null); } - - if (logSetting.IsLogging) - await channel.SendMessageAsync("✅ **Logging enabled.**").ConfigureAwait(false); + if (action.Value) + await channel.SendMessageAsync("✅ Logging all events on this channel.").ConfigureAwait(false); else - await channel.SendMessageAsync("ℹ️ **Logging disabled.**").ConfigureAwait(false); + await channel.SendMessageAsync("ℹ️ Logging disabled.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -616,7 +712,7 @@ namespace NadekoBot.Modules.Administration int removed; using (var uow = DbHandler.UnitOfWork()) { - var config = uow.GuildConfigs.For(channel.Guild.Id); + var config = uow.GuildConfigs.LogSettingsFor(channel.Guild.Id); LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting); removed = logSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == channel.Id); config.LogSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == channel.Id); @@ -635,146 +731,82 @@ namespace NadekoBot.Modules.Administration await channel.SendMessageAsync($"ℹ️ Logging will **no longer ignore** #⃣ `{channel.Name} ({channel.Id})`").ConfigureAwait(false); } - //[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias] - //[RequireContext(ContextType.Guild)] - //[OwnerOnly] - //public async Task LogAdd(IUserMessage msg, [Remainder] string eventName) - //{ - // var channel = (ITextChannel)msg.Channel; - // //eventName = eventName?.Replace(" ","").ToLowerInvariant(); - - // switch (eventName.ToLowerInvariant()) - // { - // case "messageupdated": - // case "messagedeleted": - // case "userjoined": - // case "userleft": - // case "userbanned": - // case "userunbanned": - // case "channelcreated": - // case "channeldestroyed": - // case "channelupdated": - // using (var uow = DbHandler.UnitOfWork()) - // { - // var logSetting = uow.GuildConfigs.For(channel.Guild.Id).LogSetting; - // GuildLogSettings.AddOrUpdate(channel.Guild.Id, (id) => logSetting, (id, old) => logSetting); - // var prop = logSetting.GetType().GetProperty(eventName); - // prop.SetValue(logSetting, true); - // await uow.CompleteAsync().ConfigureAwait(false); - // } - // await channel.SendMessageAsync($"`Now logging {eventName} event.`").ConfigureAwait(false); - // break; - // default: - // await channel.SendMessageAsync($"`Event \"{eventName}\" not found.`").ConfigureAwait(false); - // break; - // } - //} - - //[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias] - //[RequireContext(ContextType.Guild)] - //public async Task LogRemove(IUserMessage msg, string eventName) - //{ - // var channel = (ITextChannel)msg.Channel; - // eventName = eventName.ToLowerInvariant(); - - // switch (eventName) - // { - // case "messagereceived": - // case "messageupdated": - // case "messagedeleted": - // case "userjoined": - // case "userleft": - // case "userbanned": - // case "userunbanned": - // case "channelcreated": - // case "channeldestroyed": - // case "channelupdated": - // using (var uow = DbHandler.UnitOfWork()) - // { - // var config = uow.GuildConfigs.For(channel.Guild.Id); - // LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting); - // logSetting.GetType().GetProperty(eventName).SetValue(logSetting, false); - // config.LogSetting = logSetting; - // await uow.CompleteAsync().ConfigureAwait(false); - // } - // await channel.SendMessageAsync($"`No longer logging {eventName} event.`").ConfigureAwait(false); - // break; - // default: - // await channel.SendMessageAsync($"`Event \"{eventName}\" not found.`").ConfigureAwait(false); - // break; - // } - //} - [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [RequirePermission(GuildPermission.Administrator)] - public async Task UserPresence(IUserMessage imsg) + public async Task LogEvents(IUserMessage imsg) { - var channel = (ITextChannel)imsg.Channel; - bool enabled; - using (var uow = DbHandler.UnitOfWork()) - { - var logSetting = uow.GuildConfigs.For(channel.Guild.Id).LogSetting; - GuildLogSettings.AddOrUpdate(channel.Guild.Id, (id) => logSetting, (id, old) => logSetting); - enabled = logSetting.LogUserPresence = !logSetting.LogUserPresence; - if(enabled) - logSetting.UserPresenceChannelId = channel.Id; - await uow.CompleteAsync().ConfigureAwait(false); - } - - if (enabled) - await channel.SendMessageAsync($"✅ Logging **user presence** updates in #⃣ `{channel.Name} ({channel.Id})`").ConfigureAwait(false); - else - await channel.SendMessageAsync($"ℹ️ Stopped logging **user presence** updates.").ConfigureAwait(false); + await imsg.Channel.SendConfirmAsync("Log events you can subscribe to:", String.Join(", ", Enum.GetNames(typeof(LogType)).Cast())); } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [RequirePermission(GuildPermission.Administrator)] - public async Task VoicePresence(IUserMessage imsg) + public async Task Log(IUserMessage imsg, LogType type) { var channel = (ITextChannel)imsg.Channel; - bool enabled; + ulong? channelId = null; using (var uow = DbHandler.UnitOfWork()) { - var logSetting = uow.GuildConfigs.For(channel.Guild.Id, set => set.Include(gc => gc.LogSetting) - .ThenInclude(ls => ls.IgnoredVoicePresenceChannelIds)) - .LogSetting; + var logSetting = uow.GuildConfigs.LogSettingsFor(channel.Guild.Id).LogSetting; GuildLogSettings.AddOrUpdate(channel.Guild.Id, (id) => logSetting, (id, old) => logSetting); - enabled = logSetting.LogVoicePresence = !logSetting.LogVoicePresence; - if (enabled) - logSetting.VoicePresenceChannelId = channel.Id; + switch (type) + { + case LogType.Other: + channelId = logSetting.LogOtherId = (logSetting.LogOtherId == null ? channel.Id : default(ulong?)); + break; + case LogType.MessageUpdated: + channelId = logSetting.MessageUpdatedId = (logSetting.MessageUpdatedId == null ? channel.Id : default(ulong?)); + break; + case LogType.MessageDeleted: + channelId = logSetting.MessageDeletedId = (logSetting.MessageDeletedId == null ? channel.Id : default(ulong?)); + break; + case LogType.UserJoined: + channelId = logSetting.UserJoinedId = (logSetting.UserJoinedId == null ? channel.Id : default(ulong?)); + break; + case LogType.UserLeft: + channelId = logSetting.UserLeftId = (logSetting.UserLeftId == null ? channel.Id : default(ulong?)); + break; + case LogType.UserBanned: + channelId = logSetting.UserBannedId = (logSetting.UserBannedId == null ? channel.Id : default(ulong?)); + break; + case LogType.UserUnbanned: + channelId = logSetting.UserUnbannedId = (logSetting.UserUnbannedId == null ? channel.Id : default(ulong?)); + break; + case LogType.UserUpdated: + channelId = logSetting.UserUpdatedId = (logSetting.UserUpdatedId == null ? channel.Id : default(ulong?)); + break; + case LogType.UserMuted: + channelId = logSetting.UserMutedId = (logSetting.UserMutedId == null ? channel.Id : default(ulong?)); + break; + case LogType.ChannelCreated: + channelId = logSetting.ChannelCreatedId = (logSetting.ChannelCreatedId == null ? channel.Id : default(ulong?)); + break; + case LogType.ChannelDestroyed: + channelId = logSetting.ChannelDestroyedId = (logSetting.ChannelDestroyedId == null ? channel.Id : default(ulong?)); + break; + case LogType.ChannelUpdated: + channelId = logSetting.ChannelUpdatedId = (logSetting.ChannelUpdatedId == null ? channel.Id : default(ulong?)); + break; + case LogType.UserPresence: + channelId = logSetting.LogUserPresenceId = (logSetting.LogUserPresenceId == null ? channel.Id : default(ulong?)); + break; + case LogType.VoicePresence: + channelId = logSetting.LogVoicePresenceId = (logSetting.LogVoicePresenceId == null ? channel.Id : default(ulong?)); + break; + case LogType.VoicePresenceTTS: + channelId = logSetting.LogVoicePresenceTTSId = (logSetting.LogVoicePresenceTTSId == null ? channel.Id : default(ulong?)); + break; + } + await uow.CompleteAsync().ConfigureAwait(false); } - if (enabled) - await channel.SendMessageAsync($"✅ Logging **voice presence** updates in #⃣ `{channel.Name} ({channel.Id})`").ConfigureAwait(false); + if (channelId != null) + await channel.SendMessageAsync($"✅ Logging `{type}` event in #⃣ `{channel.Name} ({channel.Id})`").ConfigureAwait(false); else - await channel.SendMessageAsync($"ℹ️ Stopped logging **voice presence** updates.").ConfigureAwait(false); + await channel.SendMessageAsync($"ℹ️ Stopped logging `{type}` event.").ConfigureAwait(false); } - - //[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias] - //[RequireContext(ContextType.Guild)] - //public async Task VoiPresIgnore(IUserMessage imsg, IVoiceChannel voiceChannel) - //{ - // var channel = (ITextChannel)imsg.Channel; - // int removed; - // using (var uow = DbHandler.UnitOfWork()) - // { - // var config = uow.GuildConfigs.For(channel.Guild.Id); - // LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting); - // removed = logSetting.IgnoredVoicePresenceChannelIds.RemoveWhere(ivpc => ivpc.ChannelId == voiceChannel.Id); - // if (removed == 0) - // logSetting.IgnoredVoicePresenceChannelIds.Add(new IgnoredVoicePresenceChannel { ChannelId = voiceChannel.Id }); - // config.LogSetting = logSetting; - // await uow.CompleteAsync().ConfigureAwait(false); - // } - - // if (removed == 0) - // await channel.SendMessageAsync($"`Enabled logging voice presence updates for {voiceChannel.Name} ({voiceChannel.Id}) channel.`").ConfigureAwait(false); - // else - // await channel.SendMessageAsync($"`Disabled logging voice presence updates for {voiceChannel.Name} ({voiceChannel.Id}) channel.`").ConfigureAwait(false); - //} } } -} +} \ No newline at end of file diff --git a/src/NadekoBot/Modules/Administration/Commands/Migration.cs b/src/NadekoBot/Modules/Administration/Commands/Migration.cs index 7027488a..9d323245 100644 --- a/src/NadekoBot/Modules/Administration/Commands/Migration.cs +++ b/src/NadekoBot/Modules/Administration/Commands/Migration.cs @@ -195,12 +195,9 @@ namespace NadekoBot.Modules.Administration guildConfig.GenerateCurrencyChannelIds = new HashSet(data.GenerateCurrencyChannels.Select(gc => new GCChannelId() { ChannelId = gc.Key })); selfAssRoles.AddRange(data.ListOfSelfAssignableRoles.Select(r => new SelfAssignedRole() { GuildId = guildConfig.GuildId, RoleId = r }).ToArray()); var logSetting = guildConfig.LogSetting; - guildConfig.LogSetting.IsLogging = data.LogChannel != null; - guildConfig.LogSetting.ChannelId = data.LogChannel ?? 0; guildConfig.LogSetting.IgnoredChannels = new HashSet(data.LogserverIgnoreChannels.Select(id => new IgnoredLogChannel() { ChannelId = id })); - guildConfig.LogSetting.LogUserPresence = data.LogPresenceChannel != null; - guildConfig.LogSetting.UserPresenceChannelId = data.LogPresenceChannel ?? 0; + guildConfig.LogSetting.LogUserPresenceId = data.LogPresenceChannel; guildConfig.FollowedStreams = new HashSet(data.ObservingStreams.Select(x => diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index df31964a..4193bdd7 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -3920,6 +3920,60 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to log. + /// + public static string log_cmd { + get { + return ResourceManager.GetString("log_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Toggles logging event. Disables it if it's active anywhere on the server. Enables if it's not active. Use `{0}logevents` to see a lit of all events you can subscribe to.. + /// + public static string log_desc { + get { + return ResourceManager.GetString("log_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}log userpresence` or `{0}log userbanned`. + /// + public static string log_usage { + get { + return ResourceManager.GetString("log_usage", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to logevents. + /// + public static string logevents_cmd { + get { + return ResourceManager.GetString("logevents_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Shows a list of all events you can subscribe to with `{0}log`. + /// + public static string logevents_desc { + get { + return ResourceManager.GetString("logevents_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `{0}logevents`. + /// + public static string logevents_usage { + get { + return ResourceManager.GetString("logevents_usage", resourceCulture); + } + } + /// /// Looks up a localized string similar to logignore. /// @@ -3957,7 +4011,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to Logs server activity in this channel.. + /// Looks up a localized string similar to Enables or Disables ALL log events. If enabled, all log events will log to this channel.. /// public static string logserver_desc { get { @@ -3966,7 +4020,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to `{0}logserver`. + /// Looks up a localized string similar to `{0}logserver enable` or `{0}logserver disable`. /// public static string logserver_usage { get { diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 1b0f35cd..fb2998b9 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -229,10 +229,10 @@ logserver - Logs server activity in this channel. + Enables or Disables ALL log events. If enabled, all log events will log to this channel. - `{0}logserver` + `{0}logserver enable` or `{0}logserver disable` logignore @@ -2799,4 +2799,22 @@ `{0}acro` or `{0}acro 30` + + logevents + + + Shows a list of all events you can subscribe to with `{0}log` + + + `{0}logevents` + + + log + + + Toggles logging event. Disables it if it's active anywhere on the server. Enables if it's not active. Use `{0}logevents` to see a lit of all events you can subscribe to. + + + `{0}log userpresence` or `{0}log userbanned` + \ No newline at end of file diff --git a/src/NadekoBot/Services/Database/Models/LogSetting.cs b/src/NadekoBot/Services/Database/Models/LogSetting.cs index b5e841fb..659df55c 100644 --- a/src/NadekoBot/Services/Database/Models/LogSetting.cs +++ b/src/NadekoBot/Services/Database/Models/LogSetting.cs @@ -2,33 +2,104 @@ namespace NadekoBot.Services.Database.Models { + public class LogSetting : DbEntity { - public bool IsLogging { get; set; } - public ulong ChannelId { get; set; } - public HashSet IgnoredChannels { get; set; } + public HashSet IgnoredChannels { get; set; } = new HashSet(); + public HashSet IgnoredVoicePresenceChannelIds { get; set; } = new HashSet(); - public bool MessageUpdated { get; set; } = true; - public bool MessageDeleted { get; set; } = true; + public ulong? LogOtherId { get; set; } = null; + public ulong? MessageUpdatedId { get; set; } = null; + public ulong? MessageDeletedId { get; set; } = null; - public bool UserJoined { get; set; } = true; - public bool UserLeft { get; set; } = true; - public bool UserBanned { get; set; } = true; - public bool UserUnbanned { get; set; } = true; - public bool UserUpdated { get; set; } = true; + public ulong? UserJoinedId { get; set; } = null; + public ulong? UserLeftId { get; set; } = null; + public ulong? UserBannedId { get; set; } = null; + public ulong? UserUnbannedId { get; set; } = null; + public ulong? UserUpdatedId { get; set; } = null; - public bool ChannelCreated { get; set; } = true; - public bool ChannelDestroyed { get; set; } = true; - public bool ChannelUpdated { get; set; } = true; + public ulong? ChannelCreatedId { get; set; } = null; + public ulong? ChannelDestroyedId { get; set; } = null; + public ulong? ChannelUpdatedId { get; set; } = null; + + public ulong? UserMutedId { get; set; } //userpresence - public bool LogUserPresence { get; set; } = false; - public ulong UserPresenceChannelId { get; set; } + public ulong? LogUserPresenceId { get; set; } = null; //voicepresence - public bool LogVoicePresence { get; set; } = false; - public ulong VoicePresenceChannelId { get; set; } - public HashSet IgnoredVoicePresenceChannelIds { get; set; } + public ulong? LogVoicePresenceId { get; set; } = null; + public ulong? LogVoicePresenceTTSId { get; set; } = null; + + + + //-------------------DO NOT USE---------------- + // these old fields are here because sqlite doesn't support drop column operation + // will be removed after bot moves to another database provider + /// + /// DON'T USE + /// + public bool IsLogging { get; set; } + /// + /// DON'T USE + /// + public ulong ChannelId { get; set; } + /// + /// DON'T USE + /// + public bool MessageUpdated { get; set; } = true; + /// + /// DON'T USE + /// + public bool MessageDeleted { get; set; } = true; + /// + /// DON'T USE + /// + public bool UserJoined { get; set; } = true; + /// + /// DON'T USE + /// + public bool UserLeft { get; set; } = true; + /// + /// DON'T USE + /// + public bool UserBanned { get; set; } = true; + /// + /// DON'T USE + /// + public bool UserUnbanned { get; set; } = true; + /// + /// DON'T USE + /// + public bool UserUpdated { get; set; } = true; + /// + /// DON'T USE + /// + public bool ChannelCreated { get; set; } = true; + /// + /// DON'T USE + /// + public bool ChannelDestroyed { get; set; } = true; + /// + /// DON'T USE + /// + public bool ChannelUpdated { get; set; } = true; + /// + /// DON'T USE + /// + public bool LogUserPresence { get; set; } = false; + /// + /// DON'T USE + /// + public ulong UserPresenceChannelId { get; set; } + /// + /// DON'T USE + /// + public bool LogVoicePresence { get; set; } = false; + /// + /// DON'T USE + /// + public ulong VoicePresenceChannelId { get; set; } } -} +} \ No newline at end of file diff --git a/src/NadekoBot/Services/Database/Repositories/IGuildConfigRepository.cs b/src/NadekoBot/Services/Database/Repositories/IGuildConfigRepository.cs index 1fc9015d..34f3f564 100644 --- a/src/NadekoBot/Services/Database/Repositories/IGuildConfigRepository.cs +++ b/src/NadekoBot/Services/Database/Repositories/IGuildConfigRepository.cs @@ -9,6 +9,7 @@ namespace NadekoBot.Services.Database.Repositories public interface IGuildConfigRepository : IRepository { GuildConfig For(ulong guildId, Func, IQueryable> includes = null); + GuildConfig LogSettingsFor(ulong guildId); GuildConfig PermissionsFor(ulong guildId); IEnumerable PermissionsForAll(); IEnumerable GetAllGuildConfigs(); diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/GuildConfigRepository.cs b/src/NadekoBot/Services/Database/Repositories/Impl/GuildConfigRepository.cs index dc857b8b..0720e8ad 100644 --- a/src/NadekoBot/Services/Database/Repositories/Impl/GuildConfigRepository.cs +++ b/src/NadekoBot/Services/Database/Repositories/Impl/GuildConfigRepository.cs @@ -16,8 +16,6 @@ namespace NadekoBot.Services.Database.Repositories.Impl public IEnumerable GetAllGuildConfigs() => _set.Include(gc => gc.LogSetting) .ThenInclude(ls => ls.IgnoredChannels) - .Include(gc => gc.LogSetting) - .ThenInclude(ls => ls.IgnoredVoicePresenceChannelIds) .Include(gc => gc.RootPermission) .ThenInclude(gc => gc.Previous) .Include(gc => gc.RootPermission) @@ -43,10 +41,8 @@ namespace NadekoBot.Services.Database.Repositories.Impl { config = _set .Include(gc => gc.FollowedStreams) - .Include(gc => gc.LogSetting) - .ThenInclude(ls => ls.IgnoredChannels) .Include(gc => gc.LogSetting) - .ThenInclude(ls => ls.IgnoredVoicePresenceChannelIds) + .ThenInclude(ls => ls.IgnoredChannels) .Include(gc => gc.FilterInvitesChannelIds) .Include(gc => gc.FilterWordsChannelIds) .Include(gc => gc.FilteredWords) @@ -72,6 +68,13 @@ namespace NadekoBot.Services.Database.Repositories.Impl return config; } + public GuildConfig LogSettingsFor(ulong guildId) + { + return _set.Include(gc => gc.LogSetting) + .ThenInclude(gc => gc.IgnoredChannels) + .FirstOrDefault(); + } + public GuildConfig PermissionsFor(ulong guildId) { var query = _set.Include(gc => gc.RootPermission);