mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
Fixed .log commands
This commit is contained in:
@@ -113,33 +113,15 @@ namespace NadekoBot.Db
|
|||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GuildConfig LogSettingsFor(this NadekoContext ctx, ulong guildId)
|
public static LogSetting LogSettingsFor(this NadekoContext ctx, ulong guildId)
|
||||||
{
|
{
|
||||||
var config = ctx
|
var logSetting = ctx.LogSettings
|
||||||
.GuildConfigs
|
|
||||||
.AsQueryable()
|
.AsQueryable()
|
||||||
.Include(gc => gc.LogSetting)
|
.Include(x => x.IgnoredChannels)
|
||||||
.ThenInclude(gc => gc.IgnoredChannels)
|
.Where(x => x.GuildId == guildId)
|
||||||
.FirstOrDefault(x => x.GuildId == guildId);
|
.FirstOrDefault();
|
||||||
|
|
||||||
if (config is null)
|
return logSetting;
|
||||||
{
|
|
||||||
ctx.GuildConfigs.Add((config = new GuildConfig
|
|
||||||
{
|
|
||||||
GuildId = guildId,
|
|
||||||
Permissions = Permissionv2.GetDefaultPermlist,
|
|
||||||
WarningsInitialized = true,
|
|
||||||
WarnPunishments = DefaultWarnPunishments,
|
|
||||||
}));
|
|
||||||
ctx.SaveChanges();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!config.WarningsInitialized)
|
|
||||||
{
|
|
||||||
config.WarningsInitialized = true;
|
|
||||||
config.WarnPunishments = DefaultWarnPunishments;
|
|
||||||
}
|
|
||||||
return config;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<GuildConfig> Permissionsv2ForAll(this DbSet<GuildConfig> configs, List<ulong> include)
|
public static IEnumerable<GuildConfig> Permissionsv2ForAll(this DbSet<GuildConfig> configs, List<ulong> include)
|
||||||
|
@@ -41,8 +41,6 @@ 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; }
|
||||||
|
@@ -8,6 +8,7 @@ namespace NadekoBot.Services.Database.Models
|
|||||||
public HashSet<IgnoredLogChannel> IgnoredChannels { get; set; } = new HashSet<IgnoredLogChannel>();
|
public HashSet<IgnoredLogChannel> IgnoredChannels { get; set; } = new HashSet<IgnoredLogChannel>();
|
||||||
public HashSet<IgnoredVoicePresenceChannel> IgnoredVoicePresenceChannelIds { get; set; } = new HashSet<IgnoredVoicePresenceChannel>();
|
public HashSet<IgnoredVoicePresenceChannel> IgnoredVoicePresenceChannelIds { get; set; } = new HashSet<IgnoredVoicePresenceChannel>();
|
||||||
|
|
||||||
|
public ulong GuildId { get; set; }
|
||||||
public ulong? LogOtherId { get; set; }
|
public ulong? LogOtherId { get; set; }
|
||||||
public ulong? MessageUpdatedId { get; set; }
|
public ulong? MessageUpdatedId { get; set; }
|
||||||
public ulong? MessageDeletedId { get; set; }
|
public ulong? MessageDeletedId { get; set; }
|
||||||
|
@@ -337,6 +337,14 @@ namespace NadekoBot.Services.Database
|
|||||||
.OnDelete(DeleteBehavior.Cascade));
|
.OnDelete(DeleteBehavior.Cascade));
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region LogSettings
|
||||||
|
|
||||||
|
modelBuilder.Entity<LogSetting>(ls => ls
|
||||||
|
.HasIndex(x => x.GuildId)
|
||||||
|
.IsUnique());
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2630
src/NadekoBot/Migrations/20210912200106_logsettings-independence.Designer.cs
generated
Normal file
2630
src/NadekoBot/Migrations/20210912200106_logsettings-independence.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,69 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
namespace NadekoBot.Migrations
|
||||||
|
{
|
||||||
|
public partial class logsettingsindependence : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<ulong>(
|
||||||
|
name: "GuildId",
|
||||||
|
table: "LogSettings",
|
||||||
|
type: "INTEGER",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0ul);
|
||||||
|
|
||||||
|
migrationBuilder.Sql(
|
||||||
|
@"UPDATE LogSettings SET GuildId = (SELECT GuildId FROM GuildConfigs WHERE LogSettingId = LogSettings.Id);
|
||||||
|
DELETE FROM LogSettings WHERE GuildId = 0;");
|
||||||
|
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "FK_GuildConfigs_LogSettings_LogSettingId",
|
||||||
|
table: "GuildConfigs");
|
||||||
|
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_GuildConfigs_LogSettingId",
|
||||||
|
table: "GuildConfigs");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "LogSettingId",
|
||||||
|
table: "GuildConfigs");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_LogSettings_GuildId",
|
||||||
|
table: "LogSettings",
|
||||||
|
column: "GuildId",
|
||||||
|
unique: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_LogSettings_GuildId",
|
||||||
|
table: "LogSettings");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "GuildId",
|
||||||
|
table: "LogSettings");
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "LogSettingId",
|
||||||
|
table: "GuildConfigs",
|
||||||
|
type: "INTEGER",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_GuildConfigs_LogSettingId",
|
||||||
|
table: "GuildConfigs",
|
||||||
|
column: "LogSettingId");
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "FK_GuildConfigs_LogSettings_LogSettingId",
|
||||||
|
table: "GuildConfigs",
|
||||||
|
column: "LogSettingId",
|
||||||
|
principalTable: "LogSettings",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Restrict);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -795,9 +795,6 @@ namespace NadekoBot.Migrations
|
|||||||
b.Property<string>("Locale")
|
b.Property<string>("Locale")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<int?>("LogSettingId")
|
|
||||||
.HasColumnType("INTEGER");
|
|
||||||
|
|
||||||
b.Property<string>("MuteRoleName")
|
b.Property<string>("MuteRoleName")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
@@ -845,8 +842,6 @@ namespace NadekoBot.Migrations
|
|||||||
b.HasIndex("GuildId")
|
b.HasIndex("GuildId")
|
||||||
.IsUnique();
|
.IsUnique();
|
||||||
|
|
||||||
b.HasIndex("LogSettingId");
|
|
||||||
|
|
||||||
b.HasIndex("WarnExpireHours");
|
b.HasIndex("WarnExpireHours");
|
||||||
|
|
||||||
b.ToTable("GuildConfigs");
|
b.ToTable("GuildConfigs");
|
||||||
@@ -914,6 +909,9 @@ namespace NadekoBot.Migrations
|
|||||||
b.Property<DateTime?>("DateAdded")
|
b.Property<DateTime?>("DateAdded")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<ulong>("GuildId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<ulong?>("LogOtherId")
|
b.Property<ulong?>("LogOtherId")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
@@ -952,6 +950,9 @@ namespace NadekoBot.Migrations
|
|||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("GuildId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
b.ToTable("LogSettings");
|
b.ToTable("LogSettings");
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -2245,15 +2246,6 @@ namespace NadekoBot.Migrations
|
|||||||
b.Navigation("GuildConfig");
|
b.Navigation("GuildConfig");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.GuildConfig", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting")
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("LogSettingId");
|
|
||||||
|
|
||||||
b.Navigation("LogSetting");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredLogChannel", b =>
|
modelBuilder.Entity("NadekoBot.Services.Database.Models.IgnoredLogChannel", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting")
|
b.HasOne("NadekoBot.Services.Database.Models.LogSetting", "LogSetting")
|
||||||
|
@@ -93,15 +93,15 @@ namespace NadekoBot.Modules.Administration.Services
|
|||||||
{
|
{
|
||||||
var guildIds = client.Guilds.Select(x => x.Id).ToList();
|
var guildIds = client.Guilds.Select(x => x.Id).ToList();
|
||||||
var configs = uow
|
var configs = uow
|
||||||
.Set<GuildConfig>()
|
.LogSettings
|
||||||
.AsQueryable()
|
.AsQueryable()
|
||||||
.Include(gc => gc.LogSetting)
|
.AsNoTracking()
|
||||||
.ThenInclude(ls => ls.IgnoredChannels)
|
|
||||||
.Where(x => guildIds.Contains(x.GuildId))
|
.Where(x => guildIds.Contains(x.GuildId))
|
||||||
|
.Include(ls => ls.IgnoredChannels)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
GuildLogSettings = configs
|
GuildLogSettings = configs
|
||||||
.ToDictionary(g => g.GuildId, g => g.LogSetting)
|
.ToDictionary(ls => ls.GuildId)
|
||||||
.ToConcurrent();
|
.ToConcurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,17 +170,15 @@ namespace NadekoBot.Modules.Administration.Services
|
|||||||
int removed = 0;
|
int removed = 0;
|
||||||
using (var uow = _db.GetDbContext())
|
using (var uow = _db.GetDbContext())
|
||||||
{
|
{
|
||||||
var config = uow.LogSettingsFor(gid);
|
var logSetting = uow.LogSettingsFor(gid);
|
||||||
LogSetting logSetting = GuildLogSettings.GetOrAdd(gid, (id) => config.LogSetting);
|
|
||||||
removed = logSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == cid);
|
removed = logSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == cid);
|
||||||
config.LogSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == cid);
|
|
||||||
if (removed == 0)
|
if (removed == 0)
|
||||||
{
|
{
|
||||||
var toAdd = new IgnoredLogChannel {ChannelId = cid};
|
var toAdd = new IgnoredLogChannel {ChannelId = cid};
|
||||||
logSetting.IgnoredChannels.Add(toAdd);
|
logSetting.IgnoredChannels.Add(toAdd);
|
||||||
config.LogSetting.IgnoredChannels.Add(toAdd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GuildLogSettings.AddOrUpdate(gid, logSetting, (_, _) => logSetting);
|
||||||
uow.SaveChanges();
|
uow.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,11 +207,10 @@ namespace NadekoBot.Modules.Administration.Services
|
|||||||
|
|
||||||
public async Task LogServer(ulong guildId, ulong channelId, bool value)
|
public async Task LogServer(ulong guildId, ulong channelId, bool value)
|
||||||
{
|
{
|
||||||
LogSetting logSetting;
|
|
||||||
using (var uow = _db.GetDbContext())
|
using (var uow = _db.GetDbContext())
|
||||||
{
|
{
|
||||||
logSetting = uow.LogSettingsFor(guildId).LogSetting;
|
var logSetting = uow.LogSettingsFor(guildId);
|
||||||
GuildLogSettings.AddOrUpdate(guildId, (id) => logSetting, (id, old) => logSetting);
|
|
||||||
logSetting.LogOtherId =
|
logSetting.LogOtherId =
|
||||||
logSetting.MessageUpdatedId =
|
logSetting.MessageUpdatedId =
|
||||||
logSetting.MessageDeletedId =
|
logSetting.MessageDeletedId =
|
||||||
@@ -230,8 +227,9 @@ namespace NadekoBot.Modules.Administration.Services
|
|||||||
logSetting.UserMutedId =
|
logSetting.UserMutedId =
|
||||||
logSetting.LogVoicePresenceTTSId =
|
logSetting.LogVoicePresenceTTSId =
|
||||||
(value ? channelId : (ulong?) null);
|
(value ? channelId : (ulong?) null);
|
||||||
|
;
|
||||||
await uow.SaveChangesAsync();
|
await uow.SaveChangesAsync();
|
||||||
|
GuildLogSettings.AddOrUpdate(guildId, (id) => logSetting, (id, old) => logSetting);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,7 +299,7 @@ namespace NadekoBot.Modules.Administration.Services
|
|||||||
ulong? channelId = null;
|
ulong? channelId = null;
|
||||||
using (var uow = _db.GetDbContext())
|
using (var uow = _db.GetDbContext())
|
||||||
{
|
{
|
||||||
var logSetting = uow.LogSettingsFor(gid).LogSetting;
|
var logSetting = uow.LogSettingsFor(gid);
|
||||||
GuildLogSettings.AddOrUpdate(gid, (id) => logSetting, (id, old) => logSetting);
|
GuildLogSettings.AddOrUpdate(gid, (id) => logSetting, (id, old) => logSetting);
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
@@ -1238,7 +1236,7 @@ namespace NadekoBot.Modules.Administration.Services
|
|||||||
{
|
{
|
||||||
using (var uow = _db.GetDbContext())
|
using (var uow = _db.GetDbContext())
|
||||||
{
|
{
|
||||||
var newLogSetting = uow.LogSettingsFor(guildId).LogSetting;
|
var newLogSetting = uow.LogSettingsFor(guildId);
|
||||||
switch (logChannelType)
|
switch (logChannelType)
|
||||||
{
|
{
|
||||||
case LogType.Other:
|
case LogType.Other:
|
||||||
|
@@ -57,8 +57,8 @@ namespace NadekoBot.Services
|
|||||||
// if user is a new booster
|
// if user is a new booster
|
||||||
// or boosted again the same server
|
// or boosted again the same server
|
||||||
if ((oldUser is { PremiumSince: null } && newUser is { PremiumSince: not null })
|
if ((oldUser is { PremiumSince: null } && newUser is { PremiumSince: not null })
|
||||||
|| (oldUser.PremiumSince is DateTimeOffset oldDate
|
|| (oldUser?.PremiumSince is DateTimeOffset oldDate
|
||||||
&& newUser.PremiumSince is DateTimeOffset newDate
|
&& newUser?.PremiumSince is DateTimeOffset newDate
|
||||||
&& newDate > oldDate))
|
&& newDate > oldDate))
|
||||||
{
|
{
|
||||||
var conf = GetOrAddSettingsForGuild(newUser.Guild.Id);
|
var conf = GetOrAddSettingsForGuild(newUser.Guild.Id);
|
||||||
|
Reference in New Issue
Block a user