feat: add /pickable-roles and /pick-role basis

This commit is contained in:
41666 2021-08-01 18:57:57 -04:00
parent c2ee4f380a
commit a4207d5713
22 changed files with 343 additions and 23 deletions

View 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();
}
);

View 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);
}
);