-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.js
220 lines (202 loc) · 5.58 KB
/
commands.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import util from 'util';
import { getAgentChoices } from './game.js';
import { capitalize, DiscordRequest } from './utils.js';
const CHAT_INPUT = 1;
const STRING = 3;
const INTEGER = 4;
const BOOLEAN = 5;
const USER = 6;
const CHANNEL = 7;
export async function SyncGuildCommands(appId, guildId, existingCommands, updatedCommands) {
if (guildId === '' || appId === '') return;
console.log(`\nSyncing guild ${guildId}`)
const endpoint = `applications/${appId}/guilds/${guildId}/commands`;
try {
const res = await DiscordRequest(endpoint, { method: 'GET' });
const installedCommands = await res.data;
const existingCommandNames = existingCommands.map(c => c.name);
for (const cmd of installedCommands) {
if (!existingCommandNames.includes(cmd.name)) {
console.log(`Deleting unused command: "${cmd.name}"`);
await RemoveGuildCommand(appId, guildId, cmd.id);
console.log(`Deleted "${cmd.name}"`);
}
}
} catch (err) {
console.error(util.inspect(err.response.data, {showHidden: false, depth: null, colors: true}))
}
updatedCommands.forEach(async (cmd) => {
console.log(`Installing "${cmd.name}"`);
await InstallGuildCommand(appId, guildId, cmd);
console.log(`Installed "${cmd.name}"`);
});
}
export async function InstallGuildCommand(appId, guildId, command) {
// API endpoint to get and post guild commands
const endpoint = `applications/${appId}/guilds/${guildId}/commands`;
try {
await DiscordRequest(endpoint, { method: 'POST', data: command });
} catch (err) {
console.error(util.inspect(err.response.data, {showHidden: false, depth: null, colors: true}))
}
}
export async function RemoveGuildCommand(appId, guildId, commandId) {
const endpoint = `applications/${appId}/guilds/${guildId}/commands/${commandId}`;
try {
await DiscordRequest(endpoint, { method: 'DELETE' });
} catch (err) {
console.error(util.inspect(err.response.data, {showHidden: false, depth: null, colors: true}))
}
}
function createCommandChoices() {
const choices = getAgentChoices();
return choices.map(choice => ({
name: capitalize(choice),
value: choice.toLowerCase(),
}));
}
export const FLOW_COMMAND = {
name: 'flow',
description: 'Tell me something about our Queen Flow',
type: CHAT_INPUT,
}
export const GAME_COMMAND = {
name: 'game',
description: 'Select a random Steam game from this channel\'s recent messages',
type: CHAT_INPUT,
options: [
{
type: BOOLEAN,
name: 'fullfetch',
description: 'Ignore any caches and force a full read of the channel. This may cause timeouts or slow responses'
}
]
}
export const TIME_COMMAND = {
name: 'time',
description: 'Converts date and time to Discord timestamp',
type: CHAT_INPUT,
options: [
{
type: STRING,
name: 'date',
description: 'One or more comma-separated dates in format MM/dd/YYYY HH:MM Or Day HH:MM, and game',
required: true,
},
{
type: STRING,
name: 'timezone',
description: 'Timezone (optional)',
},
]
}
export const WEEKLY_COMMAND = {
name: 'week',
description: 'Weekly Schedule using Discord timestamps',
type: CHAT_INPUT,
options: [
{
type: STRING,
name: 'date',
description: 'One or more comma-separated dates in format MM/dd/YYYY HH:MM Or Day HH:MM, and game',
required: true,
},
{
type: STRING,
name: 'timezone',
description: 'Timezone (optional)',
},
]
}
export const CHALLENGE_COMMAND = {
name: 'challenge',
description: 'Challenge to a match of valorant agent battles',
type: CHAT_INPUT,
options: [
{
type: STRING,
name: 'agent',
description: 'Choose your Agent',
required: true,
choices: createCommandChoices(),
},
{
type: USER,
name: 'target',
description: 'User to challange',
},
],
}
export const REMINDER_COMMAND = {
name: 'remind',
description: 'Add a daily reminder',
type: CHAT_INPUT,
options: [
{
type: STRING,
name: 'keyword',
description: 'Keyword(s) for the reminder. Example: laundry or buy groceries',
required: true,
},
{
type: STRING,
name: 'description',
description: 'Detailed description of the reminder',
},
{
type: USER,
name: 'user',
description: 'User to send reminder to. By default, current user',
},
{
type: CHANNEL,
name: 'channel',
description: 'Channel to send reminder to. By default, current channel',
},
{
type: INTEGER,
name: 'csthour',
description: 'The hour of day to send the reminder. Note: Must be in CST. By default, 10, for 10 am CST',
},
{
type: STRING,
name: 'cronexpression',
description: 'The exact UTC cron expression for your reminders. See https://crontab.guru for details',
},
{
type: INTEGER,
name: 'nreminders',
description: 'Total Number of reminders to send. By default, 1',
},
]
}
export const SHOW_REMINDERS_COMMAND = {
name: 'showreminders',
description: 'Show the daily reminders',
type: CHAT_INPUT,
options: [
{
type: USER,
name: 'user',
description: 'User to get the reminders of',
},
],
}
export const STOP_REMINDER_COMMAND = {
name: 'stopreminder',
description: 'Stop a daily reminder',
type: CHAT_INPUT,
options: [
{
type: STRING,
name: 'keyword',
description: 'The reminder keyword that you chose',
required: true,
},
{
type: USER,
name: 'user',
description: 'User that the reminder is sent to',
},
],
}