CoinChat Color Handling


SUBMITTED BY: Guest

DATE: Aug. 30, 2013, 3:07 p.m.

FORMAT: JavaScript

SIZE: 999 Bytes

HITS: 1001

  1. //contains is used for checking if a specific term is anywhere in a string. Useful when you don't have a command that
  2. //requires parameters, such as !help
  3. function contains(string, terms){
  4. for(var i=0; i<terms.length; i++){
  5. if(string.toLowerCase().indexOf(terms[i].toLowerCase()) == -1){
  6. return false;
  7. }
  8. }
  9. return true;
  10. }
  11. //example:
  12. if(contains(data.message, ["!help"]){
  13. //do something there
  14. }
  15. /*stripHTML (I haven't really used this, so not sure if it will work; found on github) is used to remove the html tags
  16. that are sent to the client to show the color (code source: https://github.com/whiskers75/whiskdicebot/blob/master/bot.js)*/
  17. function stripHTML(html) {
  18. return html.replace(/<\/?([a-z][a-z0-9]*)\b[^>]*>?/gi, '');
  19. }
  20. //example:
  21. if(stripHTML(data.message).split(" ")[0] == "!tip"){//if the first 'word' of the command without the html is '!tip'
  22. //do stuff here
  23. }
  24. }

comments powered by Disqus