-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
159 lines (142 loc) · 5.2 KB
/
index.ts
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
import DiscordJS, { Intents, MessageAttachment, MessageEmbed } from 'discord.js'
import dotenv from 'dotenv'
dotenv.config()
// prefix to call bot with.
let prefix = ','
// "Permissions" registry
const client = new DiscordJS.Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.DIRECT_MESSAGES
]
})
client.on('ready', () => {
console.log('The bot is ready')
})
// Fired when a message is sent in the guild (discord server)
client.on('messageCreate', (message) => {
// Checks for valid bot prefix in message.
// Terminates if not found.
if (!isBotCall(message.content)) {
return;
}
// Checks if message is from a bot.
// Terminates if true
if (message.author.bot) {
return
}
// Debug var
let argDeb = message.content.indexOf(' ')
// Isolate command from potential sub-args
let arg0 = getCommandArg(message.content)
// Command registry
switch (arg0) {
case 'repeat':
const img = null
if (message.attachments.size > 0) {
const img = message.attachments.first()
message.reply('image detected')
}
message.reply({
content: '\u200B' + img
})
break
case 'cheese':
message.reply({
content: 'that is my favorite food',
})
break
case 'ping':
message.reply({
content: 'pong! ' + message.author.toString(),
})
break
case 'pfp':
message.reply({
content: message.author.displayAvatarURL()
})
break
case 'subarg':
message.reply({
content: getCommandSubargs(message.content)
})
break
case 'picture':
let n = 0
let images:string[] = []
message.attachments.forEach(attachment => {
const ImageLink = attachment.proxyURL;
images[n] = ImageLink
n++
message.reply({ files: [ImageLink] })
});
message.reply({ files: [images[0]]})
//let attachment = message.attachments.first()?.url
//message.reply({
// content: 'Here: ' + message.attachments.first()?.proxyURL
//})
break
// How do I let people attach images in their suggestion?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?
case 'suggest':
const embed = new MessageEmbed()
.setColor('#fad378')
//.setTitle('Suggestion')
//.setAuthor({ name: message.author.username, iconURL: message.author.displayAvatarURL()})
//.setDescription('Some description here')
//.setThumbnail('https://i.imgur.com/AfFp7pu.png')
.addFields(
{ name: 'Submitter', value: message.author.tag},
{ name: 'Suggestion', value: 'HELLO'},
//{ name: '\u200B', value: '\u200B' },
//{ name: 'Inline field title', value: 'Some value here', inline: true },
//{ name: 'Inline field title', value: 'Some value here', inline: true },
)
//.addField('Inline field title', 'Some value here', true)
//.setImage(message.attachments.for)
.setTimestamp()
.setFooter({ text: 'User ID: ' + message.author.id, iconURL: message.author.displayAvatarURL() });
message.reply({
embeds: [embed]
})
default:
message.reply({
content: 'arg0 read as: ' + arg0 + '\n' +
'argDeb read as: ' + argDeb + '\n' +
'Sender: '
})
break
}
if (message.content.at(0) === prefix + 'test') {
message.reply({
content: message.author.toString(),
})
}
})
client.login(process.env.TOKEN)
// Takes a string and sees if the first character matches the prefix
function isBotCall(userMessage: string): boolean {
if (userMessage.at(0) === prefix) {
return true
}
return false
}
// Takes a string and returns in the string format of a "command argument"
// - String input loses its prefix (first char) for return.
// - String input is split at first or no space for return.
function getCommandArg(userMessage: string): string {
if (userMessage.indexOf(' ') === -1) {
return userMessage.substring(1, userMessage.length)
}
return userMessage.substring(1, userMessage.indexOf(' '))
}
// Takes a string and returns its "command sub-arguments"
// - All content after first space is returned as a string.
// - Input must have a space char, or return is empty.
function getCommandSubargs(userMessage: string): string {
let firstSpace = userMessage.indexOf(' ')
if (firstSpace === -1) {
return ''
}
return userMessage.substring(firstSpace + 1, userMessage.length)
}