Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var chatHashtags = {
  2.    '#instructions': function() {
  3.       localStorage.setItem('gettingStartedNew', null);
  4.       dialogGettingStarted();
  5.    },
  6.    '#rules': function() {
  7.       dialogRules();
  8.    },
  9.    '#store': function() {
  10.       dialogStore();
  11.    },
  12.    '#shop': function() {
  13.       dialogStore();
  14.    },
  15.    '#global': function() {
  16.       document.getElementById('roomglobal').click();
  17.    },
  18.    '#battle': function() {
  19.       document.getElementById('roombattle').click();
  20.    },
  21.    '#trades': function() {
  22.       document.getElementById('roomtrades').click();
  23.    },
  24.    '#guild': function() {
  25.       document.getElementById('roomguild').click();
  26.    },
  27.    '#discord': function() {
  28.       window.open('https://discord.gg/A4WZ6Gh', '_blank');
  29.    },
  30.    '#forums': function() {
  31.       window.open('https://forum.pokemonrise.com/', '_blank');
  32.    },
  33.    '#leaderboard': function() {
  34.       window.open('https://pokemonrise.com/leaderboard/', '_blank');
  35.    },
  36.    '#map': function() {
  37.       window.open('https://pokemap.site/', '_blank');
  38.    }
  39. };
  40.  
  41. var chatHashtagClick = function(hashtag) {
  42.    if ( hashtag in chatHashtags ) {
  43.       chatHashtags[hashtag]();
  44.    }
  45. };
  46.  
  47. var chatPokemonColor = function(pokemon) {
  48.    var ivPercentage = Math.round(((pokemon.iv_hp + pokemon.iv_atk + pokemon.iv_spd + pokemon.iv_def + pokemon.iv_spatk + pokemon.iv_spdef) / (31 * 6)) * 100);
  49.    if ( ivPercentage < 25 ) {// 0% - 24% = gray
  50.       return '#9d9d9d';
  51.    }
  52.    else if ( ivPercentage < 50 ) {// 25% - 49% = white
  53.       return '#ffffff';
  54.    }
  55.    else if ( ivPercentage < 60 ) {// 50% - 59% = green
  56.       return '#1eff00';
  57.    }
  58.    else if ( ivPercentage < 70 ) {// 60% - 69% = blue
  59.       return '#0070dd';
  60.    }
  61.    else if ( ivPercentage < 80 ) {// 70% - 79% = purple
  62.       return '#a335ee';
  63.    }
  64.    else if ( ivPercentage < 90 ) {// 80% - 89% = orange
  65.       return '#ff8000';
  66.    }
  67.    else {// 90% - 100% = yellow
  68.       return '#fff800';
  69.    }
  70. };
  71.  
  72. var convertChatHashtags = function(text) {
  73.    var hashtags = text.match(/\#([0-9a-z]+)/ig);
  74.    for ( var i = 0; hashtags && hashtags.length > 0 && i < hashtags.length; i++ ) {
  75.       if ( hashtags[i] in chatHashtags ) {
  76.          text = text.replace(hashtags[i], '<span class="changeRoom" onclick="chatHashtagClick(\'' + hashtags[i] + '\');">' + hashtags[i] + '</span>');
  77.       }
  78.    }
  79.    return text;
  80. };
  81.  
  82. var convertChatPokemon = function(text, team) {
  83.    for ( var position in team ) {
  84.       if ( team[position] ) {
  85.          text = text.replace(new RegExp('\\\[pokemon=([0-9]+)\\\]' + team[position].pk + '\\\[\\\/pokemon\\\]', 'g'), '<span class="pokemonView" style="color:' + chatPokemonColor(team[position]) + '!important;" data-user-id="$1" data-pokemon-id="' + team[position].pk + '">' + (team[position].special == 'shiny' ? '[{' + team[position].nickname + '}]' : '[' + team[position].nickname + ']') + '</span>');
  86.       }
  87.    }
  88.    return text;
  89. };
  90.  
  91. var convertChatText = function(userId, text, callback) {
  92.    text = convertChatHashtags(text);
  93.    if ( text.match(/\[pokemon=([0-9]+)\]([0-9]+)\[\/pokemon\]/) ) {
  94.       socketAdmin.Send({'a': 'pokemoninfo', 'p': {'user': userId}}, function(info) {
  95.          callback(info.result == 1 ? convertChatPokemon(text, info.team) : text);
  96.       });
  97.    }
  98.    else {
  99.       callback(text);
  100.    }
  101. };
  102.  
  103. convertChatText(56427, 'selling [pokemon=56427]790999[/pokemon] in #trades', function(text) {
  104.    alert(text);// append text to chatbot
  105. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement