Skip to content
This repository was archived by the owner on Apr 14, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions resources/i18n/en/companion.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
"Are you certain you'd like to purchase it for {{amount}} credits?\n",
"To confirm, please write {{code}}, or anything else to exit."
],
"food": [
"{{author}}, are you sure you'd like to feed your {{animal}} {{amount}} food?\n",
"To confirm, please write {{code}}, or anything else to exit."
],
"petFed": "{{author}}, you have just fed your {{animal}}, restoring their **hunger** and **mood** by {{amount}}",
"tooHungry": "Your companion is too full to feed it {{amount}} food!",
"notEnoughFood": "You can't feed your {{animal}} {{amount}} food as you only have {{inv}} in your inventory!",
"invalidCode": "you have entered an invalid code! The transaction was cancelled.",
"error": "an error has occurred! The transaction was cancelled. Try again later.",
"result": [
Expand All @@ -21,7 +28,9 @@
"wins": "Wins",
"losses": "Losses",
"info": "Companion Info",
"info2": "{{author}}'s Companion"
"info2": "{{author}}'s Companion",
"mood": "Mood",
"hunger": "Food"
},
"errors": {
"self": "you can't battle yourself!",
Expand All @@ -42,7 +51,11 @@
"plsBetProperly": "you can't bet less than one credit!",
"notBetting": "the battle has not entered the betting phase!",
"afterBetting": "the betting phase has already concluded for this battle!",
"notOnline": "that user is not online yet!"
"notOnline": "that user is not online yet!",
"hungry": "your companion is too hungry to battle",
"moody": "your companion's mood is too low to battle",
"hungryOpponent": "your opponent's companion is too hungry to battle",
"moodyOpponent": "your opponent's companion's mood is too low to battle"
},
"challenge": [
"you have challenged {{mention}} to a pet battle!\n",
Expand Down
24 changes: 24 additions & 0 deletions resources/i18n/en/shop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"buyDialog": "Items for purchase",
"sellDialog": "Items for sale",
"menu": {
"food": "Bag of generic pet food. Raises food by 1",
"checkInv": "Check your current inventory"
},
"howMuch": "{{author}}, how many {{selection}} would you like to buy?",
"purchase": [
"{{author}}, are you sure you'd like to purchase {{amount}} {{selection}}?\n",
"To confirm, please write {{code}}, or anything else to exit."
],
"result": [
"**Food Purchased**\n",
"{{author}}, you have successfully purchased {{amount}} {{selection}}.",
"__Current Balance__: {{balance}} credits\n"
],
"error": "an error has occurred! The transaction was cancelled. Try again later.",
"cannotAfford": "I'm sorry, you need {{ammount}} credits to buy that but you only have {{balance}}",
"info": "Current Inventory",
"amounts": {
"petFood": "Pet food"
}
}
15 changes: 15 additions & 0 deletions src/commands/games/battle.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,24 @@ class Battle extends Command {
balance: `**${userProfile.credits}**`
})
}

if (userProfile.companion.hunger <= 1) {
return responder.error('{{errors.hungry}}')
}

if (userProfile.companion.mood <= 1) {
return responder.error('{{errors.moody}}')
}

const oppProfile = await data.User.fetch(opp.id)
if (!oppProfile.companion) return responder.error('{{errors.opponentNoCompanion}}')
if (oppProfile.credits < this.entryFee) return responder.error('{{errors.cantChallenge}}')
if (oppProfile.companion.hunger === 1) {
return responder.error('{{errors.hungryOpponent}}')
}
if (oppProfile.companion.mood === 1) {
return responder.error('{{errors.moodyOpponent}}')
}

try {
await companions.initBattle(msg.author, opp, msg.channel, settings, responder, this.respondTime, this.entryFee)
Expand Down
83 changes: 78 additions & 5 deletions src/commands/games/companions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Companions extends Command {
super(...args, {
name: 'companion',
description: 'Animal companion system',
usage: [{ name: 'action', displayName: 'buy | rename | peek', type: 'string', optional: true }],
usage: [{ name: 'action', displayName: 'buy | rename | peek | feed', type: 'string', optional: true }],
aliases: ['pet'],
cooldown: 5,
subcommands: {
Expand All @@ -15,7 +15,10 @@ class Companions extends Command {
usage: [{ name: 'user', type: 'member', optional: false }],
options: { guildOnly: true }
},
rename: 'rename'
rename: 'rename',
feed: {
usage: [{ name: 'amount', type: 'int', optional: true }]
}
},
options: { botPerms: ['embedLinks'] }
})
Expand All @@ -34,11 +37,66 @@ class Companions extends Command {
description: `**\`LVL ${Math.floor(Math.cbrt(companion.xp)) || 0}\`** :${companion.type}: ${companion.name}`,
fields: [
{ name: responder.t('{{definitions.wins}}'), value: stats.wins || 0, inline: true },
{ name: responder.t('{{definitions.losses}}'), value: stats.losses || 0, inline: true }
{ name: responder.t('{{definitions.losses}}'), value: stats.losses || 0, inline: true },
{ name: responder.t('{{definitions.mood}}'), value: companion.mood || 10, inline: true},
{ name: responder.t('{{definitions.hunger}}'), value: companion.hunger || 10, inline: true}
]
}).send()
}

async feed ({ msg, args, data }, responder) {
const user = await data.User.fetch(msg.author.id)
const companion = (await data.User.fetchJoin(msg.author.id, { companion: true })).companion
if (!companion) {
responder.error('{{noPet}}', { command: `**\`${settings.prefix}${trigger} buy\`**` })
return
}
const amount = args.amount || 1
if ((companion.hunger + amount) > 10) {
responder.error('{{tooHungry}}', {amount: `**${amount}**`})
return
}
if (user.petfood < amount) {
responder.error('{{notEnoughFood}}', {
amount: `**${amount}**`,
inv: `**${user.petfood}**`,
animal: `:${companion.type}:`
})
return
}
const code = ~~(Math.random() * 8999) + 1000
const arg = await responder.format('emoji:info').dialog([{
prompt: '{{food}}',
input: { type: 'string', name: 'code' }
}], {
author: `**${msg.author.username}**`,
animal: `:${companion.type}:`,
amount: `**${amount}**`,
code: `**\`${code}\`**`
})
if (parseInt(arg.code, 10) !== code) {
return responder.error('{{invalidCode}}')
}
if ((companion.mood + amount) > 10) {
companion.mood = 10
} else {
companion.mood += amount
}
companion.hunger += amount
try {
await user.saveAll()
await data.User.update(user.id, user)
} catch (err) {
logger.error(`Could not save after companion feeding: ${err}`)
return responder.error('{{error}}')
}
responder.format('emoji:success').send('{{petFed}}', {
author: `**${msg.author.username}**`,
animal: `:${companion.type}:`,
amount: `**${amount}**`
})
}

async peek ({ args, data }, responder) {
const [member] = await responder.selection(args.user, { mapFunc: m => `${m.user.username}#${m.user.discriminator}` })
if (!member) return
Expand All @@ -55,7 +113,9 @@ class Companions extends Command {
description: `**\`LVL ${Math.floor(Math.cbrt(companion.xp)) || 0}\`** :${companion.type}: ${companion.name}`,
fields: [
{ name: responder.t('{{definitions.wins}}'), value: stats.wins || 0, inline: true },
{ name: responder.t('{{definitions.losses}}'), value: stats.losses || 0, inline: true }
{ name: responder.t('{{definitions.losses}}'), value: stats.losses || 0, inline: true },
{ name: responder.t('{{definitions.mood}}'), value: companion.mood || 10, inline: true},
{ name: responder.t('{{definitions.hunger}}'), value: companion.hunger || 10, inline: true}
]
}).send()
}
Expand Down Expand Up @@ -220,4 +280,17 @@ class PetBuy extends Companions {
}
}

module.exports = [ Companions, PetBuy ]
class PetFeed extends Companions {
constructor (...args) {
super(...args, {
name: 'feedpet',
description: 'Feeds your personal companion',
options: { localeKey: 'companion' },
aliases: [],
usage: [{ name: 'amount', type: 'int', optional: true }],
subcommand: 'feed'
})
}
}

module.exports = [ Companions, PetBuy, PetFeed ]
82 changes: 82 additions & 0 deletions src/commands/games/shop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
const logger = require('winston')
const { Command } = require('../../core')

class Shop extends Command {
constructor (...args) {
super(...args, {
name: 'shop',
description: 'A small shop to buy things with credits',
options: { localeKey: 'shop' }
})
}

handle (container, responder) {
const { msg, data, settings } = container
return responder.selection(['food', 'checkInv'], {
title: '{{buyDialog}}',
mapFunc: ch => responder.t(`{{menu.${ch}}}`)
}).then(arg => arg.length ? this[arg[0]](container, responder) : false)
}

async food ({ msg, data, settings }, responder) {
const user = await data.User.fetch(msg.author.id)
const arg = await responder.format('emoji:info').dialog([{
prompt: '{{howMuch}}',
input: { type: 'int', name: 'howMuch' }
}], {
author: `**${msg.author.username}**`,
selection: `food`
})
const amount = arg.howMuch
const price = (100 * amount)
if (user.credits < price) {
responder.error('{{cannotAfford}}', {
amount: `**${price}**`,
balance: `**${user.credits}**`
})
return
}
const code = ~~(Math.random() * 8999) + 1000
const argCode = await responder.format('emoji:info').dialog([{
prompt: '{{purchase}}',
input: { type: 'string', name: 'code' }
}], {
author: `**${msg.author.username}**`,
selection: `food`,
amount: `**${amount}**`,
code: `**\`${code}\`**`
})
if (parseInt(argCode.code, 10) !== code) {
return responder.error('{{invalidCode}}')
}
user.petfood += amount
user.credits -= price
try {
await user.saveAll()
await data.User.update(user.id, user)
} catch (err) {
logger.error(`Could not save after food purchase: ${err}`)
return responder.error('{{error}}')
}
responder.format('emoji:success').send('{{result}}', {
author: `**${msg.author.username}**`,
amount: `**${amount}**`,
selection: `food`,
balance: `:credits: **${user.credits}**`
})
}

async checkInv ({ msg, data, settings }, responder){
const user = await data.User.fetch(msg.author.id)
responder.embed({
color: this.colours.blue,
author: { name: responder.t('{{info}}'), icon_url: msg.author.avatarURL },
description: `:credit_card: ${user.credits}`,
fields: [
{ name: responder.t('{{amounts.petFood}}'), value: user.petfood || 0, inline: true }
]
}).send()
}

}
module.exports = [Shop]
2 changes: 1 addition & 1 deletion src/commands/moderation/autorole.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Autorole extends Command {
name: 'autorole',
description: 'Add a role to a user on join',
usage: [
{ name: 'action', displayName: ' add | remove', type: 'string', optional: true }],
{ name: 'action', displayName: ' add <@role> | remove', type: 'string', optional: true }],
subcommands: {
add: {
usage: [
Expand Down
7 changes: 0 additions & 7 deletions src/commands/moderation/ban.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ class Ban extends Command {
return responder.error('{{ban.exit}}')
}
try {
const channel = await this.bot.getDMChannel(member.id)
await this.send(channel, [
`🔨 | You have been banned from **\`${msg.channel.guild.name}\`**\n`,
`**Reason**: ${args.reason}`
].join('\n'))
await msg.channel.guild.banMember(member.id, 0, args.reason)
client.emit('haruMemberBanned', msg.channel.guild, member.user, args.reason)
return responder.format('emoji:hammer').reply('{{ban.msg}}', {
member: `**${member.user.username}#${member.user.discriminator}**`,
deleteDelay: 5000
Expand Down
6 changes: 0 additions & 6 deletions src/commands/moderation/kick.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ class Kick extends Command {
return responder.error('{{kick.exit}}')
}
try {
const channel = await this.bot.getDMChannel(member.id)
await this.send(channel, [
`👢 | You have been kicked from **\`${msg.channel.guild.name}\`**\n`,
`**Reason**: ${args.reason}`
].join('\n'))
await msg.channel.guild.kickMember(member.id, args.reason)
client.emit('haruMemberKicked', msg.channel.guild, member.user, args.reason)
return responder.format('emoji:boot').reply('{{kick.msg}}', {
member: `**${member.user.username}#${member.user.discriminator}**`,
Expand Down
3 changes: 3 additions & 0 deletions src/models/Companion.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ module.exports = function () {
hp: number().default(10),
crit: number().default(1),
atk: number().default(1),
heal: number().default(1),
mood: number().default(10),
hunger: number().default(10),
inventory: array().default([])
},
relations: {
Expand Down
1 change: 1 addition & 0 deletions src/models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = function () {
id: string(),
credits: number().default(0),
exp: number().default(0),
petfood: number().default(0),
deleted: bool().default(false),
title: string().default('Commoner'),
description: string().default('A simple wandering soul'),
Expand Down
Loading