HomeCalendarFAQSearchMemberlistUsergroupsYoutubeRegisterLog in

Photobucket
Pokemon Showdown!
Support Breakdown by clicking below


Share | 
 

 Code for MOTD Script

View previous topic View next topic Go down 
AuthorMessage
Orivexes
Creative
Creative
avatar

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

PostSubject: Code for MOTD Script   Tue 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!

_________________
My Pokemon Showdown! server: [b]IS GONE FOREVER HAHAHAHAHA
My tumblr (pokemon/homestuck fanart): http://igobyjoe.tumblr.com

Feel free to contact me with requests for art or Pokemon Showdown modifications.


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
View user profile http://play.pokemonshowdown.com/~~oriserver
 
Code for MOTD Script
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» Awesome (FREE) gun script!
» Walking Animation Script(Help)
» Emoticon Code from Neopets!
» JOIN THE MOST BEASTLY DOJO WITH THE CODE: AFAEAHGE
» OZFM - Driver Code of Conduct

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