chore: require redis connection for bot

This commit is contained in:
spiral 2023-02-12 18:00:05 -05:00
parent 52c9ca9d0e
commit 3e76fd8d28
4 changed files with 5 additions and 14 deletions

View File

@ -53,8 +53,7 @@ public class Init
// initialize Redis
var redis = services.Resolve<RedisService>();
if (coreConfig.RedisAddr != null)
await redis.InitAsync(coreConfig);
await redis.InitAsync(coreConfig);
var cache = services.Resolve<IDiscordCache>();
if (cache is RedisDiscordCache)
@ -67,16 +66,14 @@ public class Init
await services.Resolve<IDatabase>().ApplyMigrations();
// Clear shard status from Redis
if (redis.Connection != null)
await redis.Connection.GetDatabase().KeyDeleteAsync("pluralkit:shardstatus");
await redis.Connection.GetDatabase().KeyDeleteAsync("pluralkit:shardstatus");
}
logger.Information("Initializing bot");
var bot = services.Resolve<Bot>();
// Get bot status message from Redis
if (redis.Connection != null)
bot.CustomStatusMessage = await redis.Connection.GetDatabase().StringGetAsync("pluralkit:botstatus");
bot.CustomStatusMessage = await redis.Connection.GetDatabase().StringGetAsync("pluralkit:botstatus");
// Init the bot instance itself, register handlers and such to the client before beginning to connect
bot.Init();

View File

@ -52,12 +52,6 @@ public class ShardInfoService
async Task Inner()
{
if (_redis.Connection == null)
{
_logger.Warning("Redis is disabled, shard connection status will be unavailable.");
return;
}
var db = _redis.Connection.GetDatabase();
var redisInfo = await db.HashGetAsync("pluralkit::shardstatus", shard.ShardId);

View File

@ -8,8 +8,7 @@ public class RedisService
public async Task InitAsync(CoreConfig config)
{
if (config.RedisAddr != null)
Connection = await ConnectionMultiplexer.ConnectAsync(config.RedisAddr);
Connection = await ConnectionMultiplexer.ConnectAsync(config.RedisAddr);
}
private string LastMessageKey(ulong userId, ulong channelId) => $"user_last_message:{userId}:{channelId}";

View File

@ -17,6 +17,7 @@ The configuration file needs to be placed in the bot's working directory (usuall
The configuration file is in JSON format (albeit with a `.conf` extension). The following keys are available (using `.` to indicate a nested object level), bolded key names are required:
* **`PluralKit.Bot.Token`**: the Discord bot token to connect with
* **`PluralKit.Database`**: the URI of the database to connect to (in [ADO.NET Npgsql format](https://www.connectionstrings.com/npgsql/))
* **`PluralKit.RedisAddr`**: the `host:port` of a Redis database to connect to
* `PluralKit.Bot.Prefixes`: an array of command prefixes to use (default `["pk;", "pk!"]`).
* **`PluralKit.Bot.ClientId`**: the ID of the bot's user account, used for calculating the bot's own permissions and for the link in `pk;invite`.
* `PluralKit.SentryUrl` *(optional)*: the [Sentry](https://sentry.io/welcome/) client key/DSN to report runtime errors to. If absent, disables Sentry integration.