Commit Graph

14 Commits

Author SHA1 Message Date
Asaf Gartner 4568def378 Added a bunch of discord debugging 2024-03-28 21:24:46 +02:00
Ben Visness 76be9b668a Republish Discord announcements to Abner's Matrix server 2023-12-05 23:55:39 -06:00
bvisness 0210a0784b Add Discord login (#106)
This leverages our existing Discord OAuth implementation. Any users with a linked Discord account will be able to log in immediately. When logging in, we request the `email` scope in addition to `identity`, so existing users will be prompted one time to accept the new permissions. On subsequent logins, Discord will skip the prompt.

When linking your Discord account to an existing HMN account, we continue to only request the `identity` scope, so we do not receive the user's Discord email.

Both login and linking go through the same Discord OAuth callback. All flows through the callback try to achieve the same end goal: a logged-in HMN user with a linked Discord account.

Linking works the same as it ever has. Login, however, is different because we do not have a session ID to use as the OAuth state. To account for this, I have added a `pending_login` table that stores a secure unique ID and the eventual destination URL. These pending logins expire after 10 minutes. When we receive the OAuth callback, we look up the pending login by the OAuth `state` and immediately delete it. The destination URL will be used to redirect the user to the right place.

If we have a `discord_user` entry for the OAuth'd Discord user, we immediately log the user into the associated HMN account. This is the typical login case. If we do not have a `discord_user`, but there is exactly one HMN user with the same email address as the Discord user, we will link the two accounts and log into the HMN account.

(It is possible for multiple HMN accounts to have the same email, because we don't have a uniqueness constraint there. We fail the login in this case rather than link to the wrong account.)

Finally, if no associated HMN user exists, a new one will be created. It will use the Discord user's username, email, and avatar. This user will have no password, but they can set or reset a password through the usual flows.

Co-authored-by: Ben Visness <bvisness@gmail.com>
Reviewed-on: #106
2023-05-06 19:38:50 +00:00
Ben Visness 1df691bc13 Add user command for profile 2021-09-26 20:30:09 -05:00
Ben Visness 85a7a37162 Add /profile slash command 2021-09-26 17:34:38 -05:00
Ben Visness bc39b4c0b7 Clean up TODOs 2021-08-28 12:07:45 -05:00
Ben Visness 16ae2188d1 Add background features to the Discord bot 2021-08-26 22:59:12 -05:00
Ben Visness 042e9166fd Add bulk delete 2021-08-26 19:58:41 -05:00
Ben Visness 719c0d230c Delete stuff on message delete
still need to do bulk delete
2021-08-26 18:33:39 -05:00
Ben Visness 7d5590ee10 Process Discord markdown for snippets 2021-08-23 22:26:27 -05:00
Ben Visness 72ae938302 Save Discord attachments and embeds 2021-08-23 16:52:57 -05:00
Ben Visness 76f9256e97 Save Discord messages and attachments 2021-08-21 11:15:27 -05:00
Ben Visness d92bf9a9b8 Add Discord account linking 2021-08-15 23:40:56 -05:00
Ben Visness 38a1188be7 Add Discord integration
Clean up several TODOs

Implement the full disconnect / resume flow

Detect zombied connections and restart

Implement the random delay on reconnect

Implement message sending!!

(with a goofy feedback loop on the echo bot)

Fix the feedback loop in the echo bot

Clean up the Discord gateway code

Many things are methods now to reduce the amount of explicit plumbing.
Connection handling should be a little more robust, and we have an
actual error handling strategy now.

Allow sending multiple Discord messages at once

Delete irrelevant tests

uhh, start rate limiting

Add per-route rate limiting

Add global rate limit handling

Handle context cancellation in Discord REST code

Allow changing buckets per route

Add the showcase rejection bot

Add library bot
2021-08-15 20:21:04 -05:00