Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var chatHashtags = {
- '#instructions': function() {
- localStorage.setItem('gettingStartedNew', null);
- dialogGettingStarted();
- },
- '#rules': function() {
- dialogRules();
- },
- '#store': function() {
- dialogStore();
- },
- '#shop': function() {
- dialogStore();
- },
- '#global': function() {
- document.getElementById('roomglobal').click();
- },
- '#battle': function() {
- document.getElementById('roombattle').click();
- },
- '#trades': function() {
- document.getElementById('roomtrades').click();
- },
- '#guild': function() {
- document.getElementById('roomguild').click();
- },
- '#discord': function() {
- window.open('https://discord.gg/A4WZ6Gh', '_blank');
- },
- '#forums': function() {
- window.open('https://forum.pokemonrise.com/', '_blank');
- },
- '#leaderboard': function() {
- window.open('https://pokemonrise.com/leaderboard/', '_blank');
- },
- '#map': function() {
- window.open('https://pokemap.site/', '_blank');
- }
- };
- var chatHashtagClick = function(hashtag) {
- if ( hashtag in chatHashtags ) {
- chatHashtags[hashtag]();
- }
- };
- var chatPokemonColor = function(pokemon) {
- 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);
- if ( ivPercentage < 25 ) {// 0% - 24% = gray
- return '#9d9d9d';
- }
- else if ( ivPercentage < 50 ) {// 25% - 49% = white
- return '#ffffff';
- }
- else if ( ivPercentage < 60 ) {// 50% - 59% = green
- return '#1eff00';
- }
- else if ( ivPercentage < 70 ) {// 60% - 69% = blue
- return '#0070dd';
- }
- else if ( ivPercentage < 80 ) {// 70% - 79% = purple
- return '#a335ee';
- }
- else if ( ivPercentage < 90 ) {// 80% - 89% = orange
- return '#ff8000';
- }
- else {// 90% - 100% = yellow
- return '#fff800';
- }
- };
- var convertChatHashtags = function(text) {
- var hashtags = text.match(/\#([0-9a-z]+)/ig);
- for ( var i = 0; hashtags && hashtags.length > 0 && i < hashtags.length; i++ ) {
- if ( hashtags[i] in chatHashtags ) {
- text = text.replace(hashtags[i], '<span class="changeRoom" onclick="chatHashtagClick(\'' + hashtags[i] + '\');">' + hashtags[i] + '</span>');
- }
- }
- return text;
- };
- var convertChatPokemon = function(text, team) {
- for ( var position in team ) {
- if ( team[position] ) {
- 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>');
- }
- }
- return text;
- };
- var convertChatText = function(userId, text, callback) {
- text = convertChatHashtags(text);
- if ( text.match(/\[pokemon=([0-9]+)\]([0-9]+)\[\/pokemon\]/) ) {
- socketAdmin.Send({'a': 'pokemoninfo', 'p': {'user': userId}}, function(info) {
- callback(info.result == 1 ? convertChatPokemon(text, info.team) : text);
- });
- }
- else {
- callback(text);
- }
- };
- convertChatText(56427, 'selling [pokemon=56427]790999[/pokemon] in #trades', function(text) {
- alert(text);// append text to chatbot
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement