Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // from https://epicmafia.com/javascripts/m/mafia_game.js?1557699857?1557699857
- // using this NLP library: https://github.com/spencermountain/compromise
- add_role_hoverables = function(msg) {
- var nouns, regex, valid_aliases;
- // replacing the line below with 'nouns = msg.split(' ');' would remove most of the current problems, as far as I can tell - Travis
- nouns = nlp(msg).nouns().out("array");
- valid_aliases = nouns.map(function(_this) {
- return function(noun) {
- var ltoken;
- ltoken = noun.toLowerCase();
- if (ROLE_ALIASES_TO_ID[ltoken]) {
- return ltoken
- } else {
- return null
- }
- }
- }(this)).filter(function(_this) {
- return function(alias) {
- return Boolean(alias)
- }
- }(this));
- if (valid_aliases.length === 0) {
- return msg
- }
- regex = new RegExp("(" + valid_aliases.join("|") + ")","ig");
- msg = msg.replace(regex, function(_this) {
- return function(substring, match) {
- var id;
- id = ROLE_ALIASES_TO_ID[match.toLowerCase()];
- if (id == null) {
- return substring
- }
- return role_description_tmpl({
- alias: match,
- id: id
- })
- }
- }(this));
- return msg
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement