mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-04-25 12:19:10 +00:00
30 lines
780 B
JavaScript
30 lines
780 B
JavaScript
// @flow
|
|
import { type AppContext } from '../Roleypoly'
|
|
import { type Context } from 'koa'
|
|
import { bot } from './_security'
|
|
|
|
export default ($: AppContext) => ({
|
|
async checkAuthChallenge (ctx: Context, text: string): Promise<boolean> {
|
|
const chall = await $.auth.fetchDMChallenge({ human: text.toLowerCase() })
|
|
if (chall == null) {
|
|
return false
|
|
}
|
|
|
|
$.auth.injectSessionFromChallenge(ctx, chall)
|
|
$.auth.deleteDMChallenge(chall)
|
|
return true
|
|
},
|
|
|
|
issueAuthChallenge: bot($, (ctx: Context, userId: string) => {
|
|
return $.discord.issueChallenge(userId)
|
|
}),
|
|
|
|
botPing: bot($, () => {
|
|
return true
|
|
}),
|
|
|
|
removeUserSessions: bot($, async (ctx: Context, userId: string) => {
|
|
await $.auth.clearUserSessions(userId)
|
|
return true
|
|
})
|
|
})
|