#19 Add prettier

Zamknięty
alex chce scalić 2 commity/ów z alex/prettier do alex/master

+ 34 - 21
core/battle/ai.js

@@ -21,14 +21,20 @@ class AI {
 class DiscordAI extends AI {
 class DiscordAI extends AI {
   async moveChoice() {
   async moveChoice() {
     // Move
     // Move
-    const moves = await Promise.all(this.char.moveIDs.map(id => Move.findOne({_id: id})))
+    const moves = await Promise.all(
+      this.char.moveIDs.map(id => Move.findOne({_id: id}))
+    )
 
 
-    const { move } = await prompt({
+    const {move} = await prompt({
       channel: this.team.channel,
       channel: this.team.channel,
       user: this.char,
       user: this.char,
       title: this.char.getName(this.battle.game.guild),
       title: this.char.getName(this.battle.game.guild),
       description: 'Next move:',
       description: 'Next move:',
-      choices: moves.map(move => ({emote: move.emote, name: `**${move.name}** - ${move.description}`, move}))
+      choices: moves.map(move => ({
+        emote: move.emote,
+        name: `**${move.name}** - ${move.description}`,
+        move,
+      })),
     })
     })
 
 
     // Target(s)
     // Target(s)
@@ -37,41 +43,47 @@ class DiscordAI extends AI {
     if (move.target.numberMin === 1 && move.target.numberMax > 1) {
     if (move.target.numberMin === 1 && move.target.numberMax > 1) {
       targetPromptDesc += ` (pick up to ${move.target.numberMax})`
       targetPromptDesc += ` (pick up to ${move.target.numberMax})`
     } else if (move.target.numberMax > move.target.numberMin) {
     } else if (move.target.numberMax > move.target.numberMin) {
-      targetPromptDesc += ` (pick ${move.target.numberMin} - ${move.target.numberMax})`
+      targetPromptDesc += ` (pick ${move.target.numberMin} - ${
+        move.target.numberMax
+      })`
     }
     }
 
 
     let targetable
     let targetable
     switch (move.target.type) {
     switch (move.target.type) {
       // Only yourself.
       // Only yourself.
       case 'self':
       case 'self':
-      targetable = [this.char]
-      break
+        targetable = [this.char]
+        break
 
 
       // Everyone in your party but yourself.
       // Everyone in your party but yourself.
       case 'party':
       case 'party':
-      targetable = this.team.party.members
-        .filter(m => m.discordID !== this.char.discordID)
-      break
+        targetable = this.team.party.members.filter(
+          m => m.discordID !== this.char.discordID
+        )
+        break
 
 
       // Anyone in a different party (ie. hostile),
       // Anyone in a different party (ie. hostile),
       case 'enemy':
       case 'enemy':
-      targetable = _.flatten(this.battle.teams
-        .map(({ party }) => party)
-        .filter(party => party._id !== this.team.party._id)
-        .map(party => party.members))
-      break
+        targetable = _.flatten(
+          this.battle.teams
+            .map(({party}) => party)
+            .filter(party => party._id !== this.team.party._id)
+            .map(party => party.members)
+        )
+        break
 
 
       // Anyone else in the battle.
       // Anyone else in the battle.
       case 'any':
       case 'any':
-      targetable = this.battle.everyone
-        .filter(m => m._id !== this.char._id)
-      break
+        targetable = this.battle.everyone.filter(m => m._id !== this.char._id)
+        break
     }
     }
 
 
     /*if (targetable.length === 1) {
     /*if (targetable.length === 1) {
       // Only one character can be targeted, so just choose them.
       // Only one character can be targeted, so just choose them.
       return {move, targets: targetable}
       return {move, targets: targetable}
-    } else */if (targetable.length === 0) {
+    } else */ if (
+      targetable.length === 0
+    ) {
       // No-one can be targeted, so ask for a different move choice.
       // No-one can be targeted, so ask for a different move choice.
       // TODO: handle this case better?
       // TODO: handle this case better?
       const msg = await this.team.channel.send('No targets for that move!')
       const msg = await this.team.channel.send('No targets for that move!')
@@ -88,12 +100,13 @@ class DiscordAI extends AI {
       user: this.char,
       user: this.char,
       title: this.char.getName(this.battle.game.guild),
       title: this.char.getName(this.battle.game.guild),
       description: targetPromptDesc,
       description: targetPromptDesc,
-      choices: await Promise.all(targetable
-        .map(async (char, i) => ({
+      choices: await Promise.all(
+        targetable.map(async (char, i) => ({
           emote: await char.getEmote(this.battle.game),
           emote: await char.getEmote(this.battle.game),
           name: char.getName(this.battle.game.guild),
           name: char.getName(this.battle.game.guild),
           char,
           char,
-        }))),
+        }))
+      ),
       chooseMin: move.target.numberMin,
       chooseMin: move.target.numberMin,
       chooseMax: move.target.numberMax,
       chooseMax: move.target.numberMax,
     })
     })

+ 25 - 19
core/battle/index.js

@@ -20,7 +20,7 @@ class Battle {
       {id: everyoneRole, deny: 3136, allow: 0}, // -rw -react
       {id: everyoneRole, deny: 3136, allow: 0}, // -rw -react
       ...party.members.filter(char => char.discordID).map(char => {
       ...party.members.filter(char => char.discordID).map(char => {
         return {id: char.discordID, deny: 0, allow: 3072} // +rw
         return {id: char.discordID, deny: 0, allow: 3072} // +rw
-      })
+      }),
     ])
     ])
 
 
     for (const char of party.members) {
     for (const char of party.members) {
@@ -66,9 +66,11 @@ class Battle {
         // TODO: use speed stat when next === 'choice'
         // TODO: use speed stat when next === 'choice'
       } else if (char._battle.next === 'choice') {
       } else if (char._battle.next === 'choice') {
         // Decision time!
         // Decision time!
-        const { move, targets } = await char._battle.ai.moveChoice(char, this)
+        const {move, targets} = await char._battle.ai.moveChoice(char, this)
 
 
-        await this.sendMessageToAll(`${characterLabel} is preparing to use _${move.name}_...`)
+        await this.sendMessageToAll(
+          `${characterLabel} is preparing to use _${move.name}_...`
+        )
 
 
         Object.assign(char._battle, {
         Object.assign(char._battle, {
           next: 'action',
           next: 'action',
@@ -78,9 +80,11 @@ class Battle {
         })
         })
       } else if (char._battle.next === 'action') {
       } else if (char._battle.next === 'action') {
         // Perform the move.
         // Perform the move.
-        const { moveChosen, targetsChosen } = char._battle
+        const {moveChosen, targetsChosen} = char._battle
 
 
-        await this.sendMessageToAll(`${characterLabel} used _${moveChosen.name}_!`)
+        await this.sendMessageToAll(
+          `${characterLabel} used _${moveChosen.name}_!`
+        )
 
 
         for (const target of targetsChosen) {
         for (const target of targetsChosen) {
           await moveChosen.performOn(target, char, this)
           await moveChosen.performOn(target, char, this)
@@ -118,22 +122,22 @@ class Battle {
 
 
   // Every character of every team, in a one-dimensional array.
   // Every character of every team, in a one-dimensional array.
   get everyone() {
   get everyone() {
-    return _.flatten(this.teams.map(({ party }) => party.members))
+    return _.flatten(this.teams.map(({party}) => party.members))
   }
   }
 
 
   // Helper function for sending a message to all team channels.
   // Helper function for sending a message to all team channels.
   sendMessageToAll(msg) {
   sendMessageToAll(msg) {
-    return Promise.all(this.teams.map(team =>
-      team.channel.send(msg)
-    ))
+    return Promise.all(this.teams.map(team => team.channel.send(msg)))
   }
   }
 
 
   // Returns the battle channel for the passed character's team.
   // Returns the battle channel for the passed character's team.
   channelOf(char) {
   channelOf(char) {
-    for (const { party, channel } of this.teams) {
-      if (party.members.find(mem => {
-        return mem.discordID === char.discordID
-      })) {
+    for (const {party, channel} of this.teams) {
+      if (
+        party.members.find(mem => {
+          return mem.discordID === char.discordID
+        })
+      ) {
         return channel
         return channel
       }
       }
     }
     }
@@ -149,13 +153,15 @@ class Battle {
 
 
   // A battle is "complete" if every team but one has 0 HP left.
   // A battle is "complete" if every team but one has 0 HP left.
   async isComplete() {
   async isComplete() {
-    return this.teams.filter(({ party }) => {
-      for (const char of party.members) {
-        if (char.health > 0) return true // Alive member
-      }
+    return (
+      this.teams.filter(({party}) => {
+        for (const char of party.members) {
+          if (char.health > 0) return true // Alive member
+        }
 
 
-      return false // Entire team is dead :(
-    }).length <= 1
+        return false // Entire team is dead :(
+      }).length <= 1
+    )
   }
   }
 }
 }
 
 

+ 32 - 13
core/battle/move.js

@@ -1,4 +1,4 @@
-const { Document, EmbeddedDocument } = require('camo')
+const {Document, EmbeddedDocument} = require('camo')
 
 
 class Move extends Document {
 class Move extends Document {
   constructor() {
   constructor() {
@@ -28,8 +28,11 @@ class Move extends Document {
 
 
       if (action.type === 'damage') {
       if (action.type === 'damage') {
         // TODO defense stat, etc
         // TODO defense stat, etc
-        const { amount } = action.data
-        const healthState = await actionTarget.modHealth(-amount, battle.game.guild)
+        const {amount} = action.data
+        const healthState = await actionTarget.modHealth(
+          -amount,
+          battle.game.guild
+        )
 
 
         if (healthState === 'dead') {
         if (healthState === 'dead') {
           await battle.sendMessageToAll(`${targetLabel} died.`)
           await battle.sendMessageToAll(`${targetLabel} died.`)
@@ -37,15 +40,21 @@ class Move extends Document {
           await battle.sendMessageToAll(`${targetLabel} took ${amount} damage.`)
           await battle.sendMessageToAll(`${targetLabel} took ${amount} damage.`)
         }
         }
       } else if (action.type === 'heal') {
       } else if (action.type === 'heal') {
-        const { amount } = action.data
+        const {amount} = action.data
 
 
         if (actionTarget.healthState === 'dead') {
         if (actionTarget.healthState === 'dead') {
-          await battle.sendMessageToAll(`${targetLabel} is dead and cannot be healed normally.`)
+          await battle.sendMessageToAll(
+            `${targetLabel} is dead and cannot be healed normally.`
+          )
         } else if (actionTarget.healthState === 'healthy') {
         } else if (actionTarget.healthState === 'healthy') {
-          await battle.sendMessageToAll(`${targetLabel} is already at max health.`)
+          await battle.sendMessageToAll(
+            `${targetLabel} is already at max health.`
+          )
         } else {
         } else {
           await actionTarget.modHealth(+amount, battle.game.guild)
           await actionTarget.modHealth(+amount, battle.game.guild)
-          await battle.sendMessageToAll(`${targetLabel} recovered ${amount} health.`)
+          await battle.sendMessageToAll(
+            `${targetLabel} recovered ${amount} health.`
+          )
         }
         }
       } else {
       } else {
         throw 'Unknown action descriptor type: ' + action.type
         throw 'Unknown action descriptor type: ' + action.type
@@ -54,17 +63,27 @@ class Move extends Document {
   }
   }
 
 
   // Creates a new move, or re-uses if one with the same name is already found.
   // Creates a new move, or re-uses if one with the same name is already found.
-  static async upsert(emote, name, description, {target, actions=[], basePrepareTicks, baseCooldownTicks}={}) {
+  static async upsert(
+    emote,
+    name,
+    description,
+    {target, actions = [], basePrepareTicks, baseCooldownTicks} = {}
+  ) {
     const existing = await Move.findOne({name})
     const existing = await Move.findOne({name})
 
 
     if (existing) {
     if (existing) {
       return existing
       return existing
     } else {
     } else {
       const move = Move.create({
       const move = Move.create({
-        name, description, emote,
-        basePrepareTicks, baseCooldownTicks,
+        name,
+        description,
+        emote,
+        basePrepareTicks,
+        baseCooldownTicks,
         target: target instanceof TargetDesc ? target : TargetDesc.of(target),
         target: target instanceof TargetDesc ? target : TargetDesc.of(target),
-        actions: actions.map(a => a instanceof ActionDesc ? a : ActionDesc.create(a)),
+        actions: actions.map(
+          a => (a instanceof ActionDesc ? a : ActionDesc.create(a))
+        ),
       })
       })
 
 
       return move.save()
       return move.save()
@@ -87,7 +106,7 @@ class TargetDesc extends EmbeddedDocument {
     })
     })
   }
   }
 
 
-  static of(type, numberMin=1, numberMax) {
+  static of(type, numberMin = 1, numberMax) {
     if (numberMax === undefined) {
     if (numberMax === undefined) {
       // 'Up to'
       // 'Up to'
       numberMax = numberMin
       numberMax = numberMin
@@ -107,7 +126,7 @@ class ActionDesc extends EmbeddedDocument {
     this.schema({
     this.schema({
       type: {type: String, required: true, choice: ['damage', 'heal']},
       type: {type: String, required: true, choice: ['damage', 'heal']},
       data: Object, // Depending on type
       data: Object, // Depending on type
-      to: {type: String, required: 'target', choice: ['user', 'target']}
+      to: {type: String, required: 'target', choice: ['user', 'target']},
       //condition: ConditionDesc,
       //condition: ConditionDesc,
     })
     })
   }
   }

+ 22 - 15
core/character/index.js

@@ -1,4 +1,4 @@
-const { Document } = require('camo')
+const {Document} = require('camo')
 const battleAIs = require('../battle/ai')
 const battleAIs = require('../battle/ai')
 const Move = require('../battle/move')
 const Move = require('../battle/move')
 const log = require('../util/log')
 const log = require('../util/log')
@@ -11,7 +11,8 @@ const tinycolor = require('tinycolor2')
 const healthGradient = tinygradient(['#BA0020', '#ffbf00', '#77dd77'])
 const healthGradient = tinygradient(['#BA0020', '#ffbf00', '#77dd77'])
 const colorDead = '#36454f'
 const colorDead = '#36454f'
 
 
-const BACKUP_AVATAR_URL = 'https://discordapp.com/assets/6debd47ed13483642cf09e832ed0bc1b.png'
+const BACKUP_AVATAR_URL =
+  'https://discordapp.com/assets/6debd47ed13483642cf09e832ed0bc1b.png'
 
 
 // A Character refers to both a player and an enemy. The difference is in
 // A Character refers to both a player and an enemy. The difference is in
 // their `ai` that controls their actions (for players, this is DiscordAI).
 // their `ai` that controls their actions (for players, this is DiscordAI).
@@ -41,7 +42,7 @@ class Character extends Document {
     this.health += by
     this.health += by
 
 
     if (this.health > this.maxHealth) this.health = this.maxHealth
     if (this.health > this.maxHealth) this.health = this.maxHealth
-    if (this.health < 0)              this.health = 0
+    if (this.health < 0) this.health = 0
 
 
     if (guild) await this.healthUpdate(guild)
     if (guild) await this.healthUpdate(guild)
 
 
@@ -55,27 +56,33 @@ class Character extends Document {
     const member = guild.members.get(this.discordID)
     const member = guild.members.get(this.discordID)
 
 
     // Remove existing health role, if any
     // Remove existing health role, if any
-    const roleExisting = member.roles.find(role => role.name.endsWith(' health'))
+    const roleExisting = member.roles.find(role =>
+      role.name.endsWith(' health')
+    )
     if (roleExisting) await roleExisting.delete()
     if (roleExisting) await roleExisting.delete()
 
 
     // Reuse/create a health role and grant it
     // Reuse/create a health role and grant it
     const roleName = `${this.health}/${this.maxHealth} health`
     const roleName = `${this.health}/${this.maxHealth} health`
-    const role = member.roles.find(role => role.name === roleName)
-      || await guild.createRole({
+    const role =
+      member.roles.find(role => role.name === roleName) ||
+      (await guild.createRole({
         name: roleName,
         name: roleName,
-        color: this.health === 0
-          ? colorDead
-          : tinycolor(healthGradient.rgbAt(this.health / this.maxHealth)).toHexString()
-      })
+        color:
+          this.health === 0
+            ? colorDead
+            : tinycolor(
+                healthGradient.rgbAt(this.health / this.maxHealth)
+              ).toHexString(),
+      }))
 
 
     await member.addRole(role)
     await member.addRole(role)
   }
   }
 
 
   get healthState() {
   get healthState() {
     if (this.health === this.maxHealth) return 'healthy'
     if (this.health === this.maxHealth) return 'healthy'
-    else if (this.health === 1)         return 'peril'
-    else if (this.health === 0)         return 'dead'
-    else                                return 'injured'
+    else if (this.health === 1) return 'peril'
+    else if (this.health === 0) return 'dead'
+    else return 'injured'
   }
   }
 
 
   getName(guild) {
   getName(guild) {
@@ -107,7 +114,7 @@ class Character extends Document {
     const member = await game.guild.members.get(this.discordID)
     const member = await game.guild.members.get(this.discordID)
     await member.addRole(role)
     await member.addRole(role)
 
 
-    return this._discordRole = role
+    return (this._discordRole = role)
   }
   }
 
 
   // Returns a little icon emote based on the character's avatar.
   // Returns a little icon emote based on the character's avatar.
@@ -145,7 +152,7 @@ class Character extends Document {
       party = await Party.of([this])
       party = await Party.of([this])
     }
     }
 
 
-    return party || await Party.findOne({_id: this.partyID})
+    return party || (await Party.findOne({_id: this.partyID}))
   }
   }
 }
 }
 
 

+ 2 - 2
core/character/party.js

@@ -1,4 +1,4 @@
-const { Document } = require('camo')
+const {Document} = require('camo')
 const Character = require('./character')
 const Character = require('./character')
 
 
 const tinycolor = require('tinycolor2')
 const tinycolor = require('tinycolor2')
@@ -87,7 +87,7 @@ class Party extends Document {
   static async of(characters) {
   static async of(characters) {
     const party = this.create({
     const party = this.create({
       characters: [],
       characters: [],
-      colorHue: Math.random()
+      colorHue: Math.random(),
     })
     })
 
 
     for (const character of characters) {
     for (const character of characters) {

+ 21 - 9
core/config.js

@@ -5,11 +5,10 @@ const typecheck = require('./util/typecheck')
 
 
 class Config {
 class Config {
   async load() {
   async load() {
-    const jsonStr = await fs.readFile('config.json', 'utf8')
-      .catch(err => {
-        // Make the error more human-friendly
-        return Promise.reject('Could not read config.json file')
-      })
+    const jsonStr = await fs.readFile('config.json', 'utf8').catch(err => {
+      // Make the error more human-friendly
+      return Promise.reject('Could not read config.json file')
+    })
 
 
     try {
     try {
       this.obj = json.parse(jsonStr)
       this.obj = json.parse(jsonStr)
@@ -20,11 +19,24 @@ class Config {
     // Sanitize
     // Sanitize
     try {
     try {
       typecheck(this.obj.database_uri, {type: String}, 'for database_uri')
       typecheck(this.obj.database_uri, {type: String}, 'for database_uri')
-      typecheck(this.obj.discord_server_id, {type: String}, 'for discord_server_id')
-      typecheck(this.obj.discord_emote_store_server_ids, {type: Array}, 'for discord_emote_store_server_ids')
-      typecheck(this.obj.discord_bot_tokens, {type: Array}, 'for discord_bot_tokens')
+      typecheck(
+        this.obj.discord_server_id,
+        {type: String},
+        'for discord_server_id'
+      )
+      typecheck(
+        this.obj.discord_emote_store_server_ids,
+        {type: Array},
+        'for discord_emote_store_server_ids'
+      )
+      typecheck(
+        this.obj.discord_bot_tokens,
+        {type: Array},
+        'for discord_bot_tokens'
+      )
       typecheck(this.obj.protected_ids, {type: Array}, 'for protected_ids')
       typecheck(this.obj.protected_ids, {type: Array}, 'for protected_ids')
-      if (this.obj.protected_ids.length === 0) throw new TypeError('Please add at least one ID to protected_ids')
+      if (this.obj.protected_ids.length === 0)
+        throw new TypeError('Please add at least one ID to protected_ids')
       typecheck(this.obj.skip_cleanup, {type: Boolean}, 'for skip_cleanup')
       typecheck(this.obj.skip_cleanup, {type: Boolean}, 'for skip_cleanup')
     } catch (err) {
     } catch (err) {
       throw 'Error in config.json:\n' + err.message // It's human-readable!
       throw 'Error in config.json:\n' + err.message // It's human-readable!

+ 119 - 75
core/game.js

@@ -12,13 +12,13 @@ const Character = require('./character')
 const Battle = require('./battle/battle')
 const Battle = require('./battle/battle')
 const Move = require('./battle/move')
 const Move = require('./battle/move')
 const Party = require('./character/party')
 const Party = require('./character/party')
-const { DiscordAI } = require('./battle/ai')
+const {DiscordAI} = require('./battle/ai')
 
 
 class Game {
 class Game {
   // Starts the game. Should only run once per process!
   // Starts the game. Should only run once per process!
   async boot() {
   async boot() {
     // Check graphicsmagick is installed
     // Check graphicsmagick is installed
-    if (!await commandExists('gm')) {
+    if (!(await commandExists('gm'))) {
       log.warning('GraphicsMagick not found - please install it')
       log.warning('GraphicsMagick not found - please install it')
     }
     }
 
 
@@ -29,46 +29,59 @@ class Game {
     await camo.connect(config.get('database_uri'))
     await camo.connect(config.get('database_uri'))
 
 
     // Create the bot pool
     // Create the bot pool
-    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
+        }
 
 
-      // Check the bot is actually in all the guilds (servers) we will be using
-      let inAllGuilds = true
-      const guildIDs = [
-        config.get('discord_server_id'),
-        ...config.get('discord_emote_store_server_ids'),
-      ]
+        // Check the bot is actually in all the guilds (servers) we will be using
+        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) {
     if (this.clientPool.length === 0) {
       throw 'No bots connected, cannot start'
       throw 'No bots connected, cannot start'
     }
     }
 
 
     // Setup stores
     // Setup stores
-    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')) {
     if (config.get('skip_cleanup')) {
       log.warning('Cleanup skipped')
       log.warning('Cleanup skipped')
@@ -78,65 +91,88 @@ class Game {
 
 
       await Promise.all([
       await Promise.all([
         ...this.guild.channels
         ...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 => {
           .map(chnl => {
             log.info(`Deleted channel ${chalk.red(`#${chnl.name}`)}`)
             log.info(`Deleted channel ${chalk.red(`#${chnl.name}`)}`)
             return chnl.delete()
             return chnl.delete()
           }),
           }),
 
 
         ...this.guild.roles
         ...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 => {
           .map(role => {
             log.info(`Deleted role ${chalk.red(role.name)}`)
             log.info(`Deleted role ${chalk.red(role.name)}`)
             return role.delete()
             return role.delete()
-          })
+          }),
       ])
       ])
 
 
       log.info(chalk.red('Cleanup complete.'))
       log.info(chalk.red('Cleanup complete.'))
     }
     }
 
 
     // TEMP: Create a couple moves to give to new characters.
     // TEMP: Create a couple moves to give to new characters.
-    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,
+      }
+    )
 
 
     // Add all players to the database (if they don't exist already)
     // Add all players to the database (if they don't exist already)
     // This could take a while on large servers
     // This could take a while on large servers
     //
     //
     // TODO: add new users (memberadd event) as characters when they join if the
     // TODO: add new users (memberadd event) as characters when they join if the
     // server is already running
     // server is already running
-    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)
+        }
+      })
+    )
 
 
     // TEMP
     // TEMP
     this.clientPool[0].on('message', async msg => {
     this.clientPool[0].on('message', async msg => {
@@ -154,10 +190,17 @@ class Game {
         // FIXME: this crashes if the battle starts off completed (eg. one team
         // FIXME: this crashes if the battle starts off completed (eg. one team
         // is comprised of only dead players).
         // is comprised of only dead players).
 
 
-        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([
         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) {
         for (const party of parties) {
@@ -183,7 +226,7 @@ class Game {
 
 
       // Usage: .emote @user#0001 @user#0002 [...]
       // Usage: .emote @user#0001 @user#0002 [...]
       if (msg.content.startsWith('.emote ')) {
       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 char = await Character.findOne({discordID: userID})
           const emote = await char.getEmote(this)
           const emote = await char.getEmote(this)
 
 
@@ -202,7 +245,7 @@ class Game {
           ...msg.mentions.users,
           ...msg.mentions.users,
         ]
         ]
 
 
-        for (const [ id, mentioned ] of mentions) {
+        for (const [id, mentioned] of mentions) {
           const name = mentioned.name || mentioned.username
           const name = mentioned.name || mentioned.username
 
 
           await msg.channel.send(`**${name}**: \`${id}\``)
           await msg.channel.send(`**${name}**: \`${id}\``)
@@ -219,7 +262,8 @@ class Game {
 // Let's go!!
 // Let's go!!
 const game = new Game()
 const game = new Game()
 
 
-game.boot()
+game
+  .boot()
   .then(() => log.ok('Game started'))
   .then(() => log.ok('Game started'))
   .catch(err => {
   .catch(err => {
     // :(
     // :(

+ 7 - 7
core/graphics/graphicbar.js

@@ -9,24 +9,24 @@ module.exports = {
       .tile(maxLength)
       .tile(maxLength)
       .transparent('white')
       .transparent('white')
 
 
-    if (value > 0) { 
-      bar.montage(path + 'bar-full-left.png') 
+    if (value > 0) {
+      bar.montage(path + 'bar-full-left.png')
     } else {
     } else {
-      bar.montage(path + 'bar-empty-left.png') 
+      bar.montage(path + 'bar-empty-left.png')
     }
     }
 
 
     for (let i = 0; i < maxLength - 2; i++) {
     for (let i = 0; i < maxLength - 2; i++) {
       if (i <= value - 2) {
       if (i <= value - 2) {
-        bar.montage(path + 'bar-full-mid.png') 
+        bar.montage(path + 'bar-full-mid.png')
       } else {
       } else {
-        bar.montage(path + 'bar-empty-mid.png') 
+        bar.montage(path + 'bar-empty-mid.png')
       }
       }
     }
     }
 
 
     if (maxLength <= value) {
     if (maxLength <= value) {
-      bar.montage(path + 'bar-full-right.png')  
+      bar.montage(path + 'bar-full-right.png')
     } else {
     } else {
-      bar.montage(path + 'bar-empty-right.png')  
+      bar.montage(path + 'bar-empty-right.png')
     }
     }
 
 
     return bar.stream('PNG')
     return bar.stream('PNG')

+ 13 - 9
core/stores/emote.js

@@ -11,7 +11,9 @@ class EmoteStore {
     this.emotes = new Map() // id -> Emoji
     this.emotes = new Map() // id -> Emoji
     this.mutex = new Mutex()
     this.mutex = new Mutex()
 
 
-    log.info(`Emote store capacity = ${this.guildIDs.length * MAX_EMOTES_IN_GUILD}`)
+    log.info(
+      `Emote store capacity = ${this.guildIDs.length * MAX_EMOTES_IN_GUILD}`
+    )
 
 
     if (this.guildIDs.length === 0) {
     if (this.guildIDs.length === 0) {
       throw 'Need at least one emote store server'
       throw 'Need at least one emote store server'
@@ -25,14 +27,16 @@ class EmoteStore {
   // Cleans up each emote-storage guild, by removing all channels and emotes
   // Cleans up each emote-storage guild, by removing all channels and emotes
   // present there. RIP.
   // present there. RIP.
   async cleanUp() {
   async cleanUp() {
-    await Promise.all(this.guildIDs.map(guildID => {
-      const guild = this.randomClient().guilds.get(guildID)
-
-      return Promise.all([
-        ...guild.channels.map(c => c.delete()),
-        ...guild.emojis.map(e => guild.deleteEmoji(e)),
-      ])
-    }))
+    await Promise.all(
+      this.guildIDs.map(guildID => {
+        const guild = this.randomClient().guilds.get(guildID)
+
+        return Promise.all([
+          ...guild.channels.map(c => c.delete()),
+          ...guild.emojis.map(e => guild.deleteEmoji(e)),
+        ])
+      })
+    )
   }
   }
 
 
   // Finds a guild with emote slots available. If there are none, deletes an
   // Finds a guild with emote slots available. If there are none, deletes an

+ 0 - 0
core/util/log.js


Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików