Work on logserver. Migrations update. Updated discord.net

This commit is contained in:
Kwoth 2016-09-05 12:27:58 +02:00
parent 397ba798a5
commit 6d50336368
16 changed files with 1386 additions and 979 deletions

@ -1 +1 @@
Subproject commit b77ec35e2e2a7049de308af5d185e9815482f117 Subproject commit b7174499feda8f98ad43323123614393ff659fc2

View File

@ -1,418 +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("20160901001820_first")]
partial class first
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "1.0.0-rtm-21431");
modelBuilder.Entity("NadekoBot.Services.Database.Models.BlacklistItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int?>("BotConfigId");
b.Property<ulong>("ItemId");
b.HasKey("Id");
b.HasIndex("BotConfigId");
b.ToTable("BlacklistItem");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.BotConfig", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<ulong>("BufferSize");
b.Property<string>("CurrencyName");
b.Property<string>("CurrencyPluralName");
b.Property<string>("CurrencySign");
b.Property<bool>("DontJoinServers");
b.Property<bool>("ForwardMessages");
b.Property<bool>("ForwardToAllOwners");
b.Property<string>("RemindMessageFormat");
b.Property<bool>("RotatingStatuses");
b.HasKey("Id");
b.ToTable("BotConfig");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.ClashCaller", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<bool>("BaseDestroyed");
b.Property<string>("CallUser");
b.Property<int>("ClashWarId");
b.Property<int>("Stars");
b.Property<DateTime>("TimeAdded");
b.HasKey("Id");
b.HasIndex("ClashWarId");
b.ToTable("ClashCallers");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.ClashWar", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<ulong>("ChannelId");
b.Property<string>("EnemyClan");
b.Property<ulong>("GuildId");
b.Property<int>("Size");
b.Property<DateTime>("StartedAt");
b.Property<int>("WarState");
b.HasKey("Id");
b.ToTable("ClashOfClans");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.Currency", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<long>("Amount");
b.Property<ulong>("UserId");
b.HasKey("Id");
b.HasIndex("UserId")
.IsUnique();
b.ToTable("Currency");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.Donator", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("Amount");
b.Property<string>("Name");
b.Property<ulong>("UserId");
b.HasKey("Id");
b.HasIndex("UserId")
.IsUnique();
b.ToTable("Donators");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.EightBallResponse", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int?>("BotConfigId");
b.Property<string>("Text");
b.HasKey("Id");
b.HasIndex("BotConfigId");
b.ToTable("EightBallResponse");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.FollowedStream", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<ulong>("ChannelId");
b.Property<int?>("GuildConfigId");
b.Property<ulong>("GuildId");
b.Property<bool>("LastStatus");
b.Property<int>("Type");
b.Property<string>("Username");
b.HasKey("Id");
b.HasIndex("GuildConfigId");
b.ToTable("FollowedStream");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.GuildConfig", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<ulong>("AutoAssignRoleId");
b.Property<bool>("AutoDeleteByeMessages");
b.Property<bool>("AutoDeleteGreetMessages");
b.Property<int>("AutoDeleteGreetMessagesTimer");
b.Property<bool>("AutoDeleteSelfAssignedRoleMessages");
b.Property<ulong>("ByeMessageChannelId");
b.Property<string>("ChannelByeMessageText");
b.Property<string>("ChannelGreetMessageText");
b.Property<float>("DefaultMusicVolume");
b.Property<bool>("DeleteMessageOnCommand");
b.Property<string>("DmGreetMessageText");
b.Property<bool>("ExclusiveSelfAssignedRoles");
b.Property<ulong>("GreetMessageChannelId");
b.Property<ulong>("GuildId");
b.Property<bool>("SendChannelByeMessage");
b.Property<bool>("SendChannelGreetMessage");
b.Property<bool>("SendDmGreetMessage");
b.Property<bool>("VoicePlusTextEnabled");
b.HasKey("Id");
b.HasIndex("GuildId")
.IsUnique();
b.ToTable("GuildConfigs");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int?>("BotConfigId");
b.Property<string>("ModuleName");
b.Property<string>("Prefix");
b.HasKey("Id");
b.HasIndex("BotConfigId");
b.ToTable("ModulePrefix");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.PlayingStatus", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int?>("BotConfigId");
b.Property<string>("Status");
b.HasKey("Id");
b.HasIndex("BotConfigId");
b.ToTable("PlayingStatus");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.Quote", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<ulong>("AuthorId");
b.Property<string>("AuthorName")
.IsRequired();
b.Property<ulong>("GuildId");
b.Property<string>("Keyword")
.IsRequired();
b.Property<string>("Text")
.IsRequired();
b.HasKey("Id");
b.ToTable("Quotes");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.RaceAnimal", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int?>("BotConfigId");
b.Property<string>("Icon");
b.Property<string>("Name");
b.HasKey("Id");
b.HasIndex("BotConfigId");
b.ToTable("RaceAnimal");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.Reminder", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<ulong>("ChannelId");
b.Property<bool>("IsPrivate");
b.Property<string>("Message");
b.Property<ulong>("ServerId");
b.Property<ulong>("UserId");
b.Property<DateTime>("When");
b.HasKey("Id");
b.ToTable("Reminders");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.Repeater", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<ulong>("ChannelId");
b.Property<ulong>("GuildId");
b.Property<TimeSpan>("Interval");
b.Property<string>("Message");
b.HasKey("Id");
b.HasIndex("ChannelId")
.IsUnique();
b.ToTable("Repeaters");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.SelfAssignedRole", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<ulong>("GuildId");
b.Property<ulong>("RoleId");
b.HasKey("Id");
b.HasIndex("GuildId", "RoleId")
.IsUnique();
b.ToTable("SelfAssignableRoles");
});
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.ModulePrefix", b =>
{
b.HasOne("NadekoBot.Services.Database.Models.BotConfig")
.WithMany("ModulePrefixes")
.HasForeignKey("BotConfigId");
});
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");
});
}
}
}

View File

@ -1,32 +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)
{
migrationBuilder.CreateTable(
name: "TypingArticles",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Autoincrement", true),
Author = table.Column<string>(nullable: true),
Text = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_TypingArticles", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "TypingArticles");
}
}
}

View File

@ -8,8 +8,8 @@ using NadekoBot.Services.Database.Impl;
namespace NadekoBot.Migrations namespace NadekoBot.Migrations
{ {
[DbContext(typeof(NadekoSqliteContext))] [DbContext(typeof(NadekoSqliteContext))]
[Migration("20160901010812_second")] [Migration("20160905095544_first")]
partial class second partial class first
{ {
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
{ {
@ -104,6 +104,22 @@ namespace NadekoBot.Migrations
b.ToTable("ClashOfClans"); b.ToTable("ClashOfClans");
}); });
modelBuilder.Entity("NadekoBot.Services.Database.Models.ConvertUnit", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("InternalTrigger");
b.Property<decimal>("Modifier");
b.Property<string>("UnitType");
b.HasKey("Id");
b.ToTable("ConversionUnits");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.Currency", b => modelBuilder.Entity("NadekoBot.Services.Database.Models.Currency", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -213,6 +229,8 @@ namespace NadekoBot.Migrations
b.Property<ulong>("GuildId"); b.Property<ulong>("GuildId");
b.Property<int?>("LogSettingId");
b.Property<bool>("SendChannelByeMessage"); b.Property<bool>("SendChannelByeMessage");
b.Property<bool>("SendChannelGreetMessage"); b.Property<bool>("SendChannelGreetMessage");
@ -226,9 +244,87 @@ namespace NadekoBot.Migrations
b.HasIndex("GuildId") b.HasIndex("GuildId")
.IsUnique(); .IsUnique();
b.HasIndex("LogSettingId");
b.ToTable("GuildConfigs"); b.ToTable("GuildConfigs");
}); });
modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredLogChannel", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<ulong>("ChannelId");
b.Property<int?>("LogSettingId");
b.HasKey("Id");
b.HasIndex("LogSettingId");
b.ToTable("IgnoredLogChannels");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredVoicePresenceChannel", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<ulong>("ChannelId");
b.Property<int?>("LogSettingId");
b.HasKey("Id");
b.HasIndex("LogSettingId");
b.ToTable("IgnoredVoicePresenceCHannels");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.LogSetting", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<bool>("ChannelCreated");
b.Property<bool>("ChannelDestroyed");
b.Property<ulong>("ChannelId");
b.Property<bool>("ChannelUpdated");
b.Property<bool>("IsLogging");
b.Property<bool>("LogUserPresence");
b.Property<bool>("LogVoicePresence");
b.Property<bool>("MessageDeleted");
b.Property<bool>("MessageReceived");
b.Property<bool>("MessageUpdated");
b.Property<bool>("UserBanned");
b.Property<bool>("UserJoined");
b.Property<bool>("UserLeft");
b.Property<ulong>("UserPresenceChannelId");
b.Property<bool>("UserUnbanned");
b.Property<bool>("UserUpdated");
b.Property<ulong>("VoicePresenceChannelId");
b.HasKey("Id");
b.ToTable("LogSettings");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b => modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -407,6 +503,27 @@ namespace NadekoBot.Migrations
.HasForeignKey("GuildConfigId"); .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 => modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b =>
{ {
b.HasOne("NadekoBot.Services.Database.Models.BotConfig") b.HasOne("NadekoBot.Services.Database.Models.BotConfig")

View File

@ -47,6 +47,21 @@ namespace NadekoBot.Migrations
table.PrimaryKey("PK_ClashOfClans", x => x.Id); table.PrimaryKey("PK_ClashOfClans", x => x.Id);
}); });
migrationBuilder.CreateTable(
name: "ConversionUnits",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Autoincrement", true),
InternalTrigger = table.Column<string>(nullable: true),
Modifier = table.Column<decimal>(nullable: false),
UnitType = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ConversionUnits", x => x.Id);
});
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Currency", name: "Currency",
columns: table => new columns: table => new
@ -77,33 +92,32 @@ namespace NadekoBot.Migrations
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "GuildConfigs", name: "LogSettings",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(nullable: false) Id = table.Column<int>(nullable: false)
.Annotation("Autoincrement", true), .Annotation("Autoincrement", true),
AutoAssignRoleId = table.Column<ulong>(nullable: false), ChannelCreated = table.Column<bool>(nullable: false),
AutoDeleteByeMessages = table.Column<bool>(nullable: false), ChannelDestroyed = table.Column<bool>(nullable: false),
AutoDeleteGreetMessages = table.Column<bool>(nullable: false), ChannelId = table.Column<ulong>(nullable: false),
AutoDeleteGreetMessagesTimer = table.Column<int>(nullable: false), ChannelUpdated = table.Column<bool>(nullable: false),
AutoDeleteSelfAssignedRoleMessages = table.Column<bool>(nullable: false), IsLogging = table.Column<bool>(nullable: false),
ByeMessageChannelId = table.Column<ulong>(nullable: false), LogUserPresence = table.Column<bool>(nullable: false),
ChannelByeMessageText = table.Column<string>(nullable: true), LogVoicePresence = table.Column<bool>(nullable: false),
ChannelGreetMessageText = table.Column<string>(nullable: true), MessageDeleted = table.Column<bool>(nullable: false),
DefaultMusicVolume = table.Column<float>(nullable: false), MessageReceived = table.Column<bool>(nullable: false),
DeleteMessageOnCommand = table.Column<bool>(nullable: false), MessageUpdated = table.Column<bool>(nullable: false),
DmGreetMessageText = table.Column<string>(nullable: true), UserBanned = table.Column<bool>(nullable: false),
ExclusiveSelfAssignedRoles = table.Column<bool>(nullable: false), UserJoined = table.Column<bool>(nullable: false),
GreetMessageChannelId = table.Column<ulong>(nullable: false), UserLeft = table.Column<bool>(nullable: false),
GuildId = table.Column<ulong>(nullable: false), UserPresenceChannelId = table.Column<ulong>(nullable: false),
SendChannelByeMessage = table.Column<bool>(nullable: false), UserUnbanned = table.Column<bool>(nullable: false),
SendChannelGreetMessage = table.Column<bool>(nullable: false), UserUpdated = table.Column<bool>(nullable: false),
SendDmGreetMessage = table.Column<bool>(nullable: false), VoicePresenceChannelId = table.Column<ulong>(nullable: false)
VoicePlusTextEnabled = table.Column<bool>(nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_GuildConfigs", x => x.Id); table.PrimaryKey("PK_LogSettings", x => x.Id);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
@ -171,6 +185,20 @@ namespace NadekoBot.Migrations
table.PrimaryKey("PK_SelfAssignableRoles", x => x.Id); table.PrimaryKey("PK_SelfAssignableRoles", x => x.Id);
}); });
migrationBuilder.CreateTable(
name: "TypingArticles",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Autoincrement", true),
Author = table.Column<string>(nullable: true),
Text = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_TypingArticles", x => x.Id);
});
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "BlacklistItem", name: "BlacklistItem",
columns: table => new columns: table => new
@ -296,6 +324,83 @@ namespace NadekoBot.Migrations
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable(
name: "GuildConfigs",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Autoincrement", true),
AutoAssignRoleId = table.Column<ulong>(nullable: false),
AutoDeleteByeMessages = table.Column<bool>(nullable: false),
AutoDeleteGreetMessages = table.Column<bool>(nullable: false),
AutoDeleteGreetMessagesTimer = table.Column<int>(nullable: false),
AutoDeleteSelfAssignedRoleMessages = table.Column<bool>(nullable: false),
ByeMessageChannelId = table.Column<ulong>(nullable: false),
ChannelByeMessageText = table.Column<string>(nullable: true),
ChannelGreetMessageText = table.Column<string>(nullable: true),
DefaultMusicVolume = table.Column<float>(nullable: false),
DeleteMessageOnCommand = table.Column<bool>(nullable: false),
DmGreetMessageText = table.Column<string>(nullable: true),
ExclusiveSelfAssignedRoles = table.Column<bool>(nullable: false),
GreetMessageChannelId = table.Column<ulong>(nullable: false),
GuildId = table.Column<ulong>(nullable: false),
LogSettingId = table.Column<int>(nullable: true),
SendChannelByeMessage = table.Column<bool>(nullable: false),
SendChannelGreetMessage = table.Column<bool>(nullable: false),
SendDmGreetMessage = table.Column<bool>(nullable: false),
VoicePlusTextEnabled = table.Column<bool>(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
{
Id = table.Column<int>(nullable: false)
.Annotation("Autoincrement", true),
ChannelId = table.Column<ulong>(nullable: false),
LogSettingId = table.Column<int>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_IgnoredLogChannels", x => x.Id);
table.ForeignKey(
name: "FK_IgnoredLogChannels_LogSettings_LogSettingId",
column: x => x.LogSettingId,
principalTable: "LogSettings",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "IgnoredVoicePresenceCHannels",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Autoincrement", true),
ChannelId = table.Column<ulong>(nullable: false),
LogSettingId = table.Column<int>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_IgnoredVoicePresenceCHannels", x => x.Id);
table.ForeignKey(
name: "FK_IgnoredVoicePresenceCHannels_LogSettings_LogSettingId",
column: x => x.LogSettingId,
principalTable: "LogSettings",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "FollowedStream", name: "FollowedStream",
columns: table => new columns: table => new
@ -358,6 +463,21 @@ namespace NadekoBot.Migrations
column: "GuildId", column: "GuildId",
unique: true); unique: true);
migrationBuilder.CreateIndex(
name: "IX_GuildConfigs_LogSettingId",
table: "GuildConfigs",
column: "LogSettingId");
migrationBuilder.CreateIndex(
name: "IX_IgnoredLogChannels_LogSettingId",
table: "IgnoredLogChannels",
column: "LogSettingId");
migrationBuilder.CreateIndex(
name: "IX_IgnoredVoicePresenceCHannels_LogSettingId",
table: "IgnoredVoicePresenceCHannels",
column: "LogSettingId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_ModulePrefix_BotConfigId", name: "IX_ModulePrefix_BotConfigId",
table: "ModulePrefix", table: "ModulePrefix",
@ -394,6 +514,9 @@ namespace NadekoBot.Migrations
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "ClashCallers"); name: "ClashCallers");
migrationBuilder.DropTable(
name: "ConversionUnits");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Currency"); name: "Currency");
@ -406,6 +529,12 @@ namespace NadekoBot.Migrations
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "FollowedStream"); name: "FollowedStream");
migrationBuilder.DropTable(
name: "IgnoredLogChannels");
migrationBuilder.DropTable(
name: "IgnoredVoicePresenceCHannels");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "ModulePrefix"); name: "ModulePrefix");
@ -427,6 +556,9 @@ namespace NadekoBot.Migrations
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "SelfAssignableRoles"); name: "SelfAssignableRoles");
migrationBuilder.DropTable(
name: "TypingArticles");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "ClashOfClans"); name: "ClashOfClans");
@ -435,6 +567,9 @@ namespace NadekoBot.Migrations
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "BotConfig"); name: "BotConfig");
migrationBuilder.DropTable(
name: "LogSettings");
} }
} }
} }

View File

@ -103,6 +103,22 @@ namespace NadekoBot.Migrations
b.ToTable("ClashOfClans"); b.ToTable("ClashOfClans");
}); });
modelBuilder.Entity("NadekoBot.Services.Database.Models.ConvertUnit", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("InternalTrigger");
b.Property<decimal>("Modifier");
b.Property<string>("UnitType");
b.HasKey("Id");
b.ToTable("ConversionUnits");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.Currency", b => modelBuilder.Entity("NadekoBot.Services.Database.Models.Currency", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -212,6 +228,8 @@ namespace NadekoBot.Migrations
b.Property<ulong>("GuildId"); b.Property<ulong>("GuildId");
b.Property<int?>("LogSettingId");
b.Property<bool>("SendChannelByeMessage"); b.Property<bool>("SendChannelByeMessage");
b.Property<bool>("SendChannelGreetMessage"); b.Property<bool>("SendChannelGreetMessage");
@ -225,9 +243,87 @@ namespace NadekoBot.Migrations
b.HasIndex("GuildId") b.HasIndex("GuildId")
.IsUnique(); .IsUnique();
b.HasIndex("LogSettingId");
b.ToTable("GuildConfigs"); b.ToTable("GuildConfigs");
}); });
modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredLogChannel", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<ulong>("ChannelId");
b.Property<int?>("LogSettingId");
b.HasKey("Id");
b.HasIndex("LogSettingId");
b.ToTable("IgnoredLogChannels");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredVoicePresenceChannel", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<ulong>("ChannelId");
b.Property<int?>("LogSettingId");
b.HasKey("Id");
b.HasIndex("LogSettingId");
b.ToTable("IgnoredVoicePresenceCHannels");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.LogSetting", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<bool>("ChannelCreated");
b.Property<bool>("ChannelDestroyed");
b.Property<ulong>("ChannelId");
b.Property<bool>("ChannelUpdated");
b.Property<bool>("IsLogging");
b.Property<bool>("LogUserPresence");
b.Property<bool>("LogVoicePresence");
b.Property<bool>("MessageDeleted");
b.Property<bool>("MessageReceived");
b.Property<bool>("MessageUpdated");
b.Property<bool>("UserBanned");
b.Property<bool>("UserJoined");
b.Property<bool>("UserLeft");
b.Property<ulong>("UserPresenceChannelId");
b.Property<bool>("UserUnbanned");
b.Property<bool>("UserUpdated");
b.Property<ulong>("VoicePresenceChannelId");
b.HasKey("Id");
b.ToTable("LogSettings");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b => modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -406,6 +502,27 @@ namespace NadekoBot.Migrations
.HasForeignKey("GuildConfigId"); .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 => modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b =>
{ {
b.HasOne("NadekoBot.Services.Database.Models.BotConfig") b.HasOne("NadekoBot.Services.Database.Models.BotConfig")

View File

@ -1,47 +0,0 @@
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using NadekoBot.Attributes;
using NadekoBot.Extensions;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace NadekoBot.Modules.Administration
{
public partial class Administration {
[Group]
public class LogCommands
{
private DiscordSocketClient _client;
private string prettyCurrentTime => $"【{DateTime.Now:HH:mm:ss}】";
public LogCommands(DiscordSocketClient client)
{
_client = client;
_client.MessageReceived += _client_MessageReceived;
}
private Task _client_MessageReceived(IMessage imsg)
{
var msg = imsg as IUserMessage;
if (msg == null)
return Task.CompletedTask;
return Task.CompletedTask;
}
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
[RequireContext(ContextType.Guild)]
public async Task LogServer(IUserMessage msg)
{
var channel = (ITextChannel)msg.Channel;
}
}
}
}

View File

@ -0,0 +1,466 @@
//using Discord;
//using Discord.Commands;
//using Discord.WebSocket;
//using NadekoBot.Attributes;
//using NadekoBot.Extensions;
//using NadekoBot.Services;
//using NadekoBot.Services.Database;
//using NadekoBot.Services.Database.Models;
//using NLog;
//using System;
//using System.Collections.Concurrent;
//using System.Collections.Generic;
//using System.Linq;
//using System.Reflection;
//using System.Threading.Tasks;
//namespace NadekoBot.Modules.Administration
//{
// public partial class Administration
// {
// [Group]
// public class LogCommands
// {
// private DiscordSocketClient _client { get; }
// private Logger _log { get; }
// private string prettyCurrentTime => $"【{DateTime.Now:HH:mm:ss}】";
// public ConcurrentDictionary<ulong, LogSetting> GuildLogSettings { get; }
// public LogCommands(DiscordSocketClient client)
// {
// _client = client;
// _log = LogManager.GetCurrentClassLogger();
// using (var uow = DbHandler.UnitOfWork())
// {
// GuildLogSettings = new ConcurrentDictionary<ulong, LogSetting>(uow.GuildConfigs
// .GetAll()
// .ToDictionary(g => g.GuildId, g => g.LogSetting));
// }
// _client.MessageReceived += _client_MessageReceived;
// _client.MessageUpdated += _client_MessageUpdated;
// _client.MessageDeleted += _client_MessageDeleted;
// _client.UserBanned += _client_UserBanned;
// _client.UserUnbanned += _client_UserUnbanned;
// _client.UserJoined += _client_UserJoined;
// _client.UserLeft += _client_UserLeft;
// _client.UserPresenceUpdated += _client_UserPresenceUpdated;
// _client.UserVoiceStateUpdated += _client_UserVoiceStateUpdated;
// }
// private Task _client_UserVoiceStateUpdated(IUser iusr, IVoiceState before, IVoiceState after)
// {
// var usr = iusr as IGuildUser;
// if (usr == null)
// return Task.CompletedTask;
// var beforeVch = before.VoiceChannel;
// var afterVch = after.VoiceChannel;
// if (beforeVch == afterVch)
// return Task.CompletedTask;
// LogSetting logSetting;
// if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
// || !logSetting.LogVoicePresence
// || !logSetting.IgnoredChannels.Any(ic => ic.ChannelId == after.VoiceChannel.Id))
// return Task.CompletedTask;
// ITextChannel logChannel;
// if ((logChannel = usr.Guild.GetTextChannel(logSetting.ChannelId)) == null)
// return Task.CompletedTask;
// var task = Task.Run(async () =>
// {
// if (beforeVch?.Guild == afterVch?.Guild)
// {
// await logChannel.SendMessageAsync($"🎼`{prettyCurrentTime}` {usr.Username} moved from **{beforeVch.Name}** to **{afterVch.Name}** voice channel.").ConfigureAwait(false);
// }
// else if (beforeVch == null)
// {
// await logChannel.SendMessageAsync($"🎼`{prettyCurrentTime}` {usr.Username} has joined **{afterVch.Name}** voice channel.").ConfigureAwait(false);
// }
// else if (afterVch == null)
// {
// await logChannel.SendMessageAsync($"🎼`{prettyCurrentTime}` {usr.Username} has left **{beforeVch.Name}** voice channel.").ConfigureAwait(false);
// }
// });
// return Task.CompletedTask;
// }
// private Task _client_UserPresenceUpdated(IGuildUser usr, IPresence before, IPresence after)
// {
// LogSetting logSetting;
// if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
// || !logSetting.LogUserPresence
// || before.Status == after.Status)
// return Task.CompletedTask;
// ITextChannel logChannel;
// if ((logChannel = usr.Guild.GetTextChannel(logSetting.ChannelId)) == null)
// return Task.CompletedTask;
// return Task.CompletedTask;
// }
// private Task _client_UserLeft(IGuildUser usr)
// {
// LogSetting logSetting;
// if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
// || !logSetting.IsLogging
// || !logSetting.UserLeft)
// return Task.CompletedTask;
// var task = Task.Run(async () =>
// {
// });
// return Task.CompletedTask;
// }
// private Task _client_UserJoined(IGuildUser usr)
// {
// LogSetting logSetting;
// if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
// || !logSetting.IsLogging
// || !logSetting.UserJoined)
// return Task.CompletedTask;
// var task = Task.Run(async () =>
// {
// });
// return Task.CompletedTask;
// }
// private Task _client_UserUnbanned(IUser usr, IGuild guild)
// {
// LogSetting logSetting;
// if (!GuildLogSettings.TryGetValue(guild.Id, out logSetting)
// || !logSetting.IsLogging
// || !logSetting.UserUnbanned)
// return Task.CompletedTask;
// var task = Task.Run(async () =>
// {
// });
// return Task.CompletedTask;
// }
// private Task _client_UserBanned(IUser usr, IGuild guild)
// {
// LogSetting logSetting;
// if (!GuildLogSettings.TryGetValue(guild.Id, out logSetting)
// || !logSetting.IsLogging
// || !logSetting.UserBanned)
// return Task.CompletedTask;
// var task = Task.Run(async () =>
// {
// });
// return Task.CompletedTask;
// }
// private Task _client_MessageDeleted(ulong arg1, Optional<IMessage> imsg)
// {
// var msg = (imsg.IsSpecified ? imsg.Value : null) as IUserMessage;
// if (msg == null)
// return Task.CompletedTask;
// var channel = msg.Channel as ITextChannel;
// if (channel == null)
// return Task.CompletedTask;
// LogSetting logSetting;
// if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting)
// || !logSetting.IsLogging
// || !logSetting.MessageDeleted)
// return Task.CompletedTask;
// var task = Task.Run(async () =>
// {
// });
// return Task.CompletedTask;
// }
// private Task _client_MessageUpdated(Optional<IMessage> optmsg, IMessage imsg2)
// {
// var after = imsg2 as IUserMessage;
// if (after == null)
// return Task.CompletedTask;
// var channel = after.Channel as ITextChannel;
// if (channel == null)
// return Task.CompletedTask;
// LogSetting logSetting;
// if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting)
// || !logSetting.IsLogging
// || !logSetting.MessageUpdated)
// return Task.CompletedTask;
// var task = Task.Run(async () =>
// {
// });
// return Task.CompletedTask;
// }
// private Task _client_MessageReceived(IMessage imsg)
// {
// var msg = imsg as IUserMessage;
// if (msg == null)
// return Task.CompletedTask;
// var channel = msg.Channel as ITextChannel;
// if (channel == null)
// return Task.CompletedTask;
// LogSetting logSetting;
// if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting)
// || !logSetting.IsLogging
// || !logSetting.MessageReceived)
// return Task.CompletedTask;
// var task = Task.Run(() =>
// {
// });
// return Task.CompletedTask;
// }
// private enum LogChannelType { Text, Voice, UserPresence };
// private ITextChannel TryGetLogChannel(IGuild guild, LogSetting logSetting, LogChannelType logChannelType = LogChannelType.Text)
// {
// ulong id = 0;
// switch (logChannelType)
// {
// case LogChannelType.Text:
// id = logSetting.ChannelId;
// break;
// case LogChannelType.Voice:
// id = logSetting.VoicePresenceChannelId;
// break;
// case LogChannelType.UserPresence:
// id = logSetting.UserPresenceChannelId;
// break;
// }
// var channel = guild.GetTextChannel(id);
// if (channel == null)
// using (var uow = DbHandler.UnitOfWork())
// {
// switch (logChannelType)
// {
// case LogChannelType.Text:
// logSetting.IsLogging = false;
// break;
// case LogChannelType.Voice:
// logSetting.LogVoicePresence = false;
// break;
// case LogChannelType.UserPresence:
// logSetting.LogUserPresence = false;
// break;
// }
// uow.Complete();
// return null;
// }
// else
// return channel;
// }
// [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
// [RequireContext(ContextType.Guild)]
// public async Task LogServer(IUserMessage msg)
// {
// var channel = (ITextChannel)msg.Channel;
// GuildConfig config;
// using (var uow = DbHandler.UnitOfWork())
// {
// config = uow.GuildConfigs.For(channel.Guild.Id);
// LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
// logSetting.IsLogging = !logSetting.IsLogging;
// config.LogSetting = logSetting;
// await uow.CompleteAsync();
// }
// if (config.LogSetting.IsLogging)
// await channel.SendMessageAsync("`Logging enabled.`").ConfigureAwait(false);
// else
// await channel.SendMessageAsync("`Logging disabled.`").ConfigureAwait(false);
// }
// [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
// [RequireContext(ContextType.Guild)]
// public async Task LogIgnore(IUserMessage imsg)
// {
// 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.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == channel.Id);
// if (removed == 0)
// logSetting.IgnoredChannels.Add(new IgnoredLogChannel { ChannelId = channel.Id });
// config.LogSetting = logSetting;
// await uow.CompleteAsync().ConfigureAwait(false);
// }
// if (removed == 0)
// await channel.SendMessageAsync($"`Logging will now ignore {channel.Name} ({channel.Id}) channel.`").ConfigureAwait(false);
// else
// await channel.SendMessageAsync($"`Logging will no longer ignore {channel.Name} ({channel.Id}) channel.`").ConfigureAwait(false);
// }
// [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
// [RequireContext(ContextType.Guild)]
// public async Task LogAdd(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, true);
// config.LogSetting = logSetting;
// 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;
// }
// }
// [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
// [RequireContext(ContextType.Guild)]
// public async Task UserPresence(IUserMessage imsg)
// {
// var channel = (ITextChannel)imsg.Channel;
// bool enabled;
// using (var uow = DbHandler.UnitOfWork())
// {
// var config = uow.GuildConfigs.For(channel.Guild.Id);
// LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
// enabled = logSetting.LogUserPresence = !config.LogSetting.LogUserPresence;
// config.LogSetting = logSetting;
// await uow.CompleteAsync().ConfigureAwait(false);
// }
// if (enabled)
// await channel.SendMessageAsync($"`Logging user presence updates in {channel.Name} ({channel.Id}) channel.`").ConfigureAwait(false);
// else
// await channel.SendMessageAsync($"`Stopped logging user presence updates.`").ConfigureAwait(false);
// }
// [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
// [RequireContext(ContextType.Guild)]
// public async Task VoicePresence(IUserMessage imsg)
// {
// var channel = (ITextChannel)imsg.Channel;
// bool enabled;
// using (var uow = DbHandler.UnitOfWork())
// {
// var config = uow.GuildConfigs.For(channel.Guild.Id);
// LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
// enabled = config.LogSetting.LogVoicePresence = !config.LogSetting.LogVoicePresence;
// config.LogSetting = logSetting;
// await uow.CompleteAsync().ConfigureAwait(false);
// }
// if (enabled)
// await channel.SendMessageAsync($"`Logging voice presence updates in {channel.Name} ({channel.Id}) channel.`").ConfigureAwait(false);
// else
// await channel.SendMessageAsync($"`Stopped logging voice presence updates.`").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);
// }
// }
// }
//}

View File

@ -1,485 +1,466 @@
//using Discord; using Discord;
//using Discord.Commands; using Discord.Commands;
//using NadekoBot.Classes; using Discord.WebSocket;
//using NadekoBot.Extensions; using NadekoBot.Attributes;
//using NadekoBot.Modules.Permissions.Classes; using NadekoBot.Extensions;
//using System; using NadekoBot.Services;
//using System.Collections.Concurrent; using NadekoBot.Services.Database;
//using System.Collections.Generic; using NadekoBot.Services.Database.Models;
//using System.Linq; using NLog;
//using System.Threading.Tasks; using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
////todo DB namespace NadekoBot.Modules.Administration
////todo Add flags for every event {
//namespace NadekoBot.Modules.Administration public partial class Administration
//{ {
// public class LogCommand : DiscordCommand [Group]
// { public class LogCommands
// private string prettyCurrentTime => $"【{DateTime.Now:HH:mm:ss}】"; {
private DiscordSocketClient _client { get; }
private Logger _log { get; }
// private ConcurrentBag<KeyValuePair<Channel, string>> voicePresenceUpdates = new ConcurrentBag<KeyValuePair<Channel, string>>(); private string prettyCurrentTime => $"【{DateTime.Now:HH:mm:ss}】";
// public LogCommand(DiscordModule module) : base(module) public ConcurrentDictionary<ulong, LogSetting> GuildLogSettings { get; }
// {
// NadekoBot.Client.MessageReceived += MsgRecivd;
// NadekoBot.Client.MessageDeleted += MsgDltd;
// NadekoBot.Client.MessageUpdated += MsgUpdtd;
// NadekoBot.Client.UserUpdated += UsrUpdtd;
// NadekoBot.Client.UserBanned += UsrBanned;
// NadekoBot.Client.UserLeft += UsrLeft;
// NadekoBot.Client.UserJoined += UsrJoined;
// NadekoBot.Client.UserUnbanned += UsrUnbanned;
// NadekoBot.Client.ChannelCreated += ChannelCreated;
// NadekoBot.Client.ChannelDestroyed += ChannelDestroyed;
// NadekoBot.Client.ChannelUpdated += ChannelUpdated;
public LogCommands(DiscordSocketClient client)
{
_client = client;
_log = LogManager.GetCurrentClassLogger();
// NadekoBot.Client.MessageReceived += async (s, e) => using (var uow = DbHandler.UnitOfWork())
{
GuildLogSettings = new ConcurrentDictionary<ulong, LogSetting>(uow.GuildConfigs
.GetAll()
.ToDictionary(g => g.GuildId, g => g.LogSetting));
}
_client.MessageReceived += _client_MessageReceived;
_client.MessageUpdated += _client_MessageUpdated;
_client.MessageDeleted += _client_MessageDeleted;
_client.UserBanned += _client_UserBanned;
_client.UserUnbanned += _client_UserUnbanned;
_client.UserJoined += _client_UserJoined;
_client.UserLeft += _client_UserLeft;
_client.UserPresenceUpdated += _client_UserPresenceUpdated;
_client.UserVoiceStateUpdated += _client_UserVoiceStateUpdated;
}
private Task _client_UserVoiceStateUpdated(IUser iusr, IVoiceState before, IVoiceState after)
{
var usr = iusr as IGuildUser;
if (usr == null)
return Task.CompletedTask;
var beforeVch = before.VoiceChannel;
var afterVch = after.VoiceChannel;
if (beforeVch == afterVch)
return Task.CompletedTask;
LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|| !logSetting.LogVoicePresence
|| !logSetting.IgnoredChannels.Any(ic => ic.ChannelId == after.VoiceChannel.Id))
return Task.CompletedTask;
ITextChannel logChannel;
if ((logChannel = usr.Guild.GetTextChannel(logSetting.ChannelId)) == null)
return Task.CompletedTask;
var task = Task.Run(async () =>
{
if (beforeVch?.Guild == afterVch?.Guild)
{
await logChannel.SendMessageAsync($"🎼`{prettyCurrentTime}` {usr.Username} moved from **{beforeVch.Name}** to **{afterVch.Name}** voice channel.").ConfigureAwait(false);
}
else if (beforeVch == null)
{
await logChannel.SendMessageAsync($"🎼`{prettyCurrentTime}` {usr.Username} has joined **{afterVch.Name}** voice channel.").ConfigureAwait(false);
}
else if (afterVch == null)
{
await logChannel.SendMessageAsync($"🎼`{prettyCurrentTime}` {usr.Username} has left **{beforeVch.Name}** voice channel.").ConfigureAwait(false);
}
});
return Task.CompletedTask;
}
private Task _client_UserPresenceUpdated(IGuildUser usr, IPresence before, IPresence after)
{
LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|| !logSetting.LogUserPresence
|| before.Status == after.Status)
return Task.CompletedTask;
ITextChannel logChannel;
if ((logChannel = usr.Guild.GetTextChannel(logSetting.ChannelId)) == null)
return Task.CompletedTask;
return Task.CompletedTask;
}
private Task _client_UserLeft(IGuildUser usr)
{
LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|| !logSetting.IsLogging
|| !logSetting.UserLeft)
return Task.CompletedTask;
var task = Task.Run(async () =>
{
});
return Task.CompletedTask;
}
private Task _client_UserJoined(IGuildUser usr)
{
LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|| !logSetting.IsLogging
|| !logSetting.UserJoined)
return Task.CompletedTask;
var task = Task.Run(async () =>
{
});
return Task.CompletedTask;
}
private Task _client_UserUnbanned(IUser usr, IGuild guild)
{
LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(guild.Id, out logSetting)
|| !logSetting.IsLogging
|| !logSetting.UserUnbanned)
return Task.CompletedTask;
var task = Task.Run(async () =>
{
});
return Task.CompletedTask;
}
private Task _client_UserBanned(IUser usr, IGuild guild)
{
LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(guild.Id, out logSetting)
|| !logSetting.IsLogging
|| !logSetting.UserBanned)
return Task.CompletedTask;
var task = Task.Run(async () =>
{
});
return Task.CompletedTask;
}
private Task _client_MessageDeleted(ulong arg1, Optional<IMessage> imsg)
{
var msg = (imsg.IsSpecified ? imsg.Value : null) as IUserMessage;
if (msg == null)
return Task.CompletedTask;
var channel = msg.Channel as ITextChannel;
if (channel == null)
return Task.CompletedTask;
LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting)
|| !logSetting.IsLogging
|| !logSetting.MessageDeleted)
return Task.CompletedTask;
var task = Task.Run(async () =>
{
});
return Task.CompletedTask;
}
private Task _client_MessageUpdated(Optional<IMessage> optmsg, IMessage imsg2)
{
var after = imsg2 as IUserMessage;
if (after == null)
return Task.CompletedTask;
var channel = after.Channel as ITextChannel;
if (channel == null)
return Task.CompletedTask;
LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting)
|| !logSetting.IsLogging
|| !logSetting.MessageUpdated)
return Task.CompletedTask;
var task = Task.Run(async () =>
{
});
return Task.CompletedTask;
}
private Task _client_MessageReceived(IMessage imsg)
{
var msg = imsg as IUserMessage;
if (msg == null)
return Task.CompletedTask;
var channel = msg.Channel as ITextChannel;
if (channel == null)
return Task.CompletedTask;
LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting)
|| !logSetting.IsLogging
|| !logSetting.MessageReceived)
return Task.CompletedTask;
var task = Task.Run(() =>
{
});
return Task.CompletedTask;
}
private enum LogChannelType { Text, Voice, UserPresence };
private ITextChannel TryGetLogChannel(IGuild guild, LogSetting logSetting, LogChannelType logChannelType = LogChannelType.Text)
{
ulong id = 0;
switch (logChannelType)
{
case LogChannelType.Text:
id = logSetting.ChannelId;
break;
case LogChannelType.Voice:
id = logSetting.VoicePresenceChannelId;
break;
case LogChannelType.UserPresence:
id = logSetting.UserPresenceChannelId;
break;
}
var channel = guild.GetTextChannel(id);
if (channel == null)
using (var uow = DbHandler.UnitOfWork())
{
switch (logChannelType)
{
case LogChannelType.Text:
logSetting.IsLogging = false;
break;
case LogChannelType.Voice:
logSetting.LogVoicePresence = false;
break;
case LogChannelType.UserPresence:
logSetting.LogUserPresence = false;
break;
}
uow.Complete();
return null;
}
else
return channel;
}
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
[RequireContext(ContextType.Guild)]
public async Task LogServer(IUserMessage msg)
{
var channel = (ITextChannel)msg.Channel;
GuildConfig config;
using (var uow = DbHandler.UnitOfWork())
{
config = uow.GuildConfigs.For(channel.Guild.Id);
LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
logSetting.IsLogging = !logSetting.IsLogging;
config.LogSetting = logSetting;
await uow.CompleteAsync();
}
if (config.LogSetting.IsLogging)
await channel.SendMessageAsync("`Logging enabled.`").ConfigureAwait(false);
else
await channel.SendMessageAsync("`Logging disabled.`").ConfigureAwait(false);
}
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
[RequireContext(ContextType.Guild)]
public async Task LogIgnore(IUserMessage imsg)
{
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.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == channel.Id);
if (removed == 0)
logSetting.IgnoredChannels.Add(new IgnoredLogChannel { ChannelId = channel.Id });
config.LogSetting = logSetting;
await uow.CompleteAsync().ConfigureAwait(false);
}
if (removed == 0)
await channel.SendMessageAsync($"`Logging will now ignore {channel.Name} ({channel.Id}) channel.`").ConfigureAwait(false);
else
await channel.SendMessageAsync($"`Logging will no longer ignore {channel.Name} ({channel.Id}) channel.`").ConfigureAwait(false);
}
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
//[RequireContext(ContextType.Guild)]
//public async Task LogAdd(IUserMessage msg, string eventName)
//{ //{
// if (e.Channel.IsPrivate || umsg.Author.Id == NadekoBot.Client.CurrentUser.Id) // var channel = (ITextChannel)msg.Channel;
// return; // eventName = eventName.ToLowerInvariant();
// if (!SpecificConfigurations.Default.Of(e.Server.Id).SendPrivateMessageOnMention) return;
// try // switch (eventName)
// { // {
// var usr = e.Message.MentionedUsers.FirstOrDefault(u => u != umsg.Author); // case "messagereceived":
// if (usr?.Status != UserStatus.Offline) // case "messageupdated":
// return; // case "messagedeleted":
// await channel.SendMessageAsync($"User `{usr.Name}` is offline. PM sent.").ConfigureAwait(false); // case "userjoined":
// await usr.SendMessageAsync( // case "userleft":
// $"User `{umsg.Author.Username}` mentioned you on " + // case "userbanned":
// $"`{e.Server.Name}` server while you were offline.\n" + // case "userunbanned":
// $"`Message:` {e.Message.Text}").ConfigureAwait(false); // 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, true);
// config.LogSetting = logSetting;
// await uow.CompleteAsync().ConfigureAwait(false);
// } // }
// catch { } // await channel.SendMessageAsync($"`Now logging {eventName} event.`").ConfigureAwait(false);
// }; // break;
// default:
// // start the userpresence queue // await channel.SendMessageAsync($"`Event \"{eventName}\" not found.`").ConfigureAwait(false);
// break;
// NadekoBot.OnReady += () => Task.Run(async () =>
// {
// while (true)
// {
// var toSend = new Dictionary<Channel, string>();
// //take everything from the queue and merge the messages which are going to the same channel
// KeyValuePair<Channel, string> item;
// while (voicePresenceUpdates.TryTake(out item))
// {
// if (toSend.ContainsKey(item.Key))
// {
// toSend[item.Key] = toSend[item.Key] + Environment.NewLine + item.Value;
// } // }
//}
//[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;
// }
//}
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
//[RequireContext(ContextType.Guild)]
//public async Task UserPresence(IUserMessage imsg)
//{
// var channel = (ITextChannel)imsg.Channel;
// bool enabled;
// using (var uow = DbHandler.UnitOfWork())
// {
// var config = uow.GuildConfigs.For(channel.Guild.Id);
// LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
// enabled = logSetting.LogUserPresence = !config.LogSetting.LogUserPresence;
// config.LogSetting = logSetting;
// await uow.CompleteAsync().ConfigureAwait(false);
// }
// if (enabled)
// await channel.SendMessageAsync($"`Logging user presence updates in {channel.Name} ({channel.Id}) channel.`").ConfigureAwait(false);
// else // else
// { // await channel.SendMessageAsync($"`Stopped logging user presence updates.`").ConfigureAwait(false);
// toSend.Add(item.Key, item.Value);
// }
// }
// //send merged messages to each channel
// foreach (var k in toSend)
// {
// try { await k.Key.SendMessageAsync(Environment.NewLine + k.Value).ConfigureAwait(false); } catch { }
//} //}
// await Task.Delay(5000); //[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
// } //[RequireContext(ContextType.Guild)]
// }); //public async Task VoicePresence(IUserMessage imsg)
//{
// var channel = (ITextChannel)imsg.Channel;
// bool enabled;
// using (var uow = DbHandler.UnitOfWork())
// {
// var config = uow.GuildConfigs.For(channel.Guild.Id);
// LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
// enabled = config.LogSetting.LogVoicePresence = !config.LogSetting.LogVoicePresence;
// config.LogSetting = logSetting;
// await uow.CompleteAsync().ConfigureAwait(false);
// } // }
// private async void ChannelUpdated(object sender, ChannelUpdatedEventArgs e) // if (enabled)
// { // await channel.SendMessageAsync($"`Logging voice presence updates in {channel.Name} ({channel.Id}) channel.`").ConfigureAwait(false);
// try
// {
// var config = SpecificConfigurations.Default.Of(e.Server.Id);
// var chId = config.LogServerChannel;
// if (chId == null || config.LogserverIgnoreChannels.Contains(e.After.Id))
// return;
// Channel ch;
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
// return;
// if (e.Before.Name != e.After.Name)
// await ch.SendMessageAsync($@"`{prettyCurrentTime}` **Channel Name Changed** `#{e.Before.Name}` (*{e.After.Id}*)
// `New:` {e.After.Name}").ConfigureAwait(false);
// else if (e.Before.Topic != e.After.Topic)
// await ch.SendMessageAsync($@"`{prettyCurrentTime}` **Channel Topic Changed** `#{e.After.Name}` (*{e.After.Id}*)
// `Old:` {e.Before.Topic}
// `New:` {e.After.Topic}").ConfigureAwait(false);
// }
// catch { }
// }
// private async void ChannelDestroyed(object sender, ChannelEventArgs e)
// {
// try
// {
// var config = SpecificConfigurations.Default.Of(e.Server.Id);
// var chId = config.LogServerChannel;
// if (chId == null || config.LogserverIgnoreChannels.Contains(e.Channel.Id))
// return;
// Channel ch;
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
// return;
// await ch.SendMessageAsync($"❗`{prettyCurrentTime}`❗`Channel Deleted:` #{e.Channel.Name} (*{e.Channel.Id}*)").ConfigureAwait(false);
// }
// catch { }
// }
// private async void ChannelCreated(object sender, ChannelEventArgs e)
// {
// try
// {
// var config = SpecificConfigurations.Default.Of(e.Server.Id);
// var chId = config.LogServerChannel;
// if (chId == null || config.LogserverIgnoreChannels.Contains(e.Channel.Id))
// return;
// Channel ch;
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
// return;
// await ch.SendMessageAsync($"`{prettyCurrentTime}`🆕`Channel Created:` #{e.Channel.Mention} (*{e.Channel.Id}*)").ConfigureAwait(false);
// }
// catch { }
// }
// private async void UsrUnbanned(object sender, UserEventArgs e)
// {
// try
// {
// var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel;
// if (chId == null)
// return;
// Channel ch;
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
// return;
// await ch.SendMessageAsync($"`{prettyCurrentTime}`♻`User was unbanned:` **{umsg.Author.Username}** ({umsg.Author.Id})").ConfigureAwait(false);
// }
// catch { }
// }
// private async void UsrJoined(object sender, UserEventArgs e)
// {
// try
// {
// var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel;
// if (chId == null)
// return;
// Channel ch;
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
// return;
// await ch.SendMessageAsync($"`{prettyCurrentTime}`✅`User joined:` **{umsg.Author.Username}** ({umsg.Author.Id})").ConfigureAwait(false);
// }
// catch { }
// }
// private async void UsrLeft(object sender, UserEventArgs e)
// {
// try
// {
// var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel;
// if (chId == null)
// return;
// Channel ch;
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
// return;
// await ch.SendMessageAsync($"`{prettyCurrentTime}`❗`User left:` **{umsg.Author.Username}** ({umsg.Author.Id})").ConfigureAwait(false);
// }
// catch { }
// }
// private async void UsrBanned(object sender, UserEventArgs e)
// {
// try
// {
// var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel;
// if (chId == null)
// return;
// Channel ch;
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
// return;
// await ch.SendMessageAsync($"❗`{prettyCurrentTime}`❌`User banned:` **{umsg.Author.Username}** ({umsg.Author.Id})").ConfigureAwait(false);
// }
// catch { }
// }
// private async void MsgRecivd(object sender, MessageEventArgs e)
// {
// try
// {
// if (e.Server == null || e.Channel.IsPrivate || umsg.Author.Id == NadekoBot.Client.CurrentUser.Id)
// return;
// var config = SpecificConfigurations.Default.Of(e.Server.Id);
// var chId = config.LogServerChannel;
// if (chId == null || e.Channel.Id == chId || config.LogserverIgnoreChannels.Contains(e.Channel.Id))
// return;
// Channel ch;
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
// return;
// if (!string.IsNullOrWhiteSpace(e.Message.Text))
// {
// await ch.SendMessageAsync(
// $@"🕔`{prettyCurrentTime}` **New Message** `#{e.Channel.Name}`
//👤`{umsg.Author?.ToString() ?? ("NULL")}` {e.Message.Text.Unmention()}").ConfigureAwait(false);
// }
// else // else
// { // await channel.SendMessageAsync($"`Stopped logging voice presence updates.`").ConfigureAwait(false);
// await ch.SendMessageAsync(
// $@"🕔`{prettyCurrentTime}` **File Uploaded** `#{e.Channel.Name}`
//👤`{umsg.Author?.ToString() ?? ("NULL")}` {e.Message.Attachments.FirstOrDefault()?.ProxyUrl}").ConfigureAwait(false);
//} //}
// } //[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
// catch { } //[RequireContext(ContextType.Guild)]
// } //public async Task VoiPresIgnore(IUserMessage imsg, IVoiceChannel voiceChannel)
// private async void MsgDltd(object sender, MessageEventArgs e)
//{ //{
// try // var channel = (ITextChannel)imsg.Channel;
// int removed;
// using (var uow = DbHandler.UnitOfWork())
// { // {
// if (e.Server == null || e.Channel.IsPrivate || umsg.Author?.Id == NadekoBot.Client.CurrentUser.Id) // var config = uow.GuildConfigs.For(channel.Guild.Id);
// return; // LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
// var config = SpecificConfigurations.Default.Of(e.Server.Id); // removed = logSetting.IgnoredVoicePresenceChannelIds.RemoveWhere(ivpc => ivpc.ChannelId == voiceChannel.Id);
// var chId = config.LogServerChannel; // if (removed == 0)
// if (chId == null || e.Channel.Id == chId || config.LogserverIgnoreChannels.Contains(e.Channel.Id)) // logSetting.IgnoredVoicePresenceChannelIds.Add(new IgnoredVoicePresenceChannel { ChannelId = voiceChannel.Id });
// return; // config.LogSetting = logSetting;
// Channel ch; // await uow.CompleteAsync().ConfigureAwait(false);
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
// return;
// if (!string.IsNullOrWhiteSpace(e.Message.Text))
// {
// await ch.SendMessageAsync(
// $@"🕔`{prettyCurrentTime}` **Message** 🚮 `#{e.Channel.Name}`
//👤`{umsg.Author?.ToString() ?? ("NULL")}` {e.Message.Text.Unmention()}").ConfigureAwait(false);
// } // }
// if (removed == 0)
// await channel.SendMessageAsync($"`Enabled logging voice presence updates for {voiceChannel.Name} ({voiceChannel.Id}) channel.`").ConfigureAwait(false);
// else // else
// { // await channel.SendMessageAsync($"`Disabled logging voice presence updates for {voiceChannel.Name} ({voiceChannel.Id}) channel.`").ConfigureAwait(false);
// await ch.SendMessageAsync(
// $@"🕔`{prettyCurrentTime}` **File Deleted** `#{e.Channel.Name}`
//👤`{umsg.Author?.ToString() ?? ("NULL")}` {e.Message.Attachments.FirstOrDefault()?.ProxyUrl}").ConfigureAwait(false);
// }
// }
// catch { }
// }
// private async void MsgUpdtd(object sender, MessageUpdatedEventArgs e)
// {
// try
// {
// if (e.Server == null || e.Channel.IsPrivate || umsg.Author?.Id == NadekoBot.Client.CurrentUser.Id)
// return;
// var config = SpecificConfigurations.Default.Of(e.Server.Id);
// var chId = config.LogServerChannel;
// if (chId == null || e.Channel.Id == chId || config.LogserverIgnoreChannels.Contains(e.Channel.Id))
// return;
// Channel ch;
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
// return;
// await ch.SendMessageAsync(
// $@"🕔`{prettyCurrentTime}` **Message** 📝 `#{e.Channel.Name}`
//👤`{umsg.Author?.ToString() ?? ("NULL")}`
// `Old:` {e.Before.Text.Unmention()}
// `New:` {e.After.Text.Unmention()}").ConfigureAwait(false);
// }
// catch { }
// }
// private async void UsrUpdtd(object sender, UserUpdatedEventArgs e)
// {
// var config = SpecificConfigurations.Default.Of(e.Server.Id);
// try
// {
// var chId = config.LogPresenceChannel;
// if (chId != null)
// {
// Channel ch;
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) != null)
// {
// if (e.Before.Status != e.After.Status)
// {
// voicePresenceUpdates.Add(new KeyValuePair<Channel, string>(ch, $"`{prettyCurrentTime}`**{e.Before.Name}** is now **{e.After.Status}**."));
// }
// }
// }
// }
// catch { }
// try
// {
// ulong notifyChBeforeId;
// ulong notifyChAfterId;
// Channel notifyChBefore = null;
// Channel notifyChAfter = null;
// var beforeVch = e.Before.VoiceChannel;
// var afterVch = e.After.VoiceChannel;
// var notifyLeave = false;
// var notifyJoin = false;
// if ((beforeVch != null || afterVch != null) && (beforeVch != afterVch)) // this means we need to notify for sure.
// {
// if (beforeVch != null && config.VoiceChannelLog.TryGetValue(beforeVch.Id, out notifyChBeforeId) && (notifyChBefore = e.Before.Server.TextChannels.FirstOrDefault(tc => tc.Id == notifyChBeforeId)) != null)
// {
// notifyLeave = true;
// }
// if (afterVch != null && config.VoiceChannelLog.TryGetValue(afterVch.Id, out notifyChAfterId) && (notifyChAfter = e.After.Server.TextChannels.FirstOrDefault(tc => tc.Id == notifyChAfterId)) != null)
// {
// notifyJoin = true;
// }
// if ((notifyLeave && notifyJoin) && (notifyChAfter == notifyChBefore))
// {
// await notifyChAfter.SendMessageAsync($"🎼`{prettyCurrentTime}` {e.Before.Name} moved from **{beforeVch.Mention}** to **{afterVch.Mention}** voice channel.").ConfigureAwait(false);
// }
// else if (notifyJoin)
// {
// await notifyChAfter.SendMessageAsync($"🎼`{prettyCurrentTime}` {e.Before.Name} has joined **{afterVch.Mention}** voice channel.").ConfigureAwait(false);
// }
// else if (notifyLeave)
// {
// await notifyChBefore.SendMessageAsync($"🎼`{prettyCurrentTime}` {e.Before.Name} has left **{beforeVch.Mention}** voice channel.").ConfigureAwait(false);
// }
// }
// }
// catch { }
// try
// {
// var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel;
// if (chId == null)
// return;
// Channel ch;
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
// return;
// string str = $"🕔`{prettyCurrentTime}`";
// if (e.Before.Name != e.After.Name)
// str += $"**Name Changed**👤`{e.Before?.ToString()}`\n\t\t`New:`{e.After.ToString()}`";
// else if (e.Before.Nickname != e.After.Nickname)
// str += $"**Nickname Changed**👤`{e.Before?.ToString()}`\n\t\t`Old:` {e.Before.Nickname}#{e.Before.Discriminator}\n\t\t`New:` {e.After.Nickname}#{e.After.Discriminator}";
// else if (e.Before.AvatarUrl != e.After.AvatarUrl)
// str += $"**Avatar Changed**👤`{e.Before?.ToString()}`\n\t {await e.Before.AvatarUrl.ShortenUrl()} `=>` {await e.After.AvatarUrl.ShortenUrl()}";
// else if (!e.Before.Roles.SequenceEqual(e.After.Roles))
// {
// if (e.Before.Roles.Count() < e.After.Roles.Count())
// {
// var diffRoles = e.After.Roles.Where(r => !e.Before.Roles.Contains(r)).Select(r => "`" + r.Name + "`");
// str += $"**User's Roles changed ⚔➕**👤`{e.Before?.ToString()}`\n\tNow has {string.Join(", ", diffRoles)} role.";
// }
// else if (e.Before.Roles.Count() > e.After.Roles.Count())
// {
// var diffRoles = e.Before.Roles.Where(r => !e.After.Roles.Contains(r)).Select(r => "`" + r.Name + "`");
// str += $"**User's Roles changed ⚔➖**👤`{e.Before?.ToString()}`\n\tNo longer has {string.Join(", ", diffRoles)} role.";
// }
// else
// {
// Console.WriteLine("SEQUENCE NOT EQUAL BUT NO DIFF ROLES - REPORT TO KWOTH on #NADEKOLOG server");
// return;
// }
// }
// else
// return;
// await ch.SendMessageAsync(str).ConfigureAwait(false);
// }
// catch { }
// }
// public override void Init(CommandGroupBuilder cgb)
// {
// cgb.CreateCommand(Module.Prefix + "spmom")
// .Description($"Toggles whether mentions of other offline users on your server will send a pm to them. **Needs Manage Server Permissions.**| `{Prefix}spmom`")
// .AddCheck(SimpleCheckers.ManageServer())
// .Do(async e =>
// {
// var specificConfig = SpecificConfigurations.Default.Of(e.Server.Id);
// specificConfig.SendPrivateMessageOnMention =
// !specificConfig.SendPrivateMessageOnMention;
// if (specificConfig.SendPrivateMessageOnMention)
// await channel.SendMessageAsync(":ok: I will send private messages " +
// "to mentioned offline users.").ConfigureAwait(false);
// else
// await channel.SendMessageAsync(":ok: I won't send private messages " +
// "to mentioned offline users anymore.").ConfigureAwait(false);
// });
// cgb.CreateCommand(Module.Prefix + "logserver")
// .Description($"Toggles logging in this channel. Logs every message sent/deleted/edited on the server. **Bot Owner Only!** | `{Prefix}logserver`")
// .AddCheck(SimpleCheckers.OwnerOnly())
// .AddCheck(SimpleCheckers.ManageServer())
// .Do(async e =>
// {
// var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel;
// if (chId == null)
// {
// SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel = e.Channel.Id;
// await channel.SendMessageAsync($"❗**I WILL BEGIN LOGGING SERVER ACTIVITY IN THIS CHANNEL**❗").ConfigureAwait(false);
// return;
// }
// Channel ch;
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
// return;
// SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel = null;
// await channel.SendMessageAsync($"❗**NO LONGER LOGGING IN {ch.Mention} CHANNEL**❗").ConfigureAwait(false);
// });
// cgb.CreateCommand(Prefix + "logignore")
// .Description($"Toggles whether the {Prefix}logserver command ignores this channel. Useful if you have hidden admin channel and public log channel. **Bot Owner Only!**| `{Prefix}logignore`")
// .AddCheck(SimpleCheckers.OwnerOnly())
// .AddCheck(SimpleCheckers.ManageServer())
// .Do(async e =>
// {
// var config = SpecificConfigurations.Default.Of(e.Server.Id);
// if (config.LogserverIgnoreChannels.Remove(e.Channel.Id))
// {
// await channel.SendMessageAsync($"`{Prefix}logserver will stop ignoring this channel.`");
// }
// else
// {
// config.LogserverIgnoreChannels.Add(e.Channel.Id);
// await channel.SendMessageAsync($"`{Prefix}logserver will ignore this channel.`");
// }
// });
// cgb.CreateCommand(Module.Prefix + "userpresence")
// .Description($"Starts logging to this channel when someone from the server goes online/offline/idle. **Needs Manage Server Permissions.**| `{Prefix}userpresence`")
// .AddCheck(SimpleCheckers.ManageServer())
// .Do(async e =>
// {
// var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogPresenceChannel;
// if (chId == null)
// {
// SpecificConfigurations.Default.Of(e.Server.Id).LogPresenceChannel = e.Channel.Id;
// await channel.SendMessageAsync($"**User presence notifications enabled.**").ConfigureAwait(false);
// return;
// }
// SpecificConfigurations.Default.Of(e.Server.Id).LogPresenceChannel = null;
// await channel.SendMessageAsync($"**User presence notifications disabled.**").ConfigureAwait(false);
// });
// cgb.CreateCommand(Module.Prefix + "voicepresence")
// .Description($"Toggles logging to this channel whenever someone joins or leaves a voice channel you are in right now. **Needs Manage Server Permissions.**| `{Prefix}voicerpresence`")
// .Parameter("all", ParameterType.Optional)
// .AddCheck(SimpleCheckers.ManageServer())
// .Do(async e =>
// {
// var config = SpecificConfigurations.Default.Of(e.Server.Id);
// if (all?.ToLower() == "all")
// {
// foreach (var voiceChannel in e.Server.VoiceChannels)
// {
// config.VoiceChannelLog.TryAdd(voiceChannel.Id, e.Channel.Id);
// }
// await channel.SendMessageAsync("Started logging user presence for **ALL** voice channels!").ConfigureAwait(false);
// return;
// }
// if (umsg.Author.VoiceChannel == null)
// {
// await channel.SendMessageAsync("💢 You are not in a voice channel right now. If you are, please rejoin it.").ConfigureAwait(false);
// return;
// }
// ulong throwaway;
// if (!config.VoiceChannelLog.TryRemove(umsg.Author.VoiceChannel.Id, out throwaway))
// {
// config.VoiceChannelLog.TryAdd(umsg.Author.VoiceChannel.Id, e.Channel.Id);
// await channel.SendMessageAsync($"`Logging user updates for` {umsg.Author.VoiceChannel.Mention} `voice channel.`").ConfigureAwait(false);
// }
// else
// await channel.SendMessageAsync($"`Stopped logging user updates for` {umsg.Author.VoiceChannel.Mention} `voice channel.`").ConfigureAwait(false);
// });
// }
// }
//} //}
}
}
}

View File

@ -17,7 +17,7 @@ namespace NadekoBot.Services
private CommandService _commandService; private CommandService _commandService;
private Logger _log; private Logger _log;
public event EventHandler<CommandExecutedEventArgs> CommandExecuted = async delegate { }; public event EventHandler<CommandExecutedEventArgs> CommandExecuted = delegate { };
public CommandHandler(DiscordSocketClient client, CommandService commandService) public CommandHandler(DiscordSocketClient client, CommandService commandService)
{ {

View File

@ -28,13 +28,14 @@ namespace NadekoBot.Services.Database.Models
public bool SendChannelByeMessage { get; set; } public bool SendChannelByeMessage { get; set; }
public string ChannelByeMessageText { get; set; } = "%user% has left!"; public string ChannelByeMessageText { get; set; } = "%user% has left!";
public LogSetting LogSetting { get; set; } = new LogSetting();
//self assignable roles //self assignable roles
public bool ExclusiveSelfAssignedRoles { get; set; } public bool ExclusiveSelfAssignedRoles { get; set; }
public bool AutoDeleteSelfAssignedRoleMessages { get; set; } public bool AutoDeleteSelfAssignedRoleMessages { get; set; }
public float DefaultMusicVolume { get; set; } = 1.0f; public float DefaultMusicVolume { get; set; } = 1.0f;
public bool VoicePlusTextEnabled { get; set; } public bool VoicePlusTextEnabled { get; set; }
//stream notifications //stream notifications
public List<FollowedStream> FollowedStreams { get; set; } = new List<FollowedStream>(); public List<FollowedStream> FollowedStreams { get; set; } = new List<FollowedStream>();
} }

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NadekoBot.Services.Database.Models
{
public class IgnoredLogChannel : DbEntity
{
public LogSetting LogSetting { get; set; }
public ulong ChannelId { get; set; }
}
}

View File

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NadekoBot.Services.Database.Models
{
public class LogSetting : DbEntity
{
public bool IsLogging { get; set; }
public ulong ChannelId { get; set; }
public HashSet<IgnoredLogChannel> IgnoredChannels { get; set; }
public bool MessageReceived { get; set; }
public bool MessageUpdated { get; set; }
public bool MessageDeleted { get; set; }
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 bool ChannelCreated { get; set; } = true;
public bool ChannelDestroyed { get; set; } = true;
public bool ChannelUpdated { get; set; } = true;
//userpresence
public bool LogUserPresence { get; set; } = false;
public ulong UserPresenceChannelId { get; set; }
//voicepresence
public bool LogVoicePresence { get; set; } = false;
public ulong VoicePresenceChannelId { get; set; }
public HashSet<IgnoredVoicePresenceChannel> IgnoredVoicePresenceChannelIds { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NadekoBot.Services.Database.Models
{
public class IgnoredVoicePresenceChannel : DbEntity
{
public LogSetting LogSetting { get; set; }
public ulong ChannelId { get; set; }
}
}

View File

@ -23,6 +23,11 @@ namespace NadekoBot.Services.Database
public DbSet<ConvertUnit> ConversionUnits { get; set; } public DbSet<ConvertUnit> ConversionUnits { get; set; }
public DbSet<TypingArticle> TypingArticles { get; set; } public DbSet<TypingArticle> TypingArticles { get; set; }
//logging
public DbSet<LogSetting> LogSettings { get; set; }
public DbSet<IgnoredLogChannel> IgnoredLogChannels { get; set; }
public DbSet<IgnoredVoicePresenceChannel> IgnoredVoicePresenceCHannels { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
#region QUOTES #region QUOTES
@ -86,6 +91,19 @@ namespace NadekoBot.Services.Database
.IsUnique(); .IsUnique();
#endregion #endregion
#region LogSettings
//var logSettingEntity = modelBuilder.Entity<LogSetting>();
//logSettingEntity
// .HasMany(ls => ls.IgnoredChannels)
// .WithOne(ls => ls.LogSetting)
// .HasPrincipalKey(ls => ls.id;
//logSettingEntity
// .HasMany(ls => ls.IgnoredVoicePresenceChannelIds)
// .WithOne(ls => ls.LogSetting);
#endregion
} }
protected abstract override void OnConfiguring(DbContextOptionsBuilder optionsBuilder); protected abstract override void OnConfiguring(DbContextOptionsBuilder optionsBuilder);
} }

View File

@ -21,6 +21,8 @@ namespace NadekoBot.Services.Database.Repositories.Impl
public GuildConfig For(ulong guildId) public GuildConfig For(ulong guildId)
{ {
var config = _set.Include(gc => gc.FollowedStreams) var config = _set.Include(gc => gc.FollowedStreams)
.Include(gc => gc.LogSetting)
.ThenInclude(ls=>ls.IgnoredChannels)
.FirstOrDefault(c => c.GuildId == guildId); .FirstOrDefault(c => c.GuildId == guildId);
if (config == null) if (config == null)