mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-16 17:49:09 +00:00
feat: Slash Commands (#337)
* feat: add discord interactions worker * feat(interactions): update CI/CD and terraform to add interactions * chore: fix lint issues * chore: fix build & emulation * fix(interactions): deployment + handler * chore: remove worker-dist via gitignore * feat: add /pickable-roles and /pick-role basis * feat: add pick, remove, and update the general /roleypoly command * fix: lint missing Member import
This commit is contained in:
parent
dde05c402e
commit
066f68ffef
59 changed files with 1219 additions and 248 deletions
41
packages/interactions/utils/api.ts
Normal file
41
packages/interactions/utils/api.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
import { Category, CategorySlug } from '@roleypoly/types';
|
||||
import { apiPublicURI, interactionsSharedKey } from './config';
|
||||
|
||||
export const apiFetch = (url: string, init: RequestInit = {}) =>
|
||||
fetch(`${apiPublicURI}${url}`, {
|
||||
...init,
|
||||
headers: {
|
||||
...(init.headers || {}),
|
||||
authorization: `Shared ${interactionsSharedKey}`,
|
||||
},
|
||||
});
|
||||
|
||||
export const getPickableRoles = async (
|
||||
guildID: string
|
||||
): Promise<Record<Category['name'], CategorySlug>> => {
|
||||
const response = await apiFetch(`/interactions-pickable-roles/${guildID}`);
|
||||
|
||||
if (response.status !== 200) {
|
||||
throw new Error(
|
||||
`API request failed to /interactions-pickable-roles, got code: ${response.status}`
|
||||
);
|
||||
}
|
||||
|
||||
return (await response.json()) as Record<Category['name'], CategorySlug>;
|
||||
};
|
||||
|
||||
export const selectRole = async (
|
||||
mode: 'add' | 'remove',
|
||||
guildID: string,
|
||||
userID: string,
|
||||
roleID: string
|
||||
): Promise<number> => {
|
||||
const response = await apiFetch(
|
||||
`/interactions-pick-role/${guildID}/${userID}/${roleID}`,
|
||||
{
|
||||
method: mode === 'add' ? 'PUT' : 'DELETE',
|
||||
}
|
||||
);
|
||||
|
||||
return response.status;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue