Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PT-BR translation and make majority of the strings translatable #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:9-alpine
FROM node:10-alpine
This conversation was marked as resolved.
Show resolved Hide resolved

RUN apk add --no-cache bash gettext git

Expand Down
57 changes: 15 additions & 42 deletions commands/battle/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@ class Battle extends CommandBaseClass {
}

async run(context) {
const { connection } = context;
const { client, connection } = context;



context.log('silly', 'acquiring user data for search..');
const userData = await connection.memberData(context.member);
const _ = (...x) => client.localize(userData.locale, ...x);

context.log('silly', 'got user data');
if (userData.state_engaged) {
await context.send('You cannot do that right now.');
await context.send(_('commands.general.error.engaged'));
return;
}
if (await connection.isPartyEmpty(context.member)) {
await context.send('You don\'t have a party yet. Use `-choose` to make one.');
await context.send(_('commands.general.error.partyless', { PREFIX: context.prefix }));
return;
}

Expand All @@ -42,7 +43,7 @@ class Battle extends CommandBaseClass {

if (party.reduce(function(total, blob) { return total + blob.health; }, 0) <= 0) {
await connection.setEngaged(context.member, false);
await context.send('You do not have any blobs in battling condition.');
await context.send(_('commands.battle.error.all_blobs_fainted'));
return;
}
guild_members.push(context.member);
Expand All @@ -58,35 +59,37 @@ class Battle extends CommandBaseClass {
const enemy_party = await connection.getParty(target_member);
if (target_member.user.id === context.member.user.id) {
await connection.setEngaged(context.member, false);
await context.send('You cannot battle yourself.');
await context.send(_('commands.battle.error.battling_yourself'));
return;
}
if (targetData.state_engaged) {
await connection.setEngaged(context.member, false);
await context.send('That player is busy.');
await context.send(_('commands.battle.error.target_engaged'));
return;
}

if (enemy_party.length !== 6) {
await connection.setEngaged(context.member, false);
await context.send('That user has not created a party yet.');
await context.send(_('commands.battle.error.target_partyless'));
return;
}
if (enemy_party.reduce(function(total, blob) { return total + blob.health; }, 0) <= 0) {
await connection.setEngaged(context.member, false);
await context.send('That user does not have any blobs in battling condition.');
await context.send(_('commands.battle.error.target_blobs_fainted'));
return;
}
guild_members.push(target_member);
player_datas.push(targetData);
const _t = (...x) => client.localize(targetData.locale, ...x);
await connection.setEngaged(target_member, true);
await context.send(`${target_member}, ${context.member.user.username} has challenged you to a battle!\n\`${context.prefix}accept\` or \`${context.prefix}decline\``);
await context.send(_t('commands.battle.battle_invite', { TARGET: target_member, USER: context.member.user.username, PREFIX: context.prefix }));
const re = new RegExp(`^(?:${context.client.prefixRegex})(accept|decline)(.*)$`);
const filter = m => (m.author.id === target_member.id && re.test(m.content));
let response;
try {
response = re.exec((await context.channel.awaitMessages(filter, { max: 1, time: 30000, errors: ['time'] })).first().content);
} catch (e) {
// user didnt respond
// user didnt respond
await connection.setEngaged(context.member, false);
await connection.setEngaged(target_member, false);
return;
Expand All @@ -96,44 +99,14 @@ class Battle extends CommandBaseClass {
await connection.setEngaged(target_member, false);
return;
}

}


const battle_message = await context.send('Battle starting...');
const battle_message = await context.send(_('commands.battle.battle_starting'));
const controller = new BattleController(context, connection, guild_members, player_datas, battle_message);
await controller.setup();































}
}

Expand Down
22 changes: 11 additions & 11 deletions commands/choose/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ class Choose extends CommandBaseClass {
}

async run(context) {
const { message, connection } = context;
const { client, message, connection } = context;

context.log('silly', 'acquiring user data for search..');
const userData = await connection.memberData(context.member);
const _ = (...x) => client.localize(userData.locale, ...x);
context.log('silly', 'got user data');


await connection.setEngaged(context.member, true);

if (userData.state_engaged) {
await context.send('You cannot do that right now.');
await context.send(_('commands.general.error.engaged'));
return;
}

Expand All @@ -41,12 +42,12 @@ class Choose extends CommandBaseClass {
});

for (const element of inputted_blobs) {
if (element === '-choose') {
if (element === `${context.prefix}choose`) {
continue;
}
const temp = await connection.searchBlob(element);
if (!temp) {
await context.send('One of those blobs does not exist.');
await context.send(_('commands.choose.error.non_existent_blob'));
await connection.setEngaged(context.member, false);
return;
}
Expand All @@ -57,7 +58,7 @@ class Choose extends CommandBaseClass {
for (let x = 0; x < blobdefs.length; x++)
for (let y = 0; y < blobdefs.length; y++)
if (x !== y && blobdefs[x].emoji_id === blobdefs[y].emoji_id) {
await context.send('You cannot have multiple of the same blob.');
await context.send(_('commands.choose.error.duplicated_blob'));
await connection.setEngaged(context.member, false);
return;
}
Expand All @@ -73,8 +74,7 @@ class Choose extends CommandBaseClass {
}
});

await context.send('Your chosen blobs:\n' + blob_emojis.join(' ')
+ `\nYou will not be able to change them later. \`${context.prefix}confirm\` or \`${context.prefix}cancel\``);
await context.send(_('commands.choose.choose_prompt', { BLOBS: blob_emojis.join(' '), PREFIX: context.prefix }));

const re = new RegExp(`^(?:${context.client.prefixRegex})(confirm|cancel)(.*)$`);
const filter = m => (m.author.id === context.author.id && re.test(m.content));
Expand All @@ -83,23 +83,23 @@ class Choose extends CommandBaseClass {
response = re.exec((await context.channel.awaitMessages(filter, { max: 1, time: 60000, errors: ['time'] })).first().content);
} catch (e) {
await connection.setEngaged(context.member, false);
// user didnt respond
// user didnt respond
return;
}
if (response[1] === 'confirm') {
for (let index = 0; index < blobdefs.length; index++) {
await connection.giveBlobParty(context.member, blobdefs[index], index);
}
await context.send('Your party has been created!');
await context.send(_('commands.choose.party_created'));
}

}
else {
await context.send(`You need to choose six blobs to make a party.\nUsage: \`${context.prefix}choose <blobname> <blobname> <blobname> <blobname> <blobname> <blobname>\``);
await context.send(_('commands.choose.error.six_blobs_required', { PREFIX: context.prefix }));
}
}
else {
await context.send('You cannot change your party.');
await context.send(_('commands.choose.error.cant_change_party'));
}
await connection.setEngaged(context.member, false);
}
Expand Down
9 changes: 5 additions & 4 deletions commands/heal/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,23 @@ class Heal extends CommandBaseClass {
}

async run(context) {
const { connection } = context;
const { client, connection } = context;

context.log('silly', 'acquiring user data for search..');
const userData = await connection.memberData(context.member);
const _ = (...x) => client.localize(userData.locale, ...x);
context.log('silly', 'got user data');

if (userData.state_engaged) {
await context.send('You cannot do that right now.');
await context.send(_('commands.general.error.engaged'));
return;
}
if (await connection.isPartyEmpty(context.member)) {
await context.send('You don\'t have a party yet. Use `-choose` to make one.');
await context.send(_('commands.general.error.partyless'), { PREFIX: context.prefix });
return;
}
await connection.healAllBlobs(context.member);
await context.send('Blobs healed.');
await context.send(_('commands.general.heal.blobs_healed'));
}
}
module.exports = Heal;
4 changes: 2 additions & 2 deletions commands/inventory/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class Inventory extends CommandBaseClass {
context.log('silly', 'got user data');

if (userData.state_engaged) {
await context.send('You cannot do that right now.');
await context.send(_('commands.general.error.engaged'));
return;
}
if (await connection.isPartyEmpty(context.member)) {
await context.send('You don\'t have a party yet. Use \`-choose\` to make one.');
await context.send(_('commands.general.error.partyless'), { PREFIX: context.prefix });
return;
}
}
Expand Down
13 changes: 7 additions & 6 deletions commands/party/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ class Party extends CommandBaseClass {
}

async run(context) {
const { connection } = context;
const { client, connection } = context;

context.log('silly', 'acquiring user data for search..');
const userData = await connection.memberData(context.member);
const _ = (...x) => client.localize(userData.locale, ...x);
context.log('silly', 'got user data');

if (userData.state_engaged) {
await context.send('You cannot do that right now.');
await context.send(_('commands.general.error.engaged'));
return;
}
if (await connection.isPartyEmpty(context.member)) {
await context.send('You don\'t have a party yet. Use `-choose` to make one.');
await context.send(_('commands.general.error.partyless'), { PREFIX: context.prefix });
return;
}

Expand All @@ -33,7 +34,7 @@ class Party extends CommandBaseClass {
var blob_emojis = [];
var cur_total_health = 0;
var total_health = 0;

party.forEach(function(element) {
var emoji = context.client.emojis.find(emoji => emoji.id === element.emoji_id);
if (emoji) {
Expand Down Expand Up @@ -62,9 +63,9 @@ class Party extends CommandBaseClass {
await context.send({
embed: {
color: parseInt(await this.healthColor(cur_total_health / total_health)),
title: `${context.author.username}'s Party`,
title: _('commands.party.party_title', { USER: context.author.username }),
footer: {
text: '-stats [slot] to view individual statistics'
text: _('commands.party.stats_command', { PREFIX: context.prefix })
},
fields: fields_array
}
Expand Down
22 changes: 12 additions & 10 deletions commands/rank/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ class Rank extends CommandBaseClass {
}

async run(context) {
const { connection } = context;
const { client, connection } = context;

context.log('silly', 'acquiring user data for search..');
const userData = await connection.memberData(context.member);
const _ = (...x) => client.localize(userData.locale, ...x);
context.log('silly', 'got user data');


if (userData.state_engaged) {
await context.send('You cannot do that right now.');
await context.send(_('commands.general.error.engaged'));
return;
}
if (await connection.isPartyEmpty(context.member)) {
await context.send('You don\'t have a party yet. Use `-choose` to make one.');
await context.send(_('commands.general.error.partyless'), { PREFIX: context.prefix });
return;
}

Expand All @@ -36,10 +37,10 @@ class Rank extends CommandBaseClass {
var color = 0;
var response = '';


top5.forEach(function(element) {
if (element.user_id === context.author.id) {
response += `**${element.row_number}: <@${element.user_id}> with ${element.ranking} Blob Trophies**\n`;
response += _('commands.rank.response', { PLACE: element.row_number, USERID: element.user_id, TROPHIES: element.ranking });
switch (element.row_number) {
case '1':
color = 16766720;
Expand All @@ -53,17 +54,18 @@ class Rank extends CommandBaseClass {
}
}
else
response += `${element.row_number}: <@${element.user_id}> with ${element.ranking} **Blob Trophies**\n`;
response += _('commands.rank.response', { PLACE: element.row_number, USERID: element.user_id, TROPHIES: element.ranking });
});

if (currentRank.row_number > 5) {
var adjRanks = await connection.getAdjRanks(context.member, currentRank.row_number);
response += '...\n';
response += `${adjRanks[0].row_number}: <@${adjRanks[0].user_id}> with ${adjRanks[0].ranking} **Blob Trophies**\n`;
response += `**${currentRank.row_number}: <@${currentRank.user_id}> with ${currentRank.ranking} Blob Trophies**`;
response += _('commands.rank.response', { PLACE: adjRanks[0].row_number, USERID: adjRanks[0].user_id, TROPHIES: adjRanks[0].ranking });
response += _('commands.rank.last_rank_response', { PLACE: currentRank.row_number, USERID: currentRank.user_id, TROPHIES: currentRank.ranking });
if (adjRanks.length === 2) {
response += `\n${adjRanks[1].row_number}: <@${adjRanks[1].user_id}> with ${adjRanks[1].ranking} **Blob Trophies**`;
}
response += `\n`;
response += _('commands.rank.last_rank_response', { PLACE: adjRanks[1].row_number, USERID: adjRanks[1].user_id, TROPHIES: adjRanks[1].ranking });
}
}
context.send({
embed: {
Expand Down
Loading