Skip to content

Commit

Permalink
filter and encode username to prevent unicode crash, fix a typo
Browse files Browse the repository at this point in the history
  • Loading branch information
Khaaz committed Nov 12, 2018
1 parent 2d0f9fe commit d9e75cc
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const config = require('./config.json')

const link = {};

const filterUsername = /[A-Za-z0-9_!?{}[\]() -,.]*/g

const bot = new Client(config.token, {
defaultImageFormat: 'png',
defaultImageSize: 1024,
Expand Down Expand Up @@ -33,25 +35,26 @@ bot.once('ready',() => {

async function triggerWH(guild, user, content) {
try {
const username = user.username.match(filterUsername).join('');
await bot.executeWebhook(link[guild].whID, link[guild].whToken, {
username: `${user.username}#${user.discriminator}`,
username: `${username}#${user.discriminator}`,
avatarURL: user.avatarURL,
content: content,
});
} catch (err) {
const botGuild = bot.guilds.get(guild.guildID);
const botGuild = bot.guilds.get(link[guild].guildID);
const errMsg = botGuild
? `WebHook unavailable in ${botGuild.name}.`
: `Guild unavailable: ${guild.guildID}.`

console.log(errMsg);

for (const guild in link) {
if (link[guild].guildID === guild.guildID) {
for (const g in link) {
if (link[g].guildID === guild.guildID) {
continue;
}
try {
await bot.executeWebhook(link[guild].whID, link[guild].whToken, {
await bot.executeWebhook(link[g].whID, link[g].whToken, {
username: bot.user.username,
avatarURL: bot.user.avatarURL,
content: errMsg,
Expand Down

0 comments on commit d9e75cc

Please sign in to comment.