Table of Contents

Class DiscordAccountService

Namespace
FishMMO.Database.Npgsql.Services
Assembly
FishMMO-DB.dll

The Discord bot's side of an account. Parameterized raw SQL for writes, EF for reads.

public sealed class DiscordAccountService : BaseService<AccountEntity>, IDiscordAccountService
Inheritance
DiscordAccountService
Implements
Inherited Members

Remarks

Every write names the state it expects in its WHERE, so two bot instances, or a bot racing a player who verified by email a moment ago, cannot both act: the second matches nothing. See DiscordVerification for the once-only delivery rules.

Constructors

DiscordAccountService(INpgsqlDbContextFactory)

Creates the service.

public DiscordAccountService(INpgsqlDbContextFactory dbContextFactory)

Parameters

dbContextFactory INpgsqlDbContextFactory

Methods

ClaimDeliveryAsync(string, CancellationToken)

Takes one account's DM to send it. False when it has been sent, is already taken, is no longer owed (the account verified another way), or has used up its attempts.

public Task<DatabaseResult<bool>> ClaimDeliveryAsync(string accountName, CancellationToken cancellationToken = default)

Parameters

accountName string
cancellationToken CancellationToken

Returns

Task<DatabaseResult<bool>>

FetchLinkByDiscordUserAsync(long, CancellationToken)

The account a Discord user is linked to, or null.

public Task<DatabaseResult<DiscordAccountLink?>> FetchLinkByDiscordUserAsync(long discordUserId, CancellationToken cancellationToken = default)

Parameters

discordUserId long
cancellationToken CancellationToken

Returns

Task<DatabaseResult<DiscordAccountLink?>>

FetchPendingDeliveriesAsync(int, CancellationToken)

DMs owed and not yet claimed, oldest account first.

public Task<DatabaseResult<IReadOnlyList<DiscordVerificationDelivery>>> FetchPendingDeliveriesAsync(int limit, CancellationToken cancellationToken = default)

Parameters

limit int
cancellationToken CancellationToken

Returns

Task<DatabaseResult<IReadOnlyList<DiscordVerificationDelivery>>>

FetchPendingDeliveriesForUsernameAsync(string, CancellationToken)

DMs owed to one Discord username: what the bot asks when a member joins the server.

public Task<DatabaseResult<IReadOnlyList<DiscordVerificationDelivery>>> FetchPendingDeliveriesForUsernameAsync(string discordUsername, CancellationToken cancellationToken = default)

Parameters

discordUsername string
cancellationToken CancellationToken

Returns

Task<DatabaseResult<IReadOnlyList<DiscordVerificationDelivery>>>

LinkAsync(string, long, string?, CancellationToken)

Links an account to a Discord user, replacing any earlier link on that account.

public Task<DatabaseResult> LinkAsync(string accountName, long discordUserId, string? discordUsername, CancellationToken cancellationToken = default)

Parameters

accountName string
discordUserId long
discordUsername string
cancellationToken CancellationToken

Returns

Task<DatabaseResult>

UNIQUE_VIOLATION when that Discord user is already linked to a different account.

MarkDeliveredAsync(string, long, CancellationToken)

Records that the DM was delivered, and to which Discord user. No further DM is ever sent for the account.

public Task<DatabaseResult> MarkDeliveredAsync(string accountName, long discordUserId, CancellationToken cancellationToken = default)

Parameters

accountName string
discordUserId long
cancellationToken CancellationToken

Returns

Task<DatabaseResult>

ReleaseDeliveryAsync(string, string, bool, CancellationToken)

Gives a claimed DM back unsent, recording why.

public Task<DatabaseResult> ReleaseDeliveryAsync(string accountName, string reason, bool countAttempt, CancellationToken cancellationToken = default)

Parameters

accountName string

The account.

reason string

Why it did not send, for staff.

countAttempt bool

True when Discord refused the message, which counts towards MaxSendAttempts. False when the player simply is not reachable yet (not in the server), which does not.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult>

UnlinkAsync(long, CancellationToken)

Removes a Discord user's link. True when there was one.

public Task<DatabaseResult<bool>> UnlinkAsync(long discordUserId, CancellationToken cancellationToken = default)

Parameters

discordUserId long
cancellationToken CancellationToken

Returns

Task<DatabaseResult<bool>>