MCPcopy Create free account
hub / github.com/MathMan05/Fermi / webhookMenu

Function webhookMenu

src/webpage/webhooks.ts:10–181  ·  view source on GitHub ↗
(
	guild: Guild,
	hookURL: string,
	webhooks: Options,
	channelId: false | string = false,
)

Source from the content-addressed store, hash-verified

8import {CDNParams} from "./utils/cdnParams.js";
9
10async function webhookMenu(
11 guild: Guild,
12 hookURL: string,
13 webhooks: Options,
14 channelId: false | string = false,
15) {
16 const moveChannels = guild.channels.filter(
17 (_) => _.hasPermission("MANAGE_WEBHOOKS") && _.type !== 4,
18 );
19 async function regenArea() {
20 webhooks.removeAll();
21
22 webhooks.addButtonInput("", I18n.webhooks.newWebHook(), () => {
23 const nameBox = new Dialog(I18n.webhooks.EnterWebhookName());
24 const options = nameBox.float.options;
25 const defualts = I18n.webhooks.sillyDefaults().split("\n");
26 let channel = channelId || moveChannels[0].id;
27 options.addTextInput(
28 I18n.webhooks.name(),
29 async (name) => {
30 const json = await (
31 await fetch(`${guild.info.api}/channels/${channel}/webhooks/`, {
32 method: "POST",
33 headers: guild.headers,
34 body: JSON.stringify({name}),
35 })
36 ).json();
37 makeHook(json);
38 },
39 {
40 initText: defualts[Math.floor(Math.random() * defualts.length)],
41 },
42 );
43 if (!channelId) {
44 const select = options.addSelect(
45 I18n.webhooks.channel(),
46 () => {},
47 moveChannels.map((_) => _.name),
48 {
49 defaultIndex: 0,
50 },
51 );
52 select.watchForChange((i: number) => {
53 channel = moveChannels[i].id;
54 });
55 }
56 options.addButtonInput("", I18n.submit(), () => {
57 options.submit();
58 nameBox.hide();
59 });
60 nameBox.show();
61 });
62 const hooks = (await (await fetch(hookURL, {headers: guild.headers})).json()) as webhookType[];
63 for (const hook of hooks) {
64 makeHook(hook);
65 }
66 }
67

Callers 2

generateSettingsMethod · 0.85
generateSettingsMethod · 0.85

Calls 2

regenAreaFunction · 0.85
hasPermissionMethod · 0.45

Tested by

no test coverage detected