-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
65 lines (58 loc) · 2.08 KB
/
index.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
require('dotenv').config()
const { Client, Intents, MessageEmbed } = require('discord.js')
const utils = require('./utils')
const { getImage, getPost } = require('random-reddit')
// Map of commands to their respective subreddits
const map = new Map(Object.entries({
moo: `cow`,
chonk: `cat`,
momos: `dog`,
bhature: `bhature`,
}))
// Initialize Discord Bot
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] })
client.once('ready', function (evt) {
utils.logger.info('Connected')
utils.logger.info(client.user.id)
client.user.setActivity('with my life')
})
client.on('message', async function (message) {
console.log(message.content)
try {
if (map.has(message.content)) {
imageUrl = await getImage(map.get(message.content))
message.channel.send(imageUrl)
}
else if (message.content.substr(0, 2) === `!r`) {
subreddit = message.content.substr(3)
try {
imageUrl = await getImage(subreddit)
} catch (error) {
message.channel.send(`Invalid subreddit/No Images found for ${subreddit}`)
return
}
message.channel.send(imageUrl)
} else if (message.content.substr(0, 2) === `!p`) {
subreddit = message.content.substr(3)
try {
post = await getPost(subreddit)
} catch (error) {
message.channel.send(`Invalid subreddit/No Posts found for ${subreddit}`)
return
}
const embed = new MessageEmbed(
{
title: `${post?.crosspost_parent_list?.title || post?.title}`,
url: `https://reddit.com${post?.permalink}`,
image: {
url: post?.url
}
}
)
message.channel.send(embed)
}
} catch (err) {
utils.logger.error(err)
}
})
client.login(process.env.token)