-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (25 loc) · 1.03 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
const Xusu = require('./xusu')
const xusu = new Xusu()
//# Simple code
xusu.on('message', async message => {
if (message.author.bot) return; // Disallow bots & allows DM messages
if (message.channel.id !== xusu.channel.id && !message.mentions.users.has(xusu.user.id) && message.channel.type !== 'dm') return;
let pattern = `<!?${xusu.user.id}>`
pattern = new RegExp(pattern)
if (message.mentions.users.has(xusu.user.id)) message.content = message.content.replace(pattern, '')
const configuration = {
bot: xusu.type,
text: message.content,
uid: xusu.sessions.get(message.author.id)
}
xusu.chat('http://xu.su/api/send', {
body: JSON.stringify(configuration),
headers: { 'Content-Type': 'application/json' },
method: 'POST',
mode: 'cors'
}).then(response => response.json()).then(response => {
message.channel.send(response.text)
if (!xusu.sessions.get(message.author.id)) xusu.sessions.set(message.author.id, response.uid)
})
})
xusu.auth()