diff --git a/src/DMManager.ts b/src/DMManager.ts index b0d6f49..ec83c2d 100644 --- a/src/DMManager.ts +++ b/src/DMManager.ts @@ -1,5 +1,6 @@ import { LocalStorage } from 'yamdbf'; import { Client, Message, Guild, User, TextChannel, DMChannel, Collection, RichEmbed } from 'discord.js'; +import { normalize } from './Util'; export default class DMManager { @@ -76,7 +77,8 @@ export default class DMManager private async createNewChannel(user: User): Promise { const newChannel: TextChannel = await this._guild - .createChannel(`${user.username}-${user.discriminator}`, 'text'); + .createChannel(`${normalize(user.username) || 'unicode'}-${user.discriminator}`, 'text') + .catch(err => console.error(`DMManager: Failed to create channel: '${normalize(user.username)}-${user.discriminator}'`)); this.channels.set(user.id, newChannel); this.storeOpenChannels(); @@ -105,6 +107,7 @@ export default class DMManager { if (message.embeds[0] && message.channel.type !== 'dm') return; if (message.channel.type !== 'dm' && message.guild.id !== this.guild) return; + if (message.guild && message.channel.id === message.guild.id) return; if (message.author.id !== this.client.user.id && !this.channels.has(message.author.id)) await this.createNewChannel(message.author); diff --git a/src/Util.ts b/src/Util.ts new file mode 100644 index 0000000..cbf6fbf --- /dev/null +++ b/src/Util.ts @@ -0,0 +1,8 @@ +/** + * Remove any non alphanumeric characters from the given text + * and lowercase it + */ +export function normalize(text: string): string +{ + return text.toLowerCase().replace(/[^a-z0-9]/g, ''); +} diff --git a/tslint.json b/tslint.json index 7a03064..71513e2 100644 --- a/tslint.json +++ b/tslint.json @@ -62,7 +62,7 @@ ], "typedef": [ "parameter", - "arrow-parameter", + // "arrow-parameter", "call-signature", "member-variable-declaration", "property-declaration",