mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-17 09:59:10 +00:00
feat: add discord interactions worker
This commit is contained in:
parent
dde05c402e
commit
9354047447
36 changed files with 486 additions and 178 deletions
|
@ -7,10 +7,13 @@ type URLParams = {
|
|||
clientID: string;
|
||||
permissions: number;
|
||||
guildID?: string;
|
||||
scopes: string[];
|
||||
};
|
||||
|
||||
const buildURL = (params: URLParams) => {
|
||||
let url = `https://discord.com/api/oauth2/authorize?client_id=${params.clientID}&scope=bot&permissions=${params.permissions}`;
|
||||
let url = `https://discord.com/api/oauth2/authorize?client_id=${
|
||||
params.clientID
|
||||
}&scope=${params.scopes.join('%20')}&permissions=${params.permissions}`;
|
||||
|
||||
if (params.guildID) {
|
||||
url += `&guild_id=${params.guildID}&disable_guild_select=true`;
|
||||
|
@ -31,6 +34,7 @@ export const BotJoin = (request: Request): Response => {
|
|||
clientID: botClientID,
|
||||
permissions: 268435456,
|
||||
guildID,
|
||||
scopes: ['bot', 'application.commands'],
|
||||
})
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { memberPassesAccessControl } from '@roleypoly/api/utils/access-control';
|
||||
import { accessControlViolation } from '@roleypoly/api/utils/responses';
|
||||
import { DiscordUser, GuildSlug, PresentableGuild, SessionData } from '@roleypoly/types';
|
||||
import { respond, withSession } from '../utils/api-tools';
|
||||
import { respond } from '@roleypoly/worker-utils';
|
||||
import { withSession } from '../utils/api-tools';
|
||||
import { getGuild, getGuildData, getGuildMember } from '../utils/guild';
|
||||
|
||||
const fail = () => respond({ error: 'guild not found' }, { status: 404 });
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { SessionData } from '@roleypoly/types';
|
||||
import { respond, withSession } from '../utils/api-tools';
|
||||
import { respond } from '@roleypoly/worker-utils';
|
||||
import { withSession } from '../utils/api-tools';
|
||||
|
||||
export const GetSession = withSession((session?: SessionData) => (): Response => {
|
||||
const { user, guilds, sessionID } = session || {};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { GuildSlug } from '@roleypoly/types';
|
||||
import { respond } from '../utils/api-tools';
|
||||
import { respond } from '@roleypoly/worker-utils';
|
||||
import { getGuild } from '../utils/guild';
|
||||
|
||||
export const GetSlug = async (request: Request): Promise<Response> => {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { StateSession } from '@roleypoly/types';
|
||||
import { getQuery, isAllowedCallbackHost, setupStateSession } from '../utils/api-tools';
|
||||
import { getQuery } from '@roleypoly/worker-utils';
|
||||
import { isAllowedCallbackHost, setupStateSession } from '../utils/api-tools';
|
||||
import { Bounce } from '../utils/bounce';
|
||||
import { apiPublicURI, botClientID } from '../utils/config';
|
||||
|
||||
|
|
|
@ -5,25 +5,22 @@ import {
|
|||
SessionData,
|
||||
StateSession,
|
||||
} from '@roleypoly/types';
|
||||
import KSUID from 'ksuid';
|
||||
import {
|
||||
AuthType,
|
||||
discordAPIBase,
|
||||
discordFetch,
|
||||
userAgent,
|
||||
} from '@roleypoly/worker-utils';
|
||||
import KSUID from 'ksuid';
|
||||
import {
|
||||
formData,
|
||||
getStateSession,
|
||||
isAllowedCallbackHost,
|
||||
parsePermissions,
|
||||
resolveFailures,
|
||||
userAgent,
|
||||
} from '../utils/api-tools';
|
||||
import { Bounce } from '../utils/bounce';
|
||||
import {
|
||||
apiPublicURI,
|
||||
botClientID,
|
||||
botClientSecret,
|
||||
discordAPIBase,
|
||||
uiPublicURI,
|
||||
} from '../utils/config';
|
||||
import { apiPublicURI, botClientID, botClientSecret, uiPublicURI } from '../utils/config';
|
||||
import { Sessions } from '../utils/kv';
|
||||
|
||||
const AuthErrorResponse = (extra?: string) =>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { SessionData } from '@roleypoly/types';
|
||||
import { formData, respond, userAgent, withSession } from '../utils/api-tools';
|
||||
import { botClientID, botClientSecret, discordAPIBase } from '../utils/config';
|
||||
import { discordAPIBase, respond, userAgent } from '@roleypoly/worker-utils';
|
||||
import { formData, withSession } from '../utils/api-tools';
|
||||
import { botClientID, botClientSecret } from '../utils/config';
|
||||
import { Sessions } from '../utils/kv';
|
||||
|
||||
export const RevokeSession = withSession(
|
||||
|
|
|
@ -10,8 +10,9 @@ import {
|
|||
SessionData,
|
||||
TransactionType,
|
||||
} from '@roleypoly/types';
|
||||
import { AuthType, discordFetch, respond } from '@roleypoly/worker-utils';
|
||||
import { difference, groupBy, keyBy, union } from 'lodash';
|
||||
import { AuthType, discordFetch, respond, withSession } from '../utils/api-tools';
|
||||
import { withSession } from '../utils/api-tools';
|
||||
import { botToken } from '../utils/config';
|
||||
import {
|
||||
getGuild,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue