Class DiscordAccountService
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
dbContextFactoryINpgsqlDbContextFactory
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
accountNamestringcancellationTokenCancellationToken
Returns
FetchLinkByDiscordUserAsync(long, CancellationToken)
The account a Discord user is linked to, or null.
public Task<DatabaseResult<DiscordAccountLink?>> FetchLinkByDiscordUserAsync(long discordUserId, CancellationToken cancellationToken = default)
Parameters
discordUserIdlongcancellationTokenCancellationToken
Returns
FetchPendingDeliveriesAsync(int, CancellationToken)
DMs owed and not yet claimed, oldest account first.
public Task<DatabaseResult<IReadOnlyList<DiscordVerificationDelivery>>> FetchPendingDeliveriesAsync(int limit, CancellationToken cancellationToken = default)
Parameters
limitintcancellationTokenCancellationToken
Returns
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
discordUsernamestringcancellationTokenCancellationToken
Returns
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
accountNamestringdiscordUserIdlongdiscordUsernamestringcancellationTokenCancellationToken
Returns
- Task<DatabaseResult>
UNIQUE_VIOLATIONwhen 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
accountNamestringdiscordUserIdlongcancellationTokenCancellationToken
Returns
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
accountNamestringThe account.
reasonstringWhy it did not send, for staff.
countAttemptboolTrue 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.
cancellationTokenCancellationTokenCancellation token.
Returns
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
discordUserIdlongcancellationTokenCancellationToken