Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async handleMessage (bot, sender, channel, isDirect, msg) {
// Ignore ourself.
if (sender === bot.identity.id || sender === bot.identity.name) return
const {mbMeta} = bot
const team = bot.identifyTeam()
const shouldLearn = isDirect || mbMeta.ambient // Should we be learning factoids?
const shouldReply = isDirect || !mbMeta.direct // Should we reply to this?
const isVerbose = mbMeta.verbose // TODO: Combine with shouldLearn
// Sometimes Slack sends HTML entities.
msg = Entities.decode(msg)
// Basic input sanitization.
msg = msg.substr(0, MAX_FACTOID_SIZE).trim().replace(/\0/g, '').replace(/\n/g, ' ')
// Simple reply helper.
const reply = text => bot.reply({channel}, {text})
// Used to parse a factoid's contents and reply with it.
const parseAndReply = async (key, value, tell = null) => {
// Factoids are stored as { key: "foo", value: "is bar" }
let [, verb, rest] = Array.from(value.match(/^(is|are)\s+(.*)/i))
value = rest
// Split on |, but don't split on \|. Use an HTML entity as a separator.
value = value.replace(/\\\|/g, '\\|')
value = this.oneOf(value.split(/\|/i)).trim()
game[id].correctId = 0;
}
else {
// Sort the answers in reverse alphabetical order.
answers.sort();
answers.reverse();
for(var i = 0; i <= answers.length-1; i++) {
answers[i] = answers[i].toString();
if(answers[i] === correct_answer) {
game[id].correctId = i;
}
answerString = `${answerString}**${Letters[i]}:** ${entities.decode(answers[i])}${getConfigVal("debug-mode")&&i===game[id].correctId?" *(Answer)*":""}\n`;
}
}
var categoryString = entities.decode(question.category);
var timer = getConfigVal("round-length", channel);
if(gameMode === 2) {
// Hangman games get an extra ten seconds for balance.
timer = timer+10000;
}
var infoString = "";
if(!scheduled) {
infoString = "\n";
Trivia.parseAnswerHangman = function(str, id, userId, username, scoreValue) {
var input = str.toLowerCase();
// Decode and remove all non-alphabetical characters
var answer = entities.decode(game[id].answer).toLowerCase().replace(/\W/g, "");
// Return -1 if the input is a command.
// If the input is much longer than the actual answer, assume that it is not an attempt to answer.
if(input.startsWith(getConfigVal("prefix", id)) || input.length > answer.length*2) {
return -1;
}
if(input.replace(/\W/g, "") === answer) {
return Trivia.parseAnswer(Letters[game[id].correctId], id, userId, username, scoreValue);
}
else {
// The string doesn't match, so we'll pass the first incorrect answer.
var incorrect = Letters.slice(0); // Copy to avoid modifying it
incorrect.splice(game[id].correctId, 1);
return Trivia.parseAnswer(incorrect[0], id, userId, username, scoreValue);
}
case "hard":
color = 14164000;
break;
}
}
game[id].color = color;
var answerString = "";
if(gameMode === 2) {
var answer = entities.decode(correct_answer);
var obscuredAnswer = createObscuredAnswer(answer);
answerString = obscuredAnswer;
if(getConfigVal("debug-mode")) {
answerString = `${answerString} *(Answer: ${entities.decode(correct_answer)})*`;
}
game[id].correctId = 0;
}
else {
// Sort the answers in reverse alphabetical order.
answers.sort();
answers.reverse();
for(var i = 0; i <= answers.length-1; i++) {
answers[i] = answers[i].toString();
if(answers[i] === correct_answer) {
game[id].correctId = i;
}
replace ( match, $1 ) {
init ();
const id = `mermaid-${CRC32.str ( $1 )}`;
try {
const svg = mermaid.render ( id, entities.decode ( $1 ) );
return `<div class="mermaid">${svg}</div>`;
} catch ( e ) {
console.error ( `[mermaid] ${e.message}` );
$(`#${id}`).remove ();
return `<p class="text-warning">[mermaid error: ${e.message}]</p>`;
}
}
}];
highlight ( str: string, language?: string ): string {
if ( !language ) return str;
const lang = Highlighter.languagesAliases[language] || language;
if ( !Highlighter.initLanguage ( lang ) ) return str;
return Prism.highlight ( entities.decode ( str ), Prism.languages[language], language );
}
exports.getVideoDescription = (html) => {
const regex = /(.+?)<\/p>[\n\r\s]*?<\/div>/im;
const description = html.match(regex);
return description ?
Entities.decode(util.stripHTML(description[1])) : '';
};
request(splitmes[i], function (error, response, body) {
if (!error && response.statusCode === 200) {
//split at <title>
var match = re.exec(body);
if (match && match[2]) {
//send title message
var ln = "" + match[2];
that._sendMessageAfterDelay(toId, ent.decode(ln));
}
match = re.exec(body);
}
});
}</title>
changeHandler(value) {
this.setState({code: AllHtmlEntities.decode(value)});
}
}
this.message = this.message.replace(/\$spotifySong/g, format.replace(/\$song/g, spotifySong.song).replace(/\$artist/g, spotifySong.artist));
} else {this.message = this.message.replace(/\$spotifySong/g, translate('songs.not-playing'))};
if (songs.enabled
&& this.message.includes('$ytSong')
&& Object.values(songs.isPlaying).find(o => o)) {
let currentSong = _.get(JSON.parse(await songs.currentSong), 'title', translate('songs.not-playing'));
if (opts.escape) {
currentSong = currentSong.replace(new RegExp(opts.escape, 'g'), `\\${opts.escape}`);
}
this.message = this.message.replace(/\$ytSong/g, currentSong);
} else {this.message = this.message.replace(/\$ytSong/g, translate('songs.not-playing'))};
return Entities.decode(this.message);
}