Remove all redis leftovers
This commit is contained in:
parent
46fee88f03
commit
520633c590
8 changed files with 2 additions and 156 deletions
|
@ -1,16 +1,12 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using Geekbot.net.Lib.AlmostRedis;
|
||||
using Geekbot.net.Lib.ErrorHandling;
|
||||
using Geekbot.net.Lib.GlobalSettings;
|
||||
using Geekbot.net.Lib.Logger;
|
||||
using Geekbot.net.Lib.ReactionListener;
|
||||
using Geekbot.net.Lib.UserRepository;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace Geekbot.net.Commands.Admin.Owner
|
||||
{
|
||||
|
@ -21,22 +17,16 @@ namespace Geekbot.net.Commands.Admin.Owner
|
|||
private readonly DiscordSocketClient _client;
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IDatabase _redis;
|
||||
private readonly IReactionListener _reactionListener;
|
||||
private readonly IGeekbotLogger _logger;
|
||||
private readonly IUserRepository _userRepository;
|
||||
|
||||
public Owner(DiscordSocketClient client, IGeekbotLogger logger, IUserRepository userRepositry, IErrorHandler errorHandler, IGlobalSettings globalSettings,
|
||||
IAlmostRedis redis, IReactionListener reactionListener
|
||||
)
|
||||
public Owner(DiscordSocketClient client, IGeekbotLogger logger, IUserRepository userRepositry, IErrorHandler errorHandler, IGlobalSettings globalSettings)
|
||||
{
|
||||
_client = client;
|
||||
_logger = logger;
|
||||
_userRepository = userRepositry;
|
||||
_errorHandler = errorHandler;
|
||||
_globalSettings = globalSettings;
|
||||
_redis = redis.Db;
|
||||
_reactionListener = reactionListener;
|
||||
}
|
||||
|
||||
[Command("youtubekey", RunMode = RunMode.Async)]
|
||||
|
@ -132,72 +122,5 @@ namespace Geekbot.net.Commands.Admin.Owner
|
|||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
[Command("migrate_listeners", RunMode = RunMode.Async)]
|
||||
public async Task MigrateListeners()
|
||||
{
|
||||
try
|
||||
{
|
||||
var messageIds = _redis.SetMembers("MessageIds");
|
||||
var connectedGuilds = _client.Guilds;
|
||||
var messageGuildAssociation = new Dictionary<ulong, ulong>();
|
||||
foreach (var messageIdUnparsed in messageIds)
|
||||
{
|
||||
var messageId = ulong.Parse(messageIdUnparsed);
|
||||
var reactions = _redis.HashGetAll($"Messages:{messageIdUnparsed.ToString()}");
|
||||
|
||||
foreach (var reaction in reactions)
|
||||
{
|
||||
_logger.Information(LogSource.Migration, $"{messageIdUnparsed.ToString()} - Starting");
|
||||
try
|
||||
{
|
||||
ulong guildId = 0;
|
||||
IRole role = null;
|
||||
|
||||
var roleId = ulong.Parse(reaction.Value);
|
||||
if (messageGuildAssociation.ContainsKey(messageId))
|
||||
{
|
||||
guildId = messageGuildAssociation[messageId];
|
||||
_logger.Information(LogSource.Migration, $"{messageIdUnparsed.ToString()} - known to be in {guildId}");
|
||||
role = _client.GetGuild(guildId).GetRole(roleId);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Information(LogSource.Migration, $"{messageIdUnparsed.ToString()} - Attempting to find guild");
|
||||
IRole foundRole = null;
|
||||
try
|
||||
{
|
||||
foreach (var guild in connectedGuilds)
|
||||
{
|
||||
foundRole = guild.GetRole(roleId);
|
||||
if (foundRole != null)
|
||||
{
|
||||
role = _client.GetGuild(foundRole.Guild.Id).GetRole(ulong.Parse(reaction.Value));
|
||||
messageGuildAssociation.Add(messageId, foundRole.Guild.Id);
|
||||
}
|
||||
}
|
||||
} catch { /* ignore */ }
|
||||
|
||||
if (foundRole == null)
|
||||
{
|
||||
_logger.Warning(LogSource.Migration, $"{messageIdUnparsed.ToString()} - Could not find guild for message");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
_logger.Information(LogSource.Migration, $"{messageIdUnparsed.ToString()} - Found Role {roleId.ToString()}");
|
||||
await _reactionListener.AddRoleToListener(ulong.Parse(messageIdUnparsed), guildId, reaction.Name, role);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Error(LogSource.Migration, $"Failed to migrate reaction for {messageIdUnparsed.ToString()}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,7 +25,6 @@
|
|||
<PackageReference Include="Google.Apis.YouTube.v3" Version="1.43.0.1834" />
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.18" />
|
||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.DataProtection.Redis" Version="0.4.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Cors" Version="2.2.0" />
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using Geekbot.net.Lib.Logger;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace Geekbot.net.Lib.AlmostRedis
|
||||
{
|
||||
// if anyone ever sees this, please come up with a better fucking name, i'd appriciate it
|
||||
public class AlmostRedis : IAlmostRedis
|
||||
{
|
||||
private readonly GeekbotLogger _logger;
|
||||
private readonly RunParameters _runParameters;
|
||||
|
||||
public AlmostRedis(GeekbotLogger logger, RunParameters runParameters)
|
||||
{
|
||||
_logger = logger;
|
||||
_runParameters = runParameters;
|
||||
}
|
||||
|
||||
public void Connect()
|
||||
{
|
||||
Connection = ConnectionMultiplexer.Connect($"{_runParameters.RedisHost}:{_runParameters.RedisPort}");
|
||||
Db = Connection.GetDatabase(int.Parse(_runParameters.RedisDatabase));
|
||||
_logger.Information(LogSource.Redis, $"Connected to Redis on {Connection.Configuration} at {Db.Database}");
|
||||
}
|
||||
|
||||
public IDatabase Db { get; private set; }
|
||||
|
||||
public ConnectionMultiplexer Connection { get; private set; }
|
||||
|
||||
public IEnumerable<RedisKey> GetAllKeys()
|
||||
{
|
||||
return Connection.GetServer($"{_runParameters.RedisHost}:{_runParameters.RedisPort}").Keys(int.Parse(_runParameters.RedisDatabase));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace Geekbot.net.Lib.AlmostRedis
|
||||
{
|
||||
public interface IAlmostRedis
|
||||
{
|
||||
void Connect();
|
||||
IDatabase Db { get; }
|
||||
ConnectionMultiplexer Connection { get; }
|
||||
IEnumerable<RedisKey> GetAllKeys();
|
||||
}
|
||||
}
|
|
@ -10,7 +10,7 @@
|
|||
TranslationsFailed = 201,
|
||||
|
||||
// Dependent Services
|
||||
RedisConnectionFailed = 301,
|
||||
/* 301 not in use anymore (redis) */
|
||||
DatabaseConnectionFailed = 302,
|
||||
|
||||
// Discord Related
|
||||
|
|
|
@ -10,7 +10,6 @@ namespace Geekbot.net.Lib.Logger
|
|||
Rest,
|
||||
Gateway,
|
||||
Discord,
|
||||
Redis,
|
||||
Database,
|
||||
Message,
|
||||
UserRepository,
|
||||
|
|
|
@ -50,19 +50,6 @@ namespace Geekbot.net.Lib
|
|||
[Option("db-logging", Default = false, HelpText = "Enable database logging")]
|
||||
public bool DbLogging { get; set; }
|
||||
|
||||
/************************************
|
||||
* Redis *
|
||||
************************************/
|
||||
|
||||
[Option("redis-host", Default = "127.0.0.1", HelpText = "Set a redis host")]
|
||||
public string RedisHost { get; set; }
|
||||
|
||||
[Option("redis-port", Default = "6379", HelpText = "Set a redis port")]
|
||||
public string RedisPort { get; set; }
|
||||
|
||||
[Option("redis-database", Default = "6", HelpText = "Select a redis database (1-15)")]
|
||||
public string RedisDatabase { get; set; }
|
||||
|
||||
/************************************
|
||||
* WebApi *
|
||||
************************************/
|
||||
|
|
|
@ -8,7 +8,6 @@ using Discord.Commands;
|
|||
using Discord.WebSocket;
|
||||
using Geekbot.net.Database;
|
||||
using Geekbot.net.Lib;
|
||||
using Geekbot.net.Lib.AlmostRedis;
|
||||
using Geekbot.net.Lib.Clients;
|
||||
using Geekbot.net.Lib.Converters;
|
||||
using Geekbot.net.Lib.ErrorHandling;
|
||||
|
@ -41,7 +40,6 @@ namespace Geekbot.net
|
|||
private GeekbotLogger _logger;
|
||||
private IUserRepository _userRepository;
|
||||
private RunParameters _runParameters;
|
||||
private IAlmostRedis _redis;
|
||||
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
|
@ -94,17 +92,6 @@ namespace Geekbot.net
|
|||
|
||||
_globalSettings = new GlobalSettings(database);
|
||||
|
||||
try
|
||||
{
|
||||
_redis = new AlmostRedis(logger, runParameters);
|
||||
_redis.Connect();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.Error(LogSource.Redis, "Redis Connection Failed", e);
|
||||
Environment.Exit(GeekbotExitCode.RedisConnectionFailed.GetHashCode());
|
||||
}
|
||||
|
||||
_token = runParameters.Token ?? _globalSettings.GetKey("DiscordToken");
|
||||
if (string.IsNullOrEmpty(_token))
|
||||
{
|
||||
|
@ -128,7 +115,6 @@ namespace Geekbot.net
|
|||
var randomNumberGenerator = new RandomNumberGenerator();
|
||||
var kvMemoryStore = new KvInInMemoryStore();
|
||||
|
||||
_services.AddSingleton(_redis);
|
||||
_services.AddSingleton(_userRepository);
|
||||
_services.AddSingleton<IGeekbotLogger>(logger);
|
||||
_services.AddSingleton<ILevelCalc>(levelCalc);
|
||||
|
|
Loading…
Reference in a new issue