-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.mjs
62 lines (53 loc) · 1.82 KB
/
index.mjs
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
import fs from 'fs'
import env from 'dotenv'
import didi, { Message } from 'discord.js'
import redis from 'redis'
import fetch from 'node-fetch'
import fxp from 'fast-xml-parser'
import het from 'html-entities'
import lib from './routes/_module.mjs'
// encapsulation import
const { XmlEntities } = het,
{ Client } = didi,
{ createClient } = redis,
{ mkdirSync } = fs
// init managers
const Discord = new Client(),
Redis = createClient({ host : "redis" }),
Ent = new XmlEntities()
// load envs
env.config()
// load config
const FEEDS_REFRESH = 0.5 // minutes
const CLIENT_ID = process.env.CLIENT_ID
const HELP = fs.readFileSync('README.md', {encoding:'utf8', flag:'r'})
const PROVERBS = fs.readFileSync('proverbs.txt', {encoding:'utf8', flag:'r'}).split('\n')
// Rich presence
Discord.on('ready', () => {
console.log(`Logged in as ${Discord.user.tag}!`)
//console.log(Discord.guilds.cache)
Discord.user.setActivity({
type : "WATCHING",
name : 'Shoujo\'s',
startTimestamp : Date.now(),
largeImageKey : "s-l640",
smallImageKey : "small_yuuko"
}); setInterval(() => lib.feed.fds(Discord, Redis, Ent, fxp), 60000 * FEEDS_REFRESH)
})
Discord.on('message', async msg => {
let err = [ `\`❌ I can\'t do this !\`` ]
let prefix = await new Promise(resolve => {
Redis.get(`${msg.guild.name}/prefix` , function(err, reply) {
resolve(err || reply == null ? '!' : reply)
})
})
// Redirect modules
if (msg.content[0] == prefix) {
try {
let extract = msg.content.split(' ')
extract[0] = extract[0].substring(prefix.length)
lib[extract[0]][extract[1]](extract.splice(2), msg, Redis, fxp)
} catch (e) { msg.channel.send(err[0]) }
} else {}
})
Discord.login(process.env.TOKEN)