Table of Contents

Class DiscordVerificationService

Namespace
FishMMO.DiscordBot.Services
Assembly
FishMMO-DiscordBot.dll

Delivers the Discord account-verification DM: the one message, ever, that carries an account's Discord verification code.

public sealed class DiscordVerificationService : BackgroundService, IHostedService, IDisposable
Inheritance
DiscordVerificationService
Implements
Inherited Members

Remarks

Who does what. The game and the Control Panel issue the code; the player types it back into the game or the panel. This service only carries it. Nothing is ever typed into Discord.

No polling. Issuing a code raises a PostgreSQL notification on NotifyChannel, which a dedicated connection here LISTENs for. A slow sweep catches anything raised while the bot or its listener was down, the gateway's Ready event catches up after a reconnect, and a player who was not in the Discord server yet is served from the member-joined event with a targeted read of just their username.

One DM, ever. A delivery is claimed before it is sent and marked delivered after. A send that Discord definitely refused (a 4xx, such as closed DMs) is released and counts as an attempt. A send whose outcome is unknown (a timeout, a 5xx, a dropped connection) may have reached the player, so it is deliberately left claimed for staff to check: one DM ever beats a guaranteed delivery.

Single flight. Every wake source only signals a one-slot channel, and one loop reads it, so passes never overlap and any number of wakes during a pass collapse into one more pass.

Constructors

DiscordVerificationService(DiscordSocketClient, IDiscordAccountService, NpgsqlDbContextFactory, IConfiguration, ILogger<DiscordVerificationService>)

Initializes a new instance of the DiscordVerificationService class.

public DiscordVerificationService(DiscordSocketClient discordClient, IDiscordAccountService accountService, NpgsqlDbContextFactory dbContextFactory, IConfiguration configuration, ILogger<DiscordVerificationService> logger)

Parameters

discordClient DiscordSocketClient

The Discord socket client.

accountService IDiscordAccountService

The database's Discord delivery and link service.

dbContextFactory NpgsqlDbContextFactory

Factory whose connection string the LISTEN connection reuses.

configuration IConfiguration

Application configuration.

logger ILogger<DiscordVerificationService>

Logger instance.

Methods

ExecuteAsync(CancellationToken)

This method is called when the IHostedService starts. The implementation should return a task that represents the lifetime of the long running operation(s) being performed.

protected override Task ExecuteAsync(CancellationToken stoppingToken)

Parameters

stoppingToken CancellationToken

Triggered when StopAsync(CancellationToken) is called.

Returns

Task

A Task that represents the long running operations.

Remarks

See Worker Services in .NET for implementation guidelines.