Massive cleanup

- Removed GuildConfigs repository, moved to extensions
- Moved StreamSettings extension to GuildConfig extensions
- namespace NadekoBot.Core has been simplified to NadekoBot in many places (more to come)
- Replaced some raw delete queries with simple linqtodb queries
This commit is contained in:
Kwoth
2021-06-19 03:32:48 +02:00
parent c7ff982ec1
commit 15dac7e3ed
191 changed files with 563 additions and 571 deletions

View File

@@ -3,13 +3,16 @@ using Discord.Commands;
using Discord.WebSocket;
using Microsoft.EntityFrameworkCore;
using NadekoBot.Extensions;
using NadekoBot.Core.Services;
using NadekoBot.Core.Services.Database.Models;
using NadekoBot.Services;
using NadekoBot.Services.Database.Models;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NadekoBot.Common.Attributes;
using NadekoBot.Core.Services;
using NadekoBot.Core.Services.Database.Models;
using NadekoBot.Modules.Administration;
using NadekoBot.Modules.Utility.Services;
namespace NadekoBot.Modules.Utility
@@ -60,7 +63,7 @@ namespace NadekoBot.Modules.Utility
using (var uow = _db.GetDbContext())
{
var config = uow.GuildConfigs.ForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases));
var config = uow._context.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases));
var toAdd = new CommandAlias()
{
Mapping = mapping,
@@ -79,7 +82,7 @@ namespace NadekoBot.Modules.Utility
{
using (var uow = _db.GetDbContext())
{
var config = uow.GuildConfigs.ForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases));
var config = uow._context.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases));
config.CommandAliases.Add(new CommandAlias()
{
Mapping = mapping,
@@ -94,7 +97,7 @@ namespace NadekoBot.Modules.Utility
{
using (var uow = _db.GetDbContext())
{
var config = uow.GuildConfigs.ForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases));
var config = uow._context.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases));
var toAdd = new CommandAlias()
{
Mapping = mapping,

View File

@@ -1,27 +0,0 @@
using Microsoft.EntityFrameworkCore;
using NadekoBot.Core.Services.Database.Models;
using NadekoBot.Core.Services.Database.Repositories;
namespace NadekoBot.Modules.Utility.Extensions
{
public static class StreamRoleExtensions
{
/// <summary>
/// Gets full stream role settings for the guild with the specified id.
/// </summary>
/// <param name="gc"></param>
/// <param name="guildId">Id of the guild to get stream role settings for.</param>
/// <returns></returns>
public static StreamRoleSettings GetStreamRoleSettings(this IGuildConfigRepository gc, ulong guildId)
{
var conf = gc.ForId(guildId, set => set.Include(y => y.StreamRole)
.Include(y => y.StreamRole.Whitelist)
.Include(y => y.StreamRole.Blacklist));
if (conf.StreamRole == null)
conf.StreamRole = new StreamRoleSettings();
return conf.StreamRole;
}
}
}

View File

@@ -3,7 +3,7 @@ using Discord;
using Discord.Commands;
using NadekoBot.Common.Attributes;
using NadekoBot.Core.Common;
using NadekoBot.Core.Modules.Utility.Services;
using NadekoBot.Modules.Utility.Services;
using NadekoBot.Extensions;
using System.Linq;
using System.Threading.Tasks;

View File

@@ -3,13 +3,16 @@ using Discord.Commands;
using NadekoBot.Common;
using NadekoBot.Common.Attributes;
using NadekoBot.Common.Replacements;
using NadekoBot.Core.Services;
using NadekoBot.Core.Services.Database.Models;
using NadekoBot.Services;
using NadekoBot.Services.Database.Models;
using NadekoBot.Extensions;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NadekoBot.Core.Services;
using NadekoBot.Core.Services.Database.Models;
using NadekoBot.Core.Services.Database.Repositories.Impl;
using NadekoBot.Services.Database.Repositories.Impl;
using NadekoBot.Db;
namespace NadekoBot.Modules.Utility

View File

@@ -7,6 +7,8 @@ using Discord.Commands;
using NadekoBot.Common.Attributes;
using NadekoBot.Core.Services;
using NadekoBot.Core.Services.Database.Models;
using NadekoBot.Services;
using NadekoBot.Services.Database.Models;
using NadekoBot.Extensions;
using NadekoBot.Modules.Administration.Services;
using NadekoBot.Modules.Utility.Common;

View File

@@ -49,7 +49,7 @@ namespace NadekoBot.Modules.Utility
var removed = await _service.RemoveByIndexAsync(ctx.Guild.Id, index);
if (removed is null)
{
await ReplyErrorLocalizedAsync("repeater_remove_failed").ConfigureAwait(false);
await ReplyErrorLocalizedAsync("repeater_remove_fail").ConfigureAwait(false);
return;
}

View File

@@ -5,11 +5,14 @@ using System.Threading.Tasks;
using Discord;
using NadekoBot.Common.ModuleBehaviors;
using NadekoBot.Extensions;
using NadekoBot.Core.Services;
using NadekoBot.Core.Services.Database.Models;
using NadekoBot.Services;
using NadekoBot.Services.Database.Models;
using System;
using Discord.WebSocket;
using Microsoft.EntityFrameworkCore;
using NadekoBot.Core.Services;
using NadekoBot.Core.Services.Database.Models;
using NadekoBot.Modules.Administration;
namespace NadekoBot.Modules.Utility.Services
{
@@ -50,7 +53,7 @@ namespace NadekoBot.Modules.Utility.Services
int count;
using (var uow = _db.GetDbContext())
{
var gc = uow.GuildConfigs.ForId(guildId, set => set.Include(x => x.CommandAliases));
var gc = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.CommandAliases));
count = gc.CommandAliases.Count;
gc.CommandAliases.Clear();
uow.SaveChanges();

View File

@@ -2,7 +2,7 @@
using NadekoBot.Core.Common;
using NadekoBot.Core.Services;
namespace NadekoBot.Core.Modules.Utility.Services
namespace NadekoBot.Modules.Utility.Services
{
public class InviteService : INService
{

View File

@@ -10,7 +10,7 @@ using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Discord;
using NadekoBot.Core.Modules.Gambling.Services;
using NadekoBot.Modules.Gambling.Services;
using NadekoBot.Extensions;
using Serilog;

View File

@@ -1,8 +1,8 @@
#nullable enable
using Discord.WebSocket;
using Microsoft.EntityFrameworkCore;
using NadekoBot.Core.Services;
using NadekoBot.Core.Services.Database.Models;
using NadekoBot.Services;
using NadekoBot.Services.Database.Models;
using NadekoBot.Extensions;
using System;
using System.Collections.Generic;
@@ -15,6 +15,8 @@ using NadekoBot.Common;
using NadekoBot.Common.Collections;
using NadekoBot.Common.ModuleBehaviors;
using NadekoBot.Common.Replacements;
using NadekoBot.Core.Services;
using NadekoBot.Core.Services.Database.Models;
using Serilog;
namespace NadekoBot.Modules.Utility.Services

View File

@@ -7,11 +7,11 @@ using Discord.WebSocket;
using NadekoBot.Extensions;
using NadekoBot.Core.Services;
using NadekoBot.Core.Services.Database.Models;
using NadekoBot.Modules.Utility.Extensions;
using NadekoBot.Common.TypeReaders;
using NadekoBot.Modules.Utility.Common;
using NadekoBot.Modules.Utility.Common.Exceptions;
using Discord.Net;
using NadekoBot.Modules.Administration;
using Serilog;
namespace NadekoBot.Modules.Utility.Services
@@ -81,7 +81,7 @@ namespace NadekoBot.Modules.Utility.Services
bool success = false;
using (var uow = _db.GetDbContext())
{
var streamRoleSettings = uow.GuildConfigs.GetStreamRoleSettings(guild.Id);
var streamRoleSettings = uow._context.GetStreamRoleSettings(guild.Id);
if (listType == StreamRoleListType.Whitelist)
{
@@ -146,7 +146,7 @@ namespace NadekoBot.Modules.Utility.Services
using (var uow = _db.GetDbContext())
{
var streamRoleSettings = uow.GuildConfigs.GetStreamRoleSettings(guild.Id);
var streamRoleSettings = uow._context.GetStreamRoleSettings(guild.Id);
streamRoleSettings.Keyword = keyword;
UpdateCache(guild.Id, streamRoleSettings);
@@ -170,7 +170,7 @@ namespace NadekoBot.Modules.Utility.Services
StreamRoleSettings setting;
using (var uow = _db.GetDbContext())
{
setting = uow.GuildConfigs.GetStreamRoleSettings(guildId);
setting = uow._context.GetStreamRoleSettings(guildId);
}
UpdateCache(guildId, setting);
@@ -192,7 +192,7 @@ namespace NadekoBot.Modules.Utility.Services
StreamRoleSettings setting;
using (var uow = _db.GetDbContext())
{
var streamRoleSettings = uow.GuildConfigs.GetStreamRoleSettings(fromRole.Guild.Id);
var streamRoleSettings = uow._context.GetStreamRoleSettings(fromRole.Guild.Id);
streamRoleSettings.Enabled = true;
streamRoleSettings.AddRoleId = addRole.Id;
@@ -219,7 +219,7 @@ namespace NadekoBot.Modules.Utility.Services
{
using (var uow = _db.GetDbContext())
{
var streamRoleSettings = uow.GuildConfigs.GetStreamRoleSettings(guild.Id);
var streamRoleSettings = uow._context.GetStreamRoleSettings(guild.Id);
streamRoleSettings.Enabled = false;
streamRoleSettings.AddRoleId = 0;
streamRoleSettings.FromRoleId = 0;

View File

@@ -6,6 +6,7 @@ using NadekoBot.Common.Collections;
using NadekoBot.Extensions;
using NadekoBot.Modules.Help.Services;
using NadekoBot.Core.Services;
using NadekoBot.Modules.Administration;
namespace NadekoBot.Modules.Utility.Services
{
@@ -60,7 +61,7 @@ namespace NadekoBot.Modules.Utility.Services
{
using (var uow = _db.GetDbContext())
{
var gc = uow.GuildConfigs.ForId(guildId, set => set);
var gc = uow._context.GuildConfigsForId(guildId, set => set);
if (enabled==null) enabled = gc.VerboseErrors = !gc.VerboseErrors; // Old behaviour, now behind a condition
else gc.VerboseErrors = (bool)enabled; // New behaviour, just set it.