Added migration files

This commit is contained in:
Toastie (DCS Team) 2024-06-19 02:03:46 +12:00
parent 1256528217
commit bea2b76bd2
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
10 changed files with 22259 additions and 2 deletions

View file

@ -0,0 +1,54 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Migrations;
using EllieBot.Db.Models;
namespace EllieBot.Migrations;
public static class MigrationQueries
{
public static void MigrateRero(MigrationBuilder migrationBuilder)
{
if (migrationBuilder.IsMySql())
{
migrationBuilder.Sql(
@"INSERT IGNORE into reactionroles(guildid, channelid, messageid, emote, roleid, `group`, levelreq, dateadded)
select guildid, channelid, messageid, emotename, roleid, exclusive, 0, reactionrolemessage.dateadded
from reactionrole
left join reactionrolemessage on reactionrolemessage.id = reactionrole.reactionrolemessageid
left join guildconfigs on reactionrolemessage.guildconfigid = guildconfigs.id;");
}
else if (migrationBuilder.IsSqlite())
{
migrationBuilder.Sql(
@"insert or ignore into reactionroles(guildid, channelid, messageid, emote, roleid, 'group', levelreq, dateadded)
select guildid, channelid, messageid, emotename, roleid, exclusive, 0, reactionrolemessage.dateadded
from reactionrole
left join reactionrolemessage on reactionrolemessage.id = reactionrole.reactionrolemessageid
left join guildconfigs on reactionrolemessage.guildconfigid = guildconfigs.id;");
}
else if (migrationBuilder.IsNpgsql())
{
migrationBuilder.Sql(@"insert into reactionroles(guildid, channelid, messageid, emote, roleid, ""group"", levelreq, dateadded)
select guildid, channelid, messageid, emotename, roleid, exclusive::int, 0, reactionrolemessage.dateadded
from reactionrole
left join reactionrolemessage on reactionrolemessage.id = reactionrole.reactionrolemessageid
left join guildconfigs on reactionrolemessage.guildconfigid = guildconfigs.id
ON CONFLICT DO NOTHING;");
}
else
{
throw new NotSupportedException("This database provider doesn't have an implementation for MigrateRero");
}
}
public static void GuildConfigCleanup(MigrationBuilder builder)
{
builder.Sql($"""
DELETE FROM "StreamRoleBlacklistedUser" WHERE "StreamRoleSettingsId" is NULL;
""");
builder.Sql($"""
DELETE FROM "DelMsgOnCmdChannel" WHERE "GuildConfigId" is NULL;
""");
}
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,72 @@
using EllieBot.Modules.Permissions.Common;
using EllieBot.Modules.Permissions.Services;
namespace EllieBot;
public sealed class PermissionChecker : IPermissionChecker, IEService
{
private readonly PermissionService _perms;
private readonly GlobalPermissionService _gperm;
private readonly CmdCdService _cmdCds;
private readonly IMessageSenderService _sender;
private readonly CommandHandler _ch;
public PermissionChecker(
PermissionService perms,
GlobalPermissionService gperm,
CmdCdService cmdCds,
IMessageSenderService sender,
CommandHandler ch)
{
_perms = perms;
_gperm = gperm;
_cmdCds = cmdCds;
_sender = sender;
_ch = ch;
}
public async Task<PermCheckResult> CheckPermsAsync(
IGuild guild,
IMessageChannel channel,
IUser author,
string module,
string? cmdName)
{
module = module.ToLowerInvariant();
cmdName = cmdName?.ToLowerInvariant();
if (cmdName is not null && await _cmdCds.TryBlock(guild, author, cmdName))
{
return new PermCooldown();
}
try
{
if (_gperm.BlockedModules.Contains(module))
{
return new PermGlobalBlock();
}
if (cmdName is not null && _gperm.BlockedCommands.Contains(cmdName))
{
return new PermGlobalBlock();
}
if (guild is SocketGuild sg)
{
var pc = _perms.GetCacheFor(sg.Id);
if (!pc.Permissions.CheckPermissions(author, channel, cmdName, module, out var index))
{
return new PermDisallowed(index,
pc.Permissions[index].GetCommand(_ch.GetPrefix(guild), sg),
pc.Verbose);
}
}
}
catch
{
}
return new PermAllowed();
}
}

View file

@ -1,2 +1,28 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
var pid = Environment.ProcessId;
var shardId = 0;
int? totalShards = null; // 0 to read from creds.yml
if (args.Length > 0 && args[0] != "run")
{
if (!int.TryParse(args[0], out shardId))
{
Console.Error.WriteLine("Invalid first argument (shard id): {0}", args[0]);
return;
}
if (args.Length > 1)
{
if (!int.TryParse(args[1], out var shardCount))
{
Console.Error.WriteLine("Invalid second argument (total shards): {0}", args[1]);
return;
}
totalShards = shardCount;
}
}
LogSetup.SetupLogger(shardId);
Log.Information("Pid: {ProcessId}", pid);
await new Bot(shardId, totalShards, Environment.GetEnvironmentVariable("EllieBot__creds")).RunAndBlockAsync();