Advertisement
Sivart

Epicmafia Keyword Detection

May 13th, 2019
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // from https://epicmafia.com/javascripts/m/mafia_game.js?1557699857?1557699857
  2. // using this NLP library: https://github.com/spencermountain/compromise
  3.  
  4. add_role_hoverables = function(msg) {
  5.     var nouns, regex, valid_aliases;
  6.     // replacing the line below with 'nouns = msg.split(' ');' would remove most of the current problems, as far as I can tell - Travis
  7.     nouns = nlp(msg).nouns().out("array");
  8.     valid_aliases = nouns.map(function(_this) {
  9.         return function(noun) {
  10.             var ltoken;
  11.             ltoken = noun.toLowerCase();
  12.             if (ROLE_ALIASES_TO_ID[ltoken]) {
  13.                 return ltoken
  14.             } else {
  15.                 return null
  16.             }
  17.         }
  18.     }(this)).filter(function(_this) {
  19.         return function(alias) {
  20.             return Boolean(alias)
  21.         }
  22.     }(this));
  23.     if (valid_aliases.length === 0) {
  24.         return msg
  25.     }
  26.     regex = new RegExp("(" + valid_aliases.join("|") + ")","ig");
  27.     msg = msg.replace(regex, function(_this) {
  28.         return function(substring, match) {
  29.             var id;
  30.             id = ROLE_ALIASES_TO_ID[match.toLowerCase()];
  31.             if (id == null) {
  32.                 return substring
  33.             }
  34.             return role_description_tmpl({
  35.                 alias: match,
  36.                 id: id
  37.             })
  38.         }
  39.     }(this));
  40.     return msg
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement