|
@@ -12,13 +12,13 @@ const Character = require('./character')
|
|
|
const Battle = require('./battle/battle')
|
|
|
const Move = require('./battle/move')
|
|
|
const Party = require('./character/party')
|
|
|
-const { DiscordAI } = require('./battle/ai')
|
|
|
+const {DiscordAI} = require('./battle/ai')
|
|
|
|
|
|
class Game {
|
|
|
|
|
|
async boot() {
|
|
|
|
|
|
- if (!await commandExists('gm')) {
|
|
|
+ if (!(await commandExists('gm'))) {
|
|
|
log.warning('GraphicsMagick not found - please install it')
|
|
|
}
|
|
|
|
|
@@ -29,46 +29,59 @@ class Game {
|
|
|
await camo.connect(config.get('database_uri'))
|
|
|
|
|
|
|
|
|
- this.clientPool = await Promise.all(config.get('discord_bot_tokens').map(async token => {
|
|
|
- const client = new discord.Client()
|
|
|
-
|
|
|
- try {
|
|
|
- await client.login(token)
|
|
|
- } catch (err) {
|
|
|
- log.critical('Bot login failure (is the token correct?)')
|
|
|
- return null
|
|
|
- }
|
|
|
+ this.clientPool = await Promise.all(
|
|
|
+ config.get('discord_bot_tokens').map(async token => {
|
|
|
+ const client = new discord.Client()
|
|
|
+
|
|
|
+ try {
|
|
|
+ await client.login(token)
|
|
|
+ } catch (err) {
|
|
|
+ log.critical('Bot login failure (is the token correct?)')
|
|
|
+ return null
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- let inAllGuilds = true
|
|
|
- const guildIDs = [
|
|
|
- config.get('discord_server_id'),
|
|
|
- ...config.get('discord_emote_store_server_ids'),
|
|
|
- ]
|
|
|
+
|
|
|
+ let inAllGuilds = true
|
|
|
+ const guildIDs = [
|
|
|
+ config.get('discord_server_id'),
|
|
|
+ ...config.get('discord_emote_store_server_ids'),
|
|
|
+ ]
|
|
|
|
|
|
- for (const guildID of guildIDs) {
|
|
|
- if (!client.guilds.get(guildID)) {
|
|
|
- inAllGuilds = false
|
|
|
+ for (const guildID of guildIDs) {
|
|
|
+ if (!client.guilds.get(guildID)) {
|
|
|
+ inAllGuilds = false
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- if (inAllGuilds) {
|
|
|
- log.ok(`Bot ${chalk.blue(client.user.tag)} logged in successfully`)
|
|
|
|
|
|
- return client
|
|
|
- } else {
|
|
|
- const url = `https://discordapp.com/oauth2/authorize?&client_id=${client.user.id}&scope=bot&permissions=${0x00000008}&response_type=code`
|
|
|
- log.warning(`Bot ${chalk.blue(client.user.tag)} not connected to configured Discord server(s) - add it using the following URL:\n${chalk.underline(url)}`)
|
|
|
- return null
|
|
|
- }
|
|
|
- })).then(pool => pool.filter(client => client !== null))
|
|
|
+ if (inAllGuilds) {
|
|
|
+ log.ok(`Bot ${chalk.blue(client.user.tag)} logged in successfully`)
|
|
|
+
|
|
|
+ return client
|
|
|
+ } else {
|
|
|
+ const url = `https://discordapp.com/oauth2/authorize?&client_id=${
|
|
|
+ client.user.id
|
|
|
+ }&scope=bot&permissions=${0x00000008}&response_type=code`
|
|
|
+ log.warning(
|
|
|
+ `Bot ${chalk.blue(
|
|
|
+ client.user.tag
|
|
|
+ )} not connected to configured Discord server(s) - add it using the following URL:\n${chalk.underline(
|
|
|
+ url
|
|
|
+ )}`
|
|
|
+ )
|
|
|
+ return null
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ).then(pool => pool.filter(client => client !== null))
|
|
|
|
|
|
if (this.clientPool.length === 0) {
|
|
|
throw 'No bots connected, cannot start'
|
|
|
}
|
|
|
|
|
|
|
|
|
- this.emoteStore = new EmoteStore(this, config.get('discord_emote_store_server_ids'))
|
|
|
+ this.emoteStore = new EmoteStore(
|
|
|
+ this,
|
|
|
+ config.get('discord_emote_store_server_ids')
|
|
|
+ )
|
|
|
|
|
|
if (config.get('skip_cleanup')) {
|
|
|
log.warning('Cleanup skipped')
|
|
@@ -78,65 +91,88 @@ class Game {
|
|
|
|
|
|
await Promise.all([
|
|
|
...this.guild.channels
|
|
|
- .filter(chnl =>
|
|
|
- chnl.id !== this.guild.id &&
|
|
|
- !config.get('protected_ids').includes(chnl.id))
|
|
|
+ .filter(
|
|
|
+ chnl =>
|
|
|
+ chnl.id !== this.guild.id &&
|
|
|
+ !config.get('protected_ids').includes(chnl.id)
|
|
|
+ )
|
|
|
.map(chnl => {
|
|
|
log.info(`Deleted channel ${chalk.red(`#${chnl.name}`)}`)
|
|
|
return chnl.delete()
|
|
|
}),
|
|
|
|
|
|
...this.guild.roles
|
|
|
- .filter(role =>
|
|
|
- role.id !== this.guild.id &&
|
|
|
- !config.get('protected_ids').includes(role.id))
|
|
|
+ .filter(
|
|
|
+ role =>
|
|
|
+ role.id !== this.guild.id &&
|
|
|
+ !config.get('protected_ids').includes(role.id)
|
|
|
+ )
|
|
|
.map(role => {
|
|
|
log.info(`Deleted role ${chalk.red(role.name)}`)
|
|
|
return role.delete()
|
|
|
- })
|
|
|
+ }),
|
|
|
])
|
|
|
|
|
|
log.info(chalk.red('Cleanup complete.'))
|
|
|
}
|
|
|
|
|
|
|
|
|
- const pokeMove = await Move.upsert('👉', 'Poke', 'Deals a tiny amount of damage to a single enemy.', {
|
|
|
- target: 'enemy',
|
|
|
- actions: [{type: 'damage', data: {amount: 2}, to: 'target'}],
|
|
|
- })
|
|
|
-
|
|
|
- const kissMove = await Move.upsert('💋', 'Kiss', 'Heals a party member by a tiny amount.', {
|
|
|
- target: 'party',
|
|
|
- actions: [{type: 'heal', data: {amount: 3}, to: 'target'}],
|
|
|
- basePrepareTicks: 1,
|
|
|
- })
|
|
|
-
|
|
|
- const multipokeMove = await Move.upsert('👏', 'Multipoke', 'Deals a tiny amount of damage to up to three enemies at once.', {
|
|
|
- target: Move.TargetDesc.of('enemy', 3),
|
|
|
- actions: [{type: 'damage', data: {amount: 2}, to: 'target'}],
|
|
|
- baseCooldownTicks: 2,
|
|
|
- })
|
|
|
+ const pokeMove = await Move.upsert(
|
|
|
+ '👉',
|
|
|
+ 'Poke',
|
|
|
+ 'Deals a tiny amount of damage to a single enemy.',
|
|
|
+ {
|
|
|
+ target: 'enemy',
|
|
|
+ actions: [{type: 'damage', data: {amount: 2}, to: 'target'}],
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ const kissMove = await Move.upsert(
|
|
|
+ '💋',
|
|
|
+ 'Kiss',
|
|
|
+ 'Heals a party member by a tiny amount.',
|
|
|
+ {
|
|
|
+ target: 'party',
|
|
|
+ actions: [{type: 'heal', data: {amount: 3}, to: 'target'}],
|
|
|
+ basePrepareTicks: 1,
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ const multipokeMove = await Move.upsert(
|
|
|
+ '👏',
|
|
|
+ 'Multipoke',
|
|
|
+ 'Deals a tiny amount of damage to up to three enemies at once.',
|
|
|
+ {
|
|
|
+ target: Move.TargetDesc.of('enemy', 3),
|
|
|
+ actions: [{type: 'damage', data: {amount: 2}, to: 'target'}],
|
|
|
+ baseCooldownTicks: 2,
|
|
|
+ }
|
|
|
+ )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- await Promise.all(this.guild.members.filter(m => !m.user.bot).map(async member => {
|
|
|
- let char = await Character.findOne({discordID: member.id})
|
|
|
-
|
|
|
- if (!char) {
|
|
|
- char = await Character.create({
|
|
|
- discordID: member.id,
|
|
|
- battleAI: 'DiscordAI',
|
|
|
- moveIDs: [pokeMove._id, multipokeMove._id, kissMove._id],
|
|
|
- }).save()
|
|
|
-
|
|
|
- log.info(`Created player data for new user ${chalk.blue(member.user.tag)}`)
|
|
|
-
|
|
|
- await char.healthUpdate(this.guild)
|
|
|
- }
|
|
|
- }))
|
|
|
+ await Promise.all(
|
|
|
+ this.guild.members.filter(m => !m.user.bot).map(async member => {
|
|
|
+ let char = await Character.findOne({discordID: member.id})
|
|
|
+
|
|
|
+ if (!char) {
|
|
|
+ char = await Character.create({
|
|
|
+ discordID: member.id,
|
|
|
+ battleAI: 'DiscordAI',
|
|
|
+ moveIDs: [pokeMove._id, multipokeMove._id, kissMove._id],
|
|
|
+ }).save()
|
|
|
+
|
|
|
+ log.info(
|
|
|
+ `Created player data for new user ${chalk.blue(member.user.tag)}`
|
|
|
+ )
|
|
|
+
|
|
|
+ await char.healthUpdate(this.guild)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ )
|
|
|
|
|
|
|
|
|
this.clientPool[0].on('message', async msg => {
|
|
@@ -154,10 +190,17 @@ class Game {
|
|
|
|
|
|
|
|
|
|
|
|
- const characters = await Promise.all(msg.mentions.users.map(user => Character.findOne({discordID: user.id})))
|
|
|
+ const characters = await Promise.all(
|
|
|
+ msg.mentions.users.map(user =>
|
|
|
+ Character.findOne({discordID: user.id})
|
|
|
+ )
|
|
|
+ )
|
|
|
|
|
|
const parties = _.uniq([
|
|
|
- await self.getParty(), ...await Promise.all(characters.map(character => character && character.getParty()))
|
|
|
+ await self.getParty(),
|
|
|
+ ...(await Promise.all(
|
|
|
+ characters.map(character => character && character.getParty())
|
|
|
+ )),
|
|
|
])
|
|
|
|
|
|
for (const party of parties) {
|
|
@@ -183,7 +226,7 @@ class Game {
|
|
|
|
|
|
|
|
|
if (msg.content.startsWith('.emote ')) {
|
|
|
- for (const [ userID, user ] of msg.mentions.users) {
|
|
|
+ for (const [userID, user] of msg.mentions.users) {
|
|
|
const char = await Character.findOne({discordID: userID})
|
|
|
const emote = await char.getEmote(this)
|
|
|
|
|
@@ -202,7 +245,7 @@ class Game {
|
|
|
...msg.mentions.users,
|
|
|
]
|
|
|
|
|
|
- for (const [ id, mentioned ] of mentions) {
|
|
|
+ for (const [id, mentioned] of mentions) {
|
|
|
const name = mentioned.name || mentioned.username
|
|
|
|
|
|
await msg.channel.send(`**${name}**: \`${id}\``)
|
|
@@ -219,7 +262,8 @@ class Game {
|
|
|
|
|
|
const game = new Game()
|
|
|
|
|
|
-game.boot()
|
|
|
+game
|
|
|
+ .boot()
|
|
|
.then(() => log.ok('Game started'))
|
|
|
.catch(err => {
|
|
|
|