Skip to content

Commit cfcb20f

Browse files
committed
added !quest command
1 parent 75d0492 commit cfcb20f

File tree

16 files changed

+45
-69
lines changed

16 files changed

+45
-69
lines changed

.eslintrc

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"no-mixed-operators": [ "off" ],
1616
"no-return-assign": ["off"],
1717
"no-await-in-loop": [ "off" ],
18+
"no-plusplus": [ "off" ],
1819
"no-bitwise": ["error", { "allow": ["~"] }]
1920
}
2021
}

config/default.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"invite": "",
3737
"token": [],
3838
"channels": ["general"],
39-
"userRole": "roleNameHere",
39+
"userRole": ["roleNameHere"],
4040
"admins": ["222742859059560458"],
4141
"prefix": "!",
4242
"typereact": false,

src/controllers/monster.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class Monster extends Controller {
5555
let result = await this.db.raw(query)
5656

5757
if (!['pg', 'mysql'].includes(this.config.database.client)) {
58-
result = result.filter((result) => result.distance === 0 || +result.distance > 0 && +result.distance > this.getDistance({ lat: result.latitude, lon: result.longitude }, { lat: data.latitude, lon: data.longitude }))
58+
result = result.filter((res) => res.distance=== 0 || +res.distance > 0 && +res.distance > this.getDistance({ lat: res.latitude, lon: res.longitude }, { lat: data.latitude, lon: data.longitude }))
5959
}
6060
result = this.returnByDatabaseType(result)
6161
const alertIds = []

src/lib/db/migrations/base.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
const log = require('../../logger')
22

3-
4-
exports.up = async function (knex) {
3+
exports.up = async function migrationUp(knex) {
54
await knex.schema.createTable('humans', (table) => {
65
table.string('id').primary().notNullable()
7-
table.string('type').notNullable
6+
table.string('type').notNullable()
87
table.string('name').notNullable()
98
table.boolean('enabled').notNullable().defaultTo(true)
109
table.text('area').notNullable().defaultTo('[]')
@@ -97,6 +96,6 @@ exports.up = async function (knex) {
9796
log.info('Base migration applied')
9897
}
9998

100-
exports.down = async function (knex) {
101-
99+
exports.down = async function migrationDown(knex) {
100+
log.info(knex)
102101
}

src/lib/discord/commando/commands/area.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ exports.run = async (client, msg, command) => {
99
return await msg.author.send(client.translator.translate('Please run commands in Direct Messages'))
1010
}
1111
let webhookName
12-
const webhookArray = command.find((args) => args.find((arg) => arg.match(client.re.nameRe)))
12+
const webhookArray = command.find((argss) => argss.find((arg) => arg.match(client.re.nameRe)))
1313
if (webhookArray) webhookName = webhookArray.find((arg) => arg.match(client.re.nameRe))
1414
if (webhookName) webhookName = webhookName.replace(client.translator.translate('name'), '')
1515
if (client.config.discord.admins.includes(msg.author.id) && msg.channel.type === 'text') target = { id: msg.channel.id, name: msg.channel.name, webhook: false }
16-
if (client.config.discord.admins.includes(msg.author.id) && webhookName) {
17-
target = { name: webhookName.replace(client.translator.translate('name'), ''), webhook: true }
18-
msg.content = msg.content.replace(client.hookRegex, '')
19-
}
16+
if (client.config.discord.admins.includes(msg.author.id) && webhookName) target = { name: webhookName.replace(client.translator.translate('name'), ''), webhook: true }
2017
for (let i = 0; i < args.length; i++) {
21-
if (args[i].match(/name\S+/gi)) arr.splice(i, 1)
18+
if (args[i].match(client.re.nameRe)) args.splice(i, 1)
2219
}
2320

2421
const isRegistered = target.webhook

src/lib/discord/commando/commands/location.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1-
exports.run = async (client, msg, [args]) => {
2-
const typeArray = Object.keys(client.utilData.types).map((o) => o.toLowerCase())
1+
exports.run = async (client, msg, command) => {
32
let target = { id: msg.author.id, name: msg.author.tag, webhook: false }
4-
3+
const [args] = command
54

65
try {
76
// Check target
87
if (!client.config.discord.admins.includes(msg.author.id) && msg.channel.type === 'text') {
98
return await msg.author.send(client.translator.translate('Please run commands in Direct Messages'))
109
}
1110
let webhookName
12-
const webhookArray = command.find((args) => args.find((arg) => arg.match(client.re.nameRe)))
11+
const webhookArray = command.find((argss) => argss.find((arg) => arg.match(client.re.nameRe)))
1312
if (webhookArray) webhookName = webhookArray.find((arg) => arg.match(client.re.nameRe))
1413
if (webhookName) webhookName = webhookName.replace(client.translator.translate('name'), '')
1514
if (client.config.discord.admins.includes(msg.author.id) && msg.channel.type === 'text') target = { id: msg.channel.id, name: msg.channel.name, webhook: false }
16-
if (client.config.discord.admins.includes(msg.author.id) && webhookName) {
17-
target = { name: webhookName.replace(client.translator.translate('name'), ''), webhook: true }
18-
msg.content = msg.content.replace(client.hookRegex, '')
19-
}
15+
if (client.config.discord.admins.includes(msg.author.id) && webhookName) target = { name: webhookName.replace(client.translator.translate('name'), ''), webhook: true }
2016
for (let i = 0; i < args.length; i++) {
21-
if (args[i].match(/name\S+/gi)) arr.splice(i, 1)
17+
if (args[i].match(client.re.nameRe)) args.splice(i, 1)
2218
}
2319
const search = args.join(' ')
2420

src/lib/discord/commando/commands/quest.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
exports.run = async (client, msg, command) => {
22
const typeArray = Object.keys(client.utilData.types).map((o) => o.toLowerCase())
33
let target = { id: msg.author.id, name: msg.author.tag, webhook: false }
4-
const [args] = command
54

65
try {
76
// Check target
@@ -13,10 +12,7 @@ exports.run = async (client, msg, command) => {
1312
if (webhookArray) webhookName = webhookArray.find((arg) => arg.match(client.re.nameRe))
1413
if (webhookName) webhookName = webhookName.replace(client.translator.translate('name'), '')
1514
if (client.config.discord.admins.includes(msg.author.id) && msg.channel.type === 'text') target = { id: msg.channel.id, name: msg.channel.name, webhook: false }
16-
if (client.config.discord.admins.includes(msg.author.id) && webhookName) {
17-
target = { name: webhookName.replace(client.translator.translate('name'), ''), webhook: true }
18-
msg.content = msg.content.replace(client.hookRegex, '')
19-
}
15+
if (client.config.discord.admins.includes(msg.author.id) && webhookName) target = { name: webhookName.replace(client.translator.translate('name'), ''), webhook: true }
2016
const isRegistered = target.webhook
2117
? await client.query.selectOneQuery('humans', { name: target.name, type: 'webhook' })
2218
: await client.query.countQuery('humans', { id: target.id })
@@ -37,7 +33,6 @@ exports.run = async (client, msg, command) => {
3733
const pings = [...msg.mentions.users.array().map((u) => `<@!${u.id}>`), ...msg.mentions.roles.array().map((r) => `<@&${r.id}>`)].join('')
3834
let monsters = []
3935
let fullMonsters = []
40-
const rawArgs = args.join(' ')
4136
let items = []
4237
let distance = 0
4338
const questTracks = []

src/lib/discord/commando/commands/raid.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ exports.run = async (client, msg, command) => {
1212
if (webhookArray) webhookName = webhookArray.find((arg) => arg.match(/name\S+/gi))
1313
if (webhookName) webhookName = webhookName.replace('name', '')
1414
if (client.config.discord.admins.includes(msg.author.id) && msg.channel.type === 'text') target = { id: msg.channel.id, name: msg.channel.name, webhook: false }
15-
if (client.config.discord.admins.includes(msg.author.id) && webhookName) {
16-
target = { name: webhookName.replace(/name/gi, ''), webhook: true }
17-
msg.content = msg.content.replace(client.hookRegex, '')
18-
}
15+
if (client.config.discord.admins.includes(msg.author.id) && webhookName) target = { name: webhookName.replace(/name/gi, ''), webhook: true }
1916

2017
const isRegistered = target.webhook
2118
? await client.query.selectOneQuery('humans', { name: target.name, type: 'webhook' })

src/lib/discord/commando/commands/template.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ exports.run = async (client, msg, command) => {
1212
if (webhookArray) webhookName = webhookArray.find((arg) => arg.match(client.re.nameRe))
1313
if (webhookName) webhookName = webhookName.replace(client.translator.translate('name'), '')
1414
if (client.config.discord.admins.includes(msg.author.id) && msg.channel.type === 'text') target = { id: msg.channel.id, name: msg.channel.name, webhook: false }
15-
if (client.config.discord.admins.includes(msg.author.id) && webhookName) {
16-
target = { name: webhookName.replace(client.translator.translate('name'), ''), webhook: true }
17-
msg.content = msg.content.replace(client.hookRegex, '')
18-
}
15+
if (client.config.discord.admins.includes(msg.author.id) && webhookName) target = { name: webhookName.replace(client.translator.translate('name'), ''), webhook: true }
1916
const isRegistered = target.webhook
2017
? await client.query.selectOneQuery('humans', { name: target.name, type: 'webhook' })
2118
: await client.query.countQuery('humans', { id: target.id })

src/lib/discord/commando/commands/track.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ exports.run = async (client, msg, command) => {
1212
if (webhookArray) webhookName = webhookArray.find((arg) => arg.match(client.re.nameRe))
1313
if (webhookName) webhookName = webhookName.replace(client.translator.translate('name'), '')
1414
if (client.config.discord.admins.includes(msg.author.id) && msg.channel.type === 'text') target = { id: msg.channel.id, name: msg.channel.name, webhook: false }
15-
if (client.config.discord.admins.includes(msg.author.id) && webhookName) {
16-
target = { name: webhookName.replace(client.translator.translate('name'), ''), webhook: true }
17-
msg.content = msg.content.replace(client.hookRegex, '')
18-
}
19-
15+
if (client.config.discord.admins.includes(msg.author.id) && webhookName) target = { name: webhookName.replace(client.translator.translate('name'), ''), webhook: true }
2016

2117
const isRegistered = target.webhook
2218
? await client.query.selectOneQuery('humans', { name: target.name, type: 'webhook' })
@@ -121,7 +117,7 @@ exports.run = async (client, msg, command) => {
121117
gender,
122118
clean,
123119
}))
124-
if (!insert.length) continue
120+
if (!insert.length) return
125121
const result = await client.query.insertOrUpdateQuery('monsters', insert)
126122
reaction = result.length || client.config.database.client === 'sqlite' ? '✅' : reaction
127123
}

src/lib/discord/commando/commands/tracked.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ exports.run = async (client, msg, [args]) => {
1515
if (webhookArray) webhookName = webhookArray.find((arg) => arg.match(client.re.nameRe))
1616
if (webhookName) webhookName = webhookName.replace(client.translator.translate('name'), '')
1717
if (client.config.discord.admins.includes(msg.author.id) && msg.channel.type === 'text') target = { id: msg.channel.id, name: msg.channel.name, webhook: false }
18-
if (client.config.discord.admins.includes(msg.author.id) && webhookName) {
19-
target = { name: webhookName.replace(client.translator.translate('name'), ''), webhook: true }
20-
msg.content = msg.content.replace(client.hookRegex, '')
21-
}
18+
if (client.config.discord.admins.includes(msg.author.id) && webhookName) target = { name: webhookName.replace(client.translator.translate('name'), ''), webhook: true }
19+
2220
const isRegistered = target.webhook
2321
? await client.query.selectOneQuery('humans', { name: target.name, type: 'webhook' })
2422
: await client.query.countQuery('humans', { id: target.id })
@@ -41,13 +39,12 @@ exports.run = async (client, msg, [args]) => {
4139
const quests = await client.query.selectAllQuery('quest', { id: target.id })
4240
const invasions = await client.query.selectAllQuery('invasion', { id: target.id })
4341
const maplink = `https://www.google.com/maps/search/?api=1&query=${human.latitude},${human.longitude}`
44-
let locationText = 'Y'
42+
let locationText = ''
4543
if (human.latitude !== 0 && human.longitude !== 0) {
4644
locationText = `Your location is currently set to ${maplink} \nand y`
4745
}
48-
msg.reply(`👋\n${locationText}ou are currently set to receive alarms in ${human.area}`).catch((O_o) => {
49-
client.log.error(O_o.message)
50-
})
46+
await msg.reply(`👋\n${locationText} You are currently set to receive alarms in ${human.area}`)
47+
5148
let message = ''
5249
if (monsters.length) {
5350
message = message.concat('\n\nYou\'re tracking the following monsters:\n')

src/lib/discord/commando/commands/untrack.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ exports.run = async (client, msg, command) => {
1010
return await msg.author.send(client.translator.translate('Please run commands in Direct Messages'))
1111
}
1212
let webhookName
13-
const webhookArray = command.find((args) => args.find((arg) => arg.match(client.re.nameRe)))
13+
const webhookArray = command.find((argss) => argss.find((arg) => arg.match(client.re.nameRe)))
1414
if (webhookArray) webhookName = webhookArray.find((arg) => arg.match(client.re.nameRe))
1515
if (webhookName) webhookName = webhookName.replace(client.translator.translate('name'), '')
1616
if (client.config.discord.admins.includes(msg.author.id) && msg.channel.type === 'text') target = { id: msg.channel.id, name: msg.channel.name, webhook: false }
1717
if (client.config.discord.admins.includes(msg.author.id) && webhookName) {
1818
target = { name: webhookName.replace(client.translator.translate('name'), ''), webhook: true }
19-
msg.content = msg.content.replace(client.hookRegex, '')
2019
}
2120
const isRegistered = target.webhook
2221
? await client.query.selectOneQuery('humans', { name: target.name, type: 'webhook' })
@@ -43,7 +42,11 @@ exports.run = async (client, msg, command) => {
4342
const monsterIds = monsters.map((mon) => mon.id)
4443
const result = await client.query.deleteWhereInQuery('monsters', target.id, monsterIds, 'pokemon_id')
4544

46-
result.length || client.config.database.client === 'sqlite' ? await msg.react('✅') : await msg.react('👌')
45+
if (result.length || client.config.database.client === 'sqlite') {
46+
msg.react('✅')
47+
} else {
48+
msg.react('👌')
49+
}
4750
} catch (err) {
4851
client.log.error('untrack command unhappy:', err)
4952
}

src/lib/discord/commando/events/guildMemberUpdate.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ module.exports = (client, oldMember, newMember) => {
44
let before = false
55
let after = false
66
oldMember.roles.forEach((role) => {
7-
if (role.name === client.config.discord.userRole) before = true
7+
if (client.config.discord.userRole.includes(role.name)) before = true
88
})
99
newMember.roles.forEach((role) => {
10-
if (role.name === client.config.discord.userRole) after = true
10+
if (client.config.discord.userRole.includes(role.name)) after = true
1111
})
1212

1313
if (!before && after) {
1414
client.query.countQuery('id', 'humans', 'id', oldMember.user.id)
1515
.then((isregistered) => {
1616
if (!isregistered) {
17-
client.query.insertOrUpdateQuery('humans', ['id', 'name', 'area'], [[oldMember.user.id, emojiStrip(oldMember.user.username), '[]']])
17+
client.query.insertOrUpdateQuery('humans', {
18+
id: oldMember.user.id, type: 'discord:user', name: client.emojiStrip(oldMember.user.username), area: '[]',
19+
})
1820
const view = { prefix: client.config.discord.prefix }
1921
const template = JSON.stringify(client.dts.greeting)
2022
const greeting = JSON.parse(mustache.render(template, view))

src/lib/discord/commando/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ module.exports = async (knex, config, log, monsterData, utilData, dts, geofence,
55
const re = require('../../../util/regex')(translator)
66

77
const { Client } = require('discord.js')
8-
const path = require('path')
98
const Enmap = require('enmap')
109
const fs = require('fs')
1110
const mustache = require('handlebars')

src/lib/discord/discordWorker.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class Worker {
6969
}
7070

7171
async userAlert(data) {
72-
7372
const user = this.client.users.get(data.job.target)
7473
if (!user) return this.log.warning(`user ${data.name} not found`)
7574
try {
@@ -78,11 +77,10 @@ class Worker {
7877
} catch (err) {
7978
throw this.log.error(`Failed to send Discord alert to ${data.name}, ${err.message}`)
8079
}
81-
8280
}
8381

84-
async webhookAlert(data) {
85-
82+
static async webhookAlert(firstData) {
83+
const data = firstData
8684
if (!data.target.match(hookRegex)) return this.log.warn(`Webhook, ${data.name} does not look like a link, exiting`)
8785
if (data.message.embed) data.message.embeds = [data.message.embed]
8886
try {
@@ -94,12 +92,10 @@ class Worker {
9492
} catch (err) {
9593
this.log.error(`Webhook ${data.name} failed with, ${err.message}`)
9694
}
97-
return
98-
9995
}
10096

101-
async channelAlert(data) {
102-
97+
static async channelAlert(data) {
98+
this.log.info(data)
10399
}
104100
}
105101

src/lib/discordWorker.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Worker {
1515
this.bounceWorker()
1616
}
1717

18-
async sleep(n) { return new Promise((resolve) => setTimeout(resolve, n)) }
18+
static sleep(n) { return new Promise((resolve) => setTimeout(resolve, n)) }
1919

2020
addUser(id) {
2121
this.users.push(id)
@@ -45,8 +45,8 @@ class Worker {
4545
await this.client.user.setStatus('invisible')
4646
} catch (err) {
4747
log.error(`Discord worker didn't bounce, \n ${err.message} \n trying again`)
48-
await this.sleep(2000)
49-
return await this.bounceWorker()
48+
this.sleep(2000)
49+
return this.bounceWorker()
5050
}
5151
}
5252

@@ -104,7 +104,8 @@ class Worker {
104104
return true
105105
}
106106

107-
async webhookAlert(data) {
107+
static async webhookAlert(firstData) {
108+
const data = firstData
108109
if (!data.target.match(hookRegex)) return log.warn(`Webhook, ${data.name} does not look like a link, exiting`)
109110
if (data.message.embed) data.message.embeds = [data.message.embed]
110111
try {

0 commit comments

Comments
 (0)