mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-17 09:59:10 +00:00
feat: add /pickable-roles and /pick-role basis
This commit is contained in:
parent
c2ee4f380a
commit
a4207d5713
22 changed files with 343 additions and 23 deletions
23
packages/api/handlers/interactions-pick-role.ts
Normal file
23
packages/api/handlers/interactions-pick-role.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import { interactionsEndpoint } from '../utils/api-tools';
|
||||
import { getGuildData } from '../utils/guild';
|
||||
import { invalid, notFound, ok } from '../utils/responses';
|
||||
|
||||
export const InteractionsPickRole = interactionsEndpoint(
|
||||
async (request: Request): Promise<Response> => {
|
||||
const reqURL = new URL(request.url);
|
||||
const [, , serverID, userID, roleID] = reqURL.pathname.split('/');
|
||||
if (!serverID || !userID || !roleID) {
|
||||
return invalid();
|
||||
}
|
||||
|
||||
const guildData = await getGuildData(serverID);
|
||||
if (!guildData) {
|
||||
return notFound();
|
||||
}
|
||||
|
||||
// We get exactly one role, but we have to interact with it the same way as UI does.
|
||||
// So check for safety, disable any "single" mode roles
|
||||
|
||||
return ok();
|
||||
}
|
||||
);
|
33
packages/api/handlers/interactions-pickable-roles.ts
Normal file
33
packages/api/handlers/interactions-pickable-roles.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
import { Category, CategorySlug } from '@roleypoly/types';
|
||||
import { respond } from '@roleypoly/worker-utils';
|
||||
import { interactionsEndpoint } from '../utils/api-tools';
|
||||
import { getGuildData } from '../utils/guild';
|
||||
import { notFound } from '../utils/responses';
|
||||
|
||||
export const InteractionsPickableRoles = interactionsEndpoint(
|
||||
async (request: Request): Promise<Response> => {
|
||||
const reqURL = new URL(request.url);
|
||||
const [, , serverID] = reqURL.pathname.split('/');
|
||||
|
||||
const guildData = await getGuildData(serverID);
|
||||
if (!guildData) {
|
||||
return notFound();
|
||||
}
|
||||
|
||||
const roleMap: Record<Category['name'], CategorySlug> = {};
|
||||
|
||||
for (let category of guildData.categories) {
|
||||
if (category.hidden) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO: role safety?
|
||||
roleMap[category.name] = {
|
||||
roles: category.roles,
|
||||
type: category.type,
|
||||
};
|
||||
}
|
||||
|
||||
return respond(roleMap);
|
||||
}
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue