Skip to content

Commit

Permalink
Add locale to bot
Browse files Browse the repository at this point in the history
  • Loading branch information
7coil committed Sep 10, 2017
1 parent e7db673 commit 7f2c7f3
Show file tree
Hide file tree
Showing 19 changed files with 351 additions and 272 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Expand Up @@ -9,6 +9,7 @@
"comma-dangle": 0,
"max-len": 0,
"no-console": 0,
"no-param-reassign": 0
"no-param-reassign": 0,
"no-underscore-dangle": 0
}
}
47 changes: 43 additions & 4 deletions locales/blank.json
Expand Up @@ -13,13 +13,52 @@
"error_suggest": "error_suggest",
"footer_copyright": "footer_copyright",
"footer_disclaimer": "footer_disclaimer",
"footer_tos": "footer_tos",
"footer_pa": "footer_pa",
"footer_mss": "footer_mss",
"tos": "tos",
"pa": "pa",
"mss": "mss",
"footer_lang": "footer_lang",
"mail_from": "mail_from",
"mail_date": "mail_date",
"mail_subject": "mail_subject",
"mail_to": "mail_to",
"github": "GitHub"
"github": "github",
"err_guild": "err_guild",
"err_admin": "err_admin",
"block_delimit": "block_delimit",
"block_blocked": "block_blocked",
"err_generic": "err_generic",
"err_quota": "err_quota",
"consent_subject": "consent_subject",
"consent_message": "consent_message",
"consent_guild": "consent_guild",
"consent_needed": "consent_needed",
"help_intro": "help_intro",
"help_prefixuser": "help_prefixuser",
"help_prefixguild": "help_prefixguild",
"invite": "invite",
"guild": "guild",
"guildapp": "guildapp",
"help_notime": "help_notime",
"info_nodejs": "info_nodejs",
"info_guilds": "info_guilds",
"info_pid": "info_pid",
"info_hard": "info_hard",
"info_soft": "info_soft",
"info_licence": "info_licence",
"info_licencedesc": "info_licencedesc",
"reply_incorrect": "reply_incorrect",
"reply_noexist": "reply_noexist",
"reply_conflict": "reply_conflict",
"reply_sent": "reply_sent",
"send_incorrect": "send_incorrect",
"send_blocked": "send_blocked",
"send_sent": "send_sent",
"what_guild_noexist": "what_guild_noexist",
"what_guild_exist": "what_guild_exist",
"what_user_noexist": "what_user_noexist",
"what_user_exist": "what_user_exist",
"what_user_noreg": "what_user_noreg",
"what_self_exist": "what_self_exist",
"locale_incorrect": "locale_incorrect",
"locale_set": "locale_set"
}
41 changes: 40 additions & 1 deletion locales/bullshit.json
Expand Up @@ -21,5 +21,44 @@
"mail_date": "fa la ehak Calasta: {{ date }}",
"mail_subject": "Ajd a {{ subject }} kaka nababa",
"mail_to": "{{ to }} ajax apala",
"github": "PornHub"
"github": "PornHub",
"err_guild": "Heka whadk audanddjaormapt!",
"err_admin": "Uaska lwjf anaka uey - uehan pcaj 15.2",
"block_delimit": "Jdapak wpdja `;` x (n+1)",
"block_blocked": "Hdkawuw (ga)dwjawkh {{ emails }} adwak 6.",
"err_generic": "Idhak pdjjahe ACHTUNG akdawow lays calapwksa.",
"err_quota": "Kalid a ldwocya ldfhya alerm apjalk zxoemnqm Nintendo Wii maol",
"consent_subject": "{{ name }} Ja jainme qalzcomm!",
"consent_message": "Jlajdoa nzldjwh alduhe paixhzle yertqahz olfdja 3412. Djufja Ldfhsa kfovy kdianee ale xfli pn oteisa trap.",
"consent_guild": "Ldjaiaw nxbwlke < {{ url }} > odhwmn",
"consent_needed": "Haydjw aldowur lsvnz,wo irkw,el. Yeuscpcj nxzyewjw ocurmldjv yuwtn < {{ prefix }} agree > ma rtmist isa tra pakd ycaj.",
"help_intro": "{{ name }} jdayw kxoxciw ldpgfuw bcmxmzyrf jdgjdw MMCBXLEX",
"help_prefixuser": "Iqusdk pacma pdlja xnzxku rka < {{ prefixes }} >",
"help_prefixguild": "< {{ prefixes }} > Jwdkaw ycuakw ;doawjk dhaj",
"invite": "Hakco",
"guild": ":thinking:",
"guildapp": ":b:",
"help_notime": ":pancake:",
"info_nodejs": ":flag_no:de Hakyw",
"info_guilds": "Guild Count",
"info_pid": ":levitate:",
"info_hard": "JHdiay KDJHA",
"info_soft": "Pwik and",
"info_licence": "Eucia Traad",
"info_licencedesc": "{{ name }}, Kshd jas < [DiscordMail](https://discordmail.com) > hdyctl daj a dhetnxt oepq < MIT Licence >.",
"reply_incorrect": "Idyawnr osahdbw: `{{ prefix }} {{ command }} ID-Dudgawn Kdgwitm`",
"reply_noexist": "Jdtrnt aodhrn < ID > kdwyrb",
"reply_conflict": "< I D > Hdlap Hakf Yeopqp Zoradla",
"reply_sent": "Haydkca hjruw r meme pxja r papa.",
"send_incorrect": "Icjw,we;l ucnrlw: `{{ prefix }} {{ command }} Address \"Subject\" Content`",
"send_blocked": ":egg: NEIN! EST HDIAY KZLR ORJRN AODJEG",
"send_sent": ":x: hyywwks cUDKJE Jdc",
"what_guild_noexist": "Hela oea keo ahjrb durt kmchx pral audh hmxlla hsmnvrb: {{ url }}",
"what_guild_exist": "HJduf mxhzi rlaop < {{ email }} >",
"what_user_noexist": "Khagd Zcdhj Etej Whdka Pjda! jwhfdo wyrnbmsa iadhwn aosxu ljlkajy xtuywnbqwmk joalkjiuhy vwhb abuse@discordapp.com",
"what_user_exist": "Hdk adiwhe rlUTe nakdy < {{ email }} >",
"what_user_noreg": "Jlacuew nawocsyx xycu enmn siolue `{{ prefix }} register` command",
"what_self_exist": "POwur nsnhxy xn,mnekh yuas jre `{{ email }}`",
"locale_incorrect": "Pwdi nkjyt xczytu ekja: {{ locales }}",
"locale_set": "Pdwu wjm xzcyj e iua {{ locale }}"
}
47 changes: 43 additions & 4 deletions locales/en-gb.json
Expand Up @@ -13,13 +13,52 @@
"error_suggest": "You may want to go back to the previous page.",
"footer_copyright": "Copyright 2015 - 2017, Moustacheminer Server Services",
"footer_disclaimer": "MSS are not associated with Discord Inc.",
"footer_tos": "Terms of Service",
"footer_pa": "Privacy Agreement",
"footer_mss": "Moustacheminer Server Services",
"tos": "Terms of Service",
"pa": "Privacy Agreement",
"mss": "Moustacheminer Server Services",
"footer_lang": "Languages / Internationalization",
"mail_from": "From: {{ from }}",
"mail_date": "Date: {{ date }}",
"mail_subject": "Subject: {{ subject }}",
"mail_to": "To: {{ to }}",
"github": "GitHub"
"github": "GitHub",
"err_guild": "You can only use this context while inside a guild!",
"err_admin": "Only administrators can use this context.",
"block_delimit": "Please submit email addresses, separated by semicolons `;`",
"block_blocked": "Blocked {{ emails }} email(s).",
"err_generic": "An error occured while processing your request.",
"err_quota": "DiscordMail has ran out of it's monthly Mailgun quota. The bot has been disabled.",
"consent_subject": "Welcome to {{ name }}!",
"consent_message": "Welcome! You should be reciving an E-Mail to your DMs. If you do not recieve one, make sure you have allowed DMs to your account.",
"consent_guild": "To register the guild, please fill in this form: {{ url }}",
"consent_needed": "Your account has not been created yet. Please read the Terms of Service and Privacy agreement, before typing the `{{ prefix }} agree` comamnd.",
"help_intro": "{{ name }} allows you to send and recieve emails from within Discord.",
"help_prefixuser": "Prefixes for users: {{ prefixes }}",
"help_prefixguild": "Prefixes for guilds: {{ prefixes }}",
"invite": "Invite",
"guild": "Guild",
"guildapp": "Guild Application Forms",
"help_notime": "Literally no time whatsoever",
"info_nodejs": "Node.js",
"info_guilds": "Guild Count",
"info_pid": "Process ID",
"info_hard": "Hardware",
"info_soft": "Software",
"info_licence": "Licence",
"info_licencedesc": "{{ name }}, an instance of [DiscordMail](https://discordmail.com) is licenced under the MIT Licence.",
"reply_incorrect": "Expected input: `{{ prefix }} {{ command }} Reply-ID Content`",
"reply_noexist": "Could not find your E-Mail ID",
"reply_conflict": "You cannot reply with another user's ID",
"reply_sent": "Successfully replied to E-Mail.",
"send_incorrect": "Expected input: `{{ prefix }} {{ command }} Address \"Subject\" Content`",
"send_blocked": "This email address has been blocked by the owner of this bot.",
"send_sent": "Successfully sent E-Mail.",
"what_guild_noexist": "This guild has not registered for DiscordMail. Please register by filling in this form: {{ url }}",
"what_guild_exist": "The guild's E-Mail is `{{ email }}`",
"what_user_noexist": "This user has not registered.",
"what_user_exist": "The user's E-Mail is `{{ email }}`",
"what_user_noreg": "You have not registered! Please register by running the `{{ prefix }} register` command",
"what_self_exist": "Your E-Mail is `{{ email }}`",
"locale_incorrect": "Valid locales: {{ locales }}",
"locale_set": "Set locale to {{ locale }}"
}
10 changes: 0 additions & 10 deletions locales/zh-hk.json

This file was deleted.

16 changes: 0 additions & 16 deletions server/api.js
Expand Up @@ -171,22 +171,6 @@ router.post('/mail', upload.single('attachment-1'), validate, check, (req, res)
})
.get('/stats', (req, res) => {
res.status(200).json({ guilds: discord.guilds.size, users: discord.users.size });
})
.get('/collection', (req, res) => {
r.table('collection')
.run(r.conn, (err1, cursor) => {
if (err1) {
res.status(500).json(err1);
} else {
cursor.toArray((err2, result) => {
if (err2) {
res.status(500).json(err2);
} else {
res.status(200).json(result);
}
});
}
});
});

module.exports = router;
55 changes: 24 additions & 31 deletions server/discord/cogs/block/index.js
@@ -1,6 +1,5 @@
const r = require('./../../../db');
const dmail = require('./../../utils.js').dmail;
const isadmin = require('./../../utils.js').isadmin;

module.exports.info = {
name: 'Block E-Mail. Send E-Mails separated by ;',
Expand All @@ -12,34 +11,28 @@ module.exports.info = {
};

module.exports.command = (message) => {
if (message.context === 'guild' && !message.channel.guild) {
message.channel.createMessage('You can only use this context within a guild!');
} else if (message.context === 'guild' && !isadmin(message.member)) {
message.channel.createMessage('Only administrators can control the guild\'s dmail!');
} else {
// Check for registrations
dmail.check(message.inbox)
.then(() => {
if (!message.input) {
message.channel.createMessage('Please submit emails to be blocked. Separate emails with semicolons if required.');
} else {
const emails = message.input.toLowerCase().split(';');
r.table('registrations')
.get(message.inbox)
.update({
block: r.row('block').union(emails).default([emails])
})
.run(r.conn, (err) => {
if (err) {
message.channel.createMessage(`A fatal error occured: ${err.message}`);
} else {
message.channel.createMessage(`Blocked ${emails.length} email${emails.length > 1 ? 's' : ''}.`);
}
});
}
})
.catch((err) => {
message.channel.createMessage(err);
});
}
// Check for registrations
dmail.check(message.inbox)
.then(() => {
if (!message.input) {
message.channel.createMessage(message.__('block_delimit'));
} else {
const emails = message.input.toLowerCase().split(';');
r.table('registrations')
.get(message.inbox)
.update({
block: r.row('block').union(emails).default([emails])
})
.run(r.conn, (err) => {
if (err) {
message.channel.createMessage(message.__('err_generic'));
} else {
message.channel.createMessage(message.__('block_blocked', { emails: emails.length }));
}
});
}
})
.catch((err) => {
message.channel.createMessage(err);
});
};
10 changes: 5 additions & 5 deletions server/discord/cogs/consent/index.js
Expand Up @@ -30,27 +30,27 @@ module.exports.command = (message) => {
})
.run(r.conn, (err) => {
if (err) {
message.channel.createMessage('An error occured writing your registration to the database.');
message.channel.createMessage(message.__('err_generic'));
} else {
const data = {
from: `${config.get('name')} Mail Server <noreply@${config.get('api').mailgun.domain}>`,
to: `${message.name}#${message.author.discriminator}@${config.get('api').mailgun.domain}`,
subject: `Welcome to ${config.get('name')}!`,
subject: message.__('consent_subject', { name: message.__('name') }),
html: config.get('welcome')
};

mailgun.messages().send(data, (err2) => {
if (err2) {
message.channel.createMessage(`Failed to send E-Mail: ${err2.message}`);
message.channel.createMessage(message.__('err_generic'));
console.log(`Failed to send an introductory email to ${message.name}#${message.author.discriminator}@${config.get('api').mailgun.domain}`);
} else {
message.channel.createMessage('Welcome! You should be receiving an E-Mail to your DMs. If you do not recieve one, make sure you have allowed DMs to your account.');
message.channel.createMessage(message.__('consent_message'));
console.log((new Date()).toUTCString(), `Sent introductory email to ${message.name}#${message.author.discriminator}@${config.get('api').mailgun.domain}`);
}
});
}
});
} else {
message.channel.createMessage(`To register the guild, please fill this form in. ${config.get('webserver').domain}/url/guild`);
message.channel.createMessage(message.__('consent_guild', { url: `${config.get('webserver').domain}/url/guild` }));
}
};
14 changes: 7 additions & 7 deletions server/discord/cogs/guild/index.js
Expand Up @@ -31,22 +31,22 @@ module.exports.command = (message) => {
})
.run(r.conn, (err) => {
if (err) {
message.channel.createMessage('An error occured writing the registration to the database.');
message.channel.createMessage(message.__('err_generic'));
} else {
const data = {
from: `${config.get('name')} Mail Server <noreply@${config.get('api').mailgun.domain}>`,
to: `${name(message.input)}@${config.get('api').mailgun.domain}`,
subject: `Welcome to ${config.get('name')}!`,
to: `${message.name}#${message.author.discriminator}@${config.get('api').mailgun.domain}`,
subject: message.__('consent_subject', { name: message.__('name') }),
html: config.get('welcome')
};

mailgun.messages().send(data, (err2) => {
if (err2) {
message.channel.createMessage(`Failed to send E-Mail: ${err2.message}`);
console.log(`Failed to send an introductory email to ${name(message.input)}@${config.get('api').mailgun.domain}`);
message.channel.createMessage(message.__('err_generic'));
console.log(`Failed to send an introductory email to ${message.name}#${message.author.discriminator}@${config.get('api').mailgun.domain}`);
} else {
message.channel.createMessage('Successfully added guild to DiscordMail.');
console.log((new Date()).toUTCString(), `Sent introductory email to ${name(message.input)}@${config.get('api').mailgun.domain}`);
message.channel.createMessage(message.__('consent_message'));
console.log((new Date()).toUTCString(), `Sent introductory email to ${message.name}#${message.author.discriminator}@${config.get('api').mailgun.domain}`);
}
});
}
Expand Down
8 changes: 4 additions & 4 deletions server/discord/cogs/help/index.js
Expand Up @@ -33,9 +33,9 @@ module.exports.command = (message) => {
}
});

let reply = `${config.get('name')} allows you to send and recieve emails from within Discord.\n`;
reply += `Prefixes for users: \`${config.get('discord').prefix.user.join('; ')}\`\n`;
reply += `Prefixes for guilds: \`${config.get('discord').prefix.guild.join('; ')}\`\n`;
let reply = `${message.__('help_intro', { name: message.__('name') })}\n`;
reply += `${message.__('help_prefixuser', { prefixes: `${config.get('discord').prefix.user.join('; ')}` })}\n`;
reply += `${message.__('help_prefixguild', { prefixes: `${config.get('discord').prefix.guild.join('; ')}` })}\n`;
reply += '```\n';
Object.keys(categories).forEach((key) => {
reply += `${capitalise(key)}:\n`;
Expand All @@ -56,7 +56,7 @@ module.exports.command = (message) => {
});
});

reply += `\n\`\`\`\n[GitHub](${config.get('webserver').domain}/url/github) - [Invite](${config.get('webserver').domain}/url/invite) - [Guild](${config.get('webserver').domain}/url/help) - [Guild Applications](${config.get('webserver').domain}/url/guild)`;
reply += `\n\`\`\`\n[${message.__('github')}](${config.get('webserver').domain}/url/github) - [${message.__('invite')}](${config.get('webserver').domain}/url/invite) - [${message.__('guild')}](${config.get('webserver').domain}/url/help) - [${message.__('guildapp')}](${config.get('webserver').domain}/url/guild)`;

const embed = {
embed: {
Expand Down

0 comments on commit 7f2c7f3

Please sign in to comment.