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
|
import { DiscordAPIError, Message, VoiceChannel } from 'discord.js';
import { BushCommand, BushMessage, BushSlashMessage } from '../../lib';
const activityMap = {
'Poker Night': '755827207812677713',
'Betrayal.io': '773336526917861400',
'Fishington.io': '814288819477020702',
'YouTube Together': '755600276941176913',
'Chess in the Park': '832012774040141894',
'Watch Together': '880218394199220334',
'Doodle Crew': '878067389634314250',
'Wood Snacks': '879863976006127627',
'Letter Tile': '879863686565621790'
};
function map(phase: string) {
if (client.consts.regex.snowflake.test(phase)) return phase;
else if (Object.keys(activityMap).includes(phase)) return activityMap[phase as keyof typeof activityMap];
else if (['yt', 'youtube'].includes(phase)) return activityMap['Watch Together'];
else if (['chess', 'park'].includes(phase)) return activityMap['Chess in the Park'];
else if (['poker'].includes(phase)) return activityMap['Poker Night'];
else if (['fish', 'fishing', 'fishington'].includes(phase)) return activityMap['Fishington.io'];
else if (['betrayal'].includes(phase)) return activityMap['Betrayal.io'];
else if (['doodle-crew', 'doodle'].includes(phase)) return activityMap['Doodle Crew'];
else if (['wood-snacks', 'wood'].includes(phase)) return activityMap['Wood Snacks'];
else if (['letter-tile', 'letter'].includes(phase)) return activityMap['Letter Tile'];
else return null;
}
const activityTypeCaster = (_message: Message | BushMessage | BushSlashMessage, phrase: string) => {
if (!phrase) return null;
const mappedPhrase = map(phrase);
if (mappedPhrase) return mappedPhrase;
return null;
};
export default class YouTubeCommand extends BushCommand {
constructor() {
super('activity', {
aliases: [
'activity',
'yt',
'youtube',
'chess',
'park',
'poker',
'fish',
'fishing',
'fishington',
'betrayal',
'doodle-crew',
'doodle',
'wood-snacks',
'wood',
'letter-tile',
'letter'
],
category: 'utilities',
description: {
content: 'Allows you to play discord activities in voice channels.',
usage: [
'activity <channel> <`yt`|`youtube`|`chess`|`park`|`poker`|`fish`|`fishing`|`fishington`|`betrayal`>',
'yt <channel>' // you do not need to specify the activity if you use its alias.
],
examples: ['yt 785281831788216364', 'activity 785281831788216364 yt']
},
args: [
{
id: 'channel',
type: 'voiceChannel',
prompt: {
start: 'What channel would you like to use?',
retry: '{error} Choose a valid voice channel'
}
},
{
id: 'activity',
match: 'rest',
customType: activityTypeCaster,
prompt: {
start: 'What activity would you like to play?',
retry:
'{error} You must choose one of the following options: `yt`, `youtube`, `chess`, `park`, `poker`, `fish`, `fishing`, `fishington`, or `betrayal`.'
}
}
],
slash: true,
slashOptions: [
{
name: 'channel',
description: 'What channel would you like to use?',
type: 'CHANNEL',
required: true
},
{
name: 'activity',
description: 'What activity would you like to play?',
type: 'STRING',
required: true,
choices: Object.keys(activityMap).map((key) => ({ name: key, value: activityMap[key as keyof typeof activityMap] }))
}
],
clientPermissions: (m) => util.clientSendAndPermCheck(m),
userPermissions: []
});
}
public override async exec(
message: BushMessage | BushSlashMessage,
args: { channel: VoiceChannel; activity: string }
): Promise<unknown> {
const channel = typeof args.channel === 'string' ? message.guild?.channels.cache.get(args.channel) : args.channel;
if (!channel || channel.type !== 'GUILD_VOICE')
return await message.util.reply(`${util.emojis.error} Choose a valid voice channel`);
const target_application_id = message.util.isSlash ? args.activity : activityTypeCaster(message, args.activity);
let response: string;
const invite = await (client as any).api
.channels(channel.id)
.invites.post({
data: {
validate: null,
max_age: 604800,
max_uses: 0,
target_type: 2,
target_application_id,
temporary: false
}
})
.catch((e: Error | DiscordAPIError) => {
if ((e as DiscordAPIError).code === 50013) {
response = `${util.emojis.error} I am missing permissions to make an invite in that channel.`;
return;
} else response = `${util.emojis.error} An error occurred while generating your invite: ${e?.message ?? e}`;
});
if (response! || !invite || !invite.code)
return await message.util.reply(
response! ?? `${util.emojis.error} An unknown error occurred while generating your invite.`
);
else return await message.util.send(`https://discord.gg/${invite.code}`);
}
}
|