Breakdown
Would you like to react to this message? Create an account in a few clicks or log in to continue.



 
HomeSearchLatest imagesYoutubeRegisterLog in

Photobucket
Pokemon Showdown!
Support Breakdown by clicking below


 

 Code for MOTD Script

Go down 
AuthorMessage
Orivexes
Creative
Creative
Orivexes


Posts : 26
Rep : 2
Join date : 2012-11-10
Age : 35
Location : CT/MA, US

Code for MOTD Script Empty
PostSubject: Code for MOTD Script   Code for MOTD Script EmptyTue Nov 13, 2012 9:00 pm

Hi guys. Here's my updated code for the MOTD script. I'm not one for keeping version numbers, so just let me know if it has any problems running.

All of this stuff should be put in the chat-commands.js file.

First, add these three functions at the bottom of the file. They're three simple functions that strip out HTML from MOTDs, and make the first URL it sees linkable! (The URL code is something I found online--it was a wee bit complicated to find but thankfully it works really well. I found it here: http://stackoverflow.com/questions/37684/how-to-replace-plain-urls-with-links

Code:
function stripBrackets(target) {
   
   var cmdArr =  target.split("<");
   for(var i = 0; i < cmdArr.length; i++) {
      cmdArr[i] = cmdArr[i].trim();
   }
   return cmdArr[0];
}

function stripBrackets2(target) {
   
   var cmdArr =  target.split(">");
   for(var i = 0; i < cmdArr.length; i++) {
      cmdArr[i] = cmdArr[i].trim();
   }
   return cmdArr[0];
}

function replaceURL(text) {
    var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/i;
    return text.replace(exp,"<a href='$1' target='_blank'>$1</a>");
}

Next, you'll need to add this to the very beginning of the file. It makes some variables that will be used in the actual commands.

Code:
var motd = "";
var motdfreq = 20;
var motdcount = 19;

The following should be placed among the chat commands--it contains the following commands:
  • /motd message will set the message of the day to whatever you type.[/*]
  • /delmotd will remove the message of the day, and it won't show up in the chat.[/*]
  • /motdfreq # will set the frequency of the motd, appearing every # messages[/*]


Code:

/** MOTD START


**/      
   
   case 'motd':
      if (!user.can('announce')) {
         emit(socket, 'console', 'You do not have permissions to change the message of the day.');
         return false;
      }
      if (!target) {
         emit(socket, 'console', 'Proper syntax for this command is: /motd Message');
         return false;
      }
      
      var motda = stripBrackets(target);
      motda = stripBrackets2(motda);
      motd = replaceURL(motda);
      room.addRaw('<div style="background-color:#EEFFEE;border:1px solid #6688AA;padding:2px 4px">' +
         '<b>'+user.name+' has set the Message of the day to: </b><br />' + motd + '</div>');
      return false;
      break;
   
   case 'delmotd':
   case 'rmmotd':
   case 'clearmotd':
      if (!user.can('announce')) {
         emit(socket, 'console', 'You do not have permissions to remove the message of the day.');
         return false;
      }
      motd = "";
      room.addRaw('<div style="background-color:#EEFFEE;border:1px solid #6688AA;padding:2px 4px">' +
         '<b>'+user.name+' has removed the Message of the day.</div>');
      return false;
      break;
      
   case 'motdfreq':
      if (!user.can('announce')) {
         emit(socket, 'console', 'You do not have permissions to change the frequency of the message of the day.');
         return false;
      }
      if (!target) {
         emit(socket, 'console', 'Proper syntax for this command is: /motdfreq #');
         return false;
      }
      if (isNaN(target)) {
         emit(socket, 'console', 'The syntax for this command is /motdfreq #.  Stop trying to be clever. :P');
         return false;
      }   
      
      var targetnum = parseInt(target);      
      motdfreq = targetnum;
      motdcount = targetnum - 1;

      
         room.addRaw('<div style="background-color:#EEFFEE;border:1px solid #6688AA;padding:2px 4px">' +
         '<b>'+user.name+' has set the Message of the Day frequency to: </b><br />' + motdfreq + '</div>');
      return false;
      break;

And finally, we need the actual code for displaying the message! I placed it right under the line of code that removes the weird zalgo stuff from text--you can find the spot by looking for the // remove zalgo comment.

Code:
   if (!room.battle) {
      motdcount = motdcount + 1;
      }
   if (motdcount >= motdfreq) {
      motdcount = 0;
      if (!(motd === "") && !room.battle) {
         room.addRaw('<div style="background-color:#DDDDDD;border:1px solid #6688AA;padding:2px 4px">' +
            '<b>Message of the Day: </b><br />' + motd + '</div>');
            }
      }

Let me know how well this works out for you!


Last edited by Orivexes on Tue Nov 13, 2012 9:03 pm; edited 1 time in total (Reason for editing : adding credit)
Back to top Go down
http://play.pokemonshowdown.com/~~oriserver
 
Code for MOTD Script
Back to top 
Page 1 of 1
 Similar topics
-
» Friend Code Thread So We Can All Be Each Other's Franz

Permissions in this forum:You cannot reply to topics in this forum
Breakdown :: Server and Forum Operations :: Reports and Suggestions-
Jump to: