Updated some namespaces, finished some todos. v5 should be cancelled probably as the code is too intertwined to make it modular

This commit is contained in:
Kwoth
2023-11-11 05:22:52 +00:00
parent a28be0d343
commit bc77783820
224 changed files with 308 additions and 317 deletions

View File

@@ -1,6 +1,7 @@
#nullable disable
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection;
using Nadeko.Bot.Db;
using NadekoBot.Common.Configs;
using NadekoBot.Common.ModuleBehaviors;
using NadekoBot.Db;
@@ -14,8 +15,8 @@ using NadekoBot.Modules.Permissions;
using NadekoBot.Modules.Searches;
using NadekoBot.Modules.Utility;
using NadekoBot.Modules.Xp;
using NadekoBot.Services.Database;
using NadekoBot.Services.Database.Models;
using Nadeko.Bot.Db.Models;
using Ninject;
using Ninject.Planning;
using System.Collections.Immutable;
@@ -34,8 +35,6 @@ public sealed class Bot : IBot
private IKernel Services { get; set; }
// todo remove
public string Mention { get; private set; }
public bool IsReady { get; private set; }
public int ShardId { get; set; }
@@ -293,8 +292,7 @@ public sealed class Bot : IBot
var sw = Stopwatch.StartNew();
await LoginAsync(_creds.Token);
Mention = Client.CurrentUser.Mention;
Log.Information("Shard {ShardId} loading services...", Client.ShardId);
try
{

View File

@@ -1,7 +1,7 @@
using Microsoft.EntityFrameworkCore;
using NadekoBot.Db.Models;
namespace NadekoBot.Services.Database;
namespace Nadeko.Bot.Db;
public sealed class MysqlContext : NadekoContext
{

View File

@@ -2,11 +2,11 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using NadekoBot.Db.Models;
using NadekoBot.Services.Database.Models;
using Nadeko.Bot.Db.Models;
// ReSharper disable UnusedAutoPropertyAccessor.Global
namespace NadekoBot.Services.Database;
namespace Nadeko.Bot.Db;
public abstract class NadekoContext : DbContext
{

View File

@@ -2,7 +2,7 @@
using LinqToDB.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace NadekoBot.Services.Database;
namespace Nadeko.Bot.Db;
public sealed class NadekoDbService : DbService
{

View File

@@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore;
namespace NadekoBot.Services.Database;
namespace Nadeko.Bot.Db;
public sealed class PostgreSqlContext : NadekoContext
{

View File

@@ -1,7 +1,7 @@
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
namespace NadekoBot.Services.Database;
namespace Nadeko.Bot.Db;
public sealed class SqliteContext : NadekoContext
{

View File

@@ -1,4 +1,6 @@
internal class ContextAdapterFactory
using Nadeko.Medusa;
internal class ContextAdapterFactory
{
public static AnyContext CreateNew(ICommandContext context, IMedusaStrings strings, IServiceProvider services)
=> context.Guild is null

View File

@@ -1,5 +1,6 @@
using Discord.Commands.Builders;
using Microsoft.Extensions.DependencyInjection;
using Nadeko.Common.Medusa;
using Nadeko.Medusa.Adapters;
using NadekoBot.Common.ModuleBehaviors;
using Ninject;

View File

@@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NadekoBot.Services.Database;
using Nadeko.Bot.Db;
#nullable disable

View File

@@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NadekoBot.Services.Database;
using Nadeko.Bot.Db;
#nullable disable

View File

@@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NadekoBot.Services.Database;
using Nadeko.Bot.Db;
#nullable disable

View File

@@ -3,7 +3,7 @@ using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NadekoBot.Services.Database;
using Nadeko.Bot.Db;
#nullable disable

View File

@@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NadekoBot.Services.Database;
using Nadeko.Bot.Db;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable

View File

@@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NadekoBot.Services.Database;
using Nadeko.Bot.Db;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable

View File

@@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NadekoBot.Services.Database;
using Nadeko.Bot.Db;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable

View File

@@ -3,7 +3,7 @@ using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NadekoBot.Services.Database;
using Nadeko.Bot.Db;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable

View File

@@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NadekoBot.Services.Database;
using Nadeko.Bot.Db;
#nullable disable

View File

@@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NadekoBot.Services.Database;
using Nadeko.Bot.Db;
#nullable disable

View File

@@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NadekoBot.Services.Database;
using Nadeko.Bot.Db;
#nullable disable

View File

@@ -3,7 +3,7 @@ using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NadekoBot.Services.Database;
using Nadeko.Bot.Db;
#nullable disable

View File

@@ -3,7 +3,6 @@ using NadekoBot.Modules.Gambling.Services;
namespace NadekoBot.Modules.Gambling;
// todo do we need both currencyprovider and currencyservice
public sealed class CurrencyProvider : ICurrencyProvider, INService
{
private readonly GamblingConfigService _cs;

View File

@@ -1,4 +1,4 @@
using Nadeko.Medusa;
using Nadeko.Common.Medusa;
namespace NadekoBot.Modules;

View File

@@ -130,6 +130,9 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="data\medusae\" />
</ItemGroup>
<PropertyGroup Condition=" '$(Version)' == '' ">
<VersionPrefix Condition=" '$(VersionPrefix)' == '' ">5.0.0</VersionPrefix>

View File

@@ -11,12 +11,20 @@ public sealed class PermissionChecker : IPermissionChecker, INService
private readonly PermissionService _perms;
private readonly GlobalPermissionService _gperm;
private readonly CmdCdService _cmdCds;
private readonly IEmbedBuilderService _ebs;
private readonly CommandHandler _ch;
public PermissionChecker(PermissionService perms, GlobalPermissionService gperm, CmdCdService cmdCds)
// todo .GetPrefix should be in a different place
public PermissionChecker(PermissionService perms,
GlobalPermissionService gperm, CmdCdService cmdCds,
IEmbedBuilderService ebs,
CommandHandler ch)
{
_perms = perms;
_gperm = gperm;
_cmdCds = cmdCds;
_ebs = ebs;
_ch = ch;
}
public async Task<OneOf<Success, Error<LocStr>>> CheckAsync(
@@ -44,26 +52,29 @@ public sealed class PermissionChecker : IPermissionChecker, INService
return new Success();
}
// todo check if this even works
if (guild is SocketGuild sg)
{
var pc = _perms.GetCacheFor(guild.Id);
if (!pc.Permissions.CheckPermissions(author, channel, cmd, "ACTUALEXPRESSIONS", out var index))
if (!pc.Permissions.CheckPermissions(author, channel, cmd, module, out var index))
{
if (pc.Verbose)
{
// todo fix
// var permissionMessage = strs.perm_prevent(index + 1,
// Format.Bold(pc.Permissions[index].GetCommand(_cmd.GetPrefix(guild), sg)));
//
// try
// {
// await msg.Channel.SendErrorAsync(_eb, permissionMessage);
// }
// catch
// {
// }
//
// Log.Information("{PermissionMessage}", permissionMessage);
var permissionMessage = strs.perm_prevent(index + 1,
Format.Bold(pc.Permissions[index].GetCommand(_ch.GetPrefix(guild), sg)));
try
{
// await channel.SendErrorAsync(_ebs,
// title: null,
// text: GettextpermissionMessage);
}
catch
{
}
Log.Information("{PermissionMessage}", permissionMessage);
}
// todo add proper string