diff --git a/src/modules/core/index.ts b/src/modules/core/index.ts index 8efc580..eeed825 100644 --- a/src/modules/core/index.ts +++ b/src/modules/core/index.ts @@ -2,11 +2,10 @@ import autobind from 'autobind-decorator'; import Module from '../../module'; import Message from '../../message'; import serifs from '../../serifs'; +import { safeForInterpolate } from '../../utils/safe-for-interpolate'; const titles = ['さん', 'くん', '君', 'ちゃん', '様', '先生']; -const invalidChars = ['@', '#', '*', ':', '(', '[', ' ', ' ']; - export default class extends Module { public readonly name = 'core'; @@ -87,7 +86,7 @@ export default class extends Module { return true; } - if (invalidChars.some(c => name.includes(c))) { + if (!safeForInterpolate(name)) { msg.reply(serifs.core.invalidName); return true; } diff --git a/src/utils/safe-for-interpolate.ts b/src/utils/safe-for-interpolate.ts new file mode 100644 index 0000000..4848a3e --- /dev/null +++ b/src/utils/safe-for-interpolate.ts @@ -0,0 +1,16 @@ +const invalidChars = [ + '@', + '#', + '*', + ':', + '(', + ')', + '[', + ']', + ' ', + ' ', +]; + +export function safeForInterpolate(text: string): boolean { + return !invalidChars.some(c => text.includes(c)); +}