forked from demtario/mailer-discord-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (32 loc) · 941 Bytes
/
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
import Bot from './bot'
import Mailer from './mailer'
import { mapMapToEmbed, isInCC } from './utils'
require('dotenv').config()
const { MAIL_EMAIL, MAIL_USERNAME, MAIL_PASSWORD, MAIL_HOST, DISCORD_TOKEN, DISCORD_CHANNEL_NAME } = process.env
const main = async () => {
const bot = new Bot()
const mailer = new Mailer({
email: MAIL_EMAIL,
username: MAIL_USERNAME,
password: MAIL_PASSWORD,
host: MAIL_HOST
})
await bot.login(DISCORD_TOKEN)
mailer.subscribe((mail) => {
if (isInCC(mail.cc)) {
const message = mapMapToEmbed(mail)
bot.sendMessage(message, DISCORD_CHANNEL_NAME)
}
})
bot.setStatus(`Waiting for emails <${MAIL_EMAIL}>`, 'LISTENING')
const cleanup = async () => {
process.stdin.resume()
await bot.destroy()
mailer.destroy()
process.exit(99)
}
process.on('SIGINT', cleanup)
process.on('SIGUSR1', cleanup)
process.on('SIGUSR2', cleanup)
}
main()