forked from aritsune/lancer-cc-uncle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
73 lines (63 loc) · 2.01 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
66
67
68
69
70
71
72
73
const Commando = require('discord.js-commando')
const { search, getDetails } = require('./search')
const format = require('./format')
require('dotenv').config()
const client = new Commando.Client({
owner: process.env.OWNER,
commandPrefix: '::'
})
client.on('ready', () => console.log('UNCLE is ready!'))
class SearchCommand extends Commando.Command {
constructor(client) {
super(client, {
name: 'search-compendium',
group: 'lancer',
memberName: 'search',
aliases: ['search', 'compendium'],
description: 'Searches the LANCER compendium, including supplements.',
patterns: [/\[\[(.+?)\]\]/],
defaultHandling: false,
throttling: false
})
}
async run(msg) {
console.log(msg.content)
let targets = [];
const re = /\[\[(.+?)\]\]/g
let matches;
while ((matches = re.exec(msg.content)) != null) {
targets.push(matches[1])
}
const results = targets.map((tgt, i) => {
const results = search(tgt)
if (results.length === 0) return `No results found for *${targets[i].replace(/@/g, '\\@')}*.`
else return format(results[0].item)
}).join('\n--\n')
await msg.reply('\n' + results, { split: true })
}
}
class InviteCommand extends Commando.Command {
constructor(client) {
super(client, {
name: 'invite',
group: 'lancer',
memberName: 'invite',
description: 'Get an invite link for UNCLE',
})
client.on('ready', () => this.userID = client.user.id)
}
async run(msg) {
await msg.reply(`Invite me to your server: https://discordapp.com/api/oauth2/authorize?client_id=${this.userID}&permissions=0&scope=bot`)
}
}
const FaqCommand = require('./faq')
client.registry
.registerDefaults()
.registerGroup('lancer', 'LANCER commands')
.registerCommand(FaqCommand)
.registerCommand(SearchCommand)
.registerCommand(InviteCommand)
client.login(process.env.TOKEN)
client.on('ready', () => {
client.user.setPresence({ activity: { name: 'LANCER | use [[brackets]]' }, status: 'online' })
})