Transliterate non-ascii names for channel names properly

master
Miikka Virtanen 2017-07-24 02:41:31 +03:00
parent 1dc21880e2
commit 77b4ed856d
3 changed files with 1758 additions and 2 deletions

1753
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -13,7 +13,8 @@
"humanize-duration": "^3.10.0",
"mime": "^1.3.4",
"moment": "^2.17.1",
"public-ip": "^2.0.1"
"public-ip": "^2.0.1",
"transliteration": "^1.6.2"
},
"devDependencies": {
"eslint": "^3.9.1"

View File

@ -1,4 +1,5 @@
const Eris = require('eris');
const transliterate = require('transliteration');
const utils = require('./utils');
const jsonDb = require('./jsonDb');
const config = require('../config');
@ -69,8 +70,9 @@ function getForUser(bot, user, allowCreate = true, originalMessage = null) {
if (! allowCreate) return null;
// Channel names are particularly picky about what characters they allow...
let cleanName = user.username.replace(/[^a-zA-Z0-9]/ig, '').toLowerCase().trim();
let cleanName = transliterate.slugify(user.username);
if (cleanName === '') cleanName = 'unknown';
cleanName = cleanName.slice(0, 95); // Make sure the discrim fits
const channelName = `${cleanName}-${user.discriminator}`;