Added migration files
This commit is contained in:
parent
1256528217
commit
bea2b76bd2
10 changed files with 22259 additions and 2 deletions
54
src/EllieBot/Migrations/MigrationQueries.cs
Normal file
54
src/EllieBot/Migrations/MigrationQueries.cs
Normal 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;
|
||||||
|
""");
|
||||||
|
}
|
||||||
|
}
|
3425
src/EllieBot/Migrations/Mysql/20220409170652_mysql-init.Designer.cs
generated
Normal file
3425
src/EllieBot/Migrations/Mysql/20220409170652_mysql-init.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load diff
2342
src/EllieBot/Migrations/Mysql/20220409170652_mysql-init.cs
Normal file
2342
src/EllieBot/Migrations/Mysql/20220409170652_mysql-init.cs
Normal file
File diff suppressed because it is too large
Load diff
3816
src/EllieBot/Migrations/Mysql/MysqlContextModelSnapshot.cs
Normal file
3816
src/EllieBot/Migrations/Mysql/MysqlContextModelSnapshot.cs
Normal file
File diff suppressed because it is too large
Load diff
3565
src/EllieBot/Migrations/PostgreSql/20220409170719_mysql-init.Designer.cs
generated
Normal file
3565
src/EllieBot/Migrations/PostgreSql/20220409170719_mysql-init.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load diff
2200
src/EllieBot/Migrations/PostgreSql/20220409170719_mysql-init.cs
Normal file
2200
src/EllieBot/Migrations/PostgreSql/20220409170719_mysql-init.cs
Normal file
File diff suppressed because it is too large
Load diff
3812
src/EllieBot/Migrations/PostgreSql/PostgreSqlContextModelSnapshot.cs
Normal file
3812
src/EllieBot/Migrations/PostgreSql/PostgreSqlContextModelSnapshot.cs
Normal file
File diff suppressed because it is too large
Load diff
2945
src/EllieBot/Migrations/Sqlite/EllieSqliteContextModelSnapshot.cs
Normal file
2945
src/EllieBot/Migrations/Sqlite/EllieSqliteContextModelSnapshot.cs
Normal file
File diff suppressed because it is too large
Load diff
72
src/EllieBot/PermissionChecker.cs
Normal file
72
src/EllieBot/PermissionChecker.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,2 +1,28 @@
|
||||||
// See https://aka.ms/new-console-template for more information
|
var pid = Environment.ProcessId;
|
||||||
Console.WriteLine("Hello, World!");
|
|
||||||
|
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();
|
Loading…
Reference in a new issue