Author Topic: Color Expressions  (Read 2774 times)

DarkStar

  • Full Member
  • ***
  • Posts: 135
  • Scripts for Praise
    • CorpseCorp
Color Expressions
« on: October 28, 2008, 01:42:14 AM »
This script will add colors to words you say. It is made using regular expressions so you can expand it quite a bit if you know what you are doing. To add an expression you simply add the line

Code: [Select]
Expressions.Add "my expression", "color code"
In the designated spot. If you need help, type "/express help". Any further questions please post here, and bug reports would be appreciated.

Code: [Select]
Dim Expression
Set Expressions = CreateObject("Scripting.Dictionary")

' Below is where you add your own expressions

Expressions.Add "white", "0"
Expressions.Add "black", "1"
Expressions.Add "red", "4"
Expressions.Add "maroon", "5"
Expressions.Add "purple", "6"
Expressions.Add "orange", "7"
Expressions.Add "yellow", "8"
Expressions.Add "green", "9"
Expressions.Add "teal", "10"
Expressions.Add "cyan", "11"
Expressions.Add "blue", "12"
Expressions.Add "pink", "13"
Expressions.Add "gray", "14"
Expressions.Add "silver", "15"

' Above is where you add your own expressions





Dim power
Dim wholewords
Dim IgnoreCase

power = int(GetIniFile("express.ini","settings","power",1))
wholewords = int(GetIniFile("express.ini","settings","wholewords",1))
ignorecase = int(GetIniFile("express.ini","settings","ignorecase",1))


Function OUTTEXT(Text)
if left(lcase(Text),8)="/express" then
  args = lcase(Mid(Text,10))
  Select Case args
    Case "on"
      Power = 1
      WriteIniFile "express.ini","settings","power",1
      Echo "Color expressions are now on","-a"
    Case "off"
      Power = 0
      WriteIniFile "express.ini","settings","power",0
      Echo "Color expressions are now off","-a"
    Case "case"
      if IgnoreCase=1 then
        IgnoreCase = 0
        WriteIniFile "express.ini","settings","ignorecase",0
        Echo "Color expressions are now case sensitive by default.","-a"
      else
        IgnoreCase = 1
        WriteIniFile "express.ini","settings","ignorecase",1
        Echo "Color expressions are now case insensitive by default.","-a"
      end if
    Case "whole"
      if WholeWords=1 then
        WholeWords = 0
        WriteIniFile "express.ini","settings","WholeWords",0
        Echo "Color expressions will now match partial results by default.","-a"
      else
        WholeWords = 1
        WriteIniFile "express.ini","settings","WholeWords",1
        Echo "Color expressions will now match whole words only.","-a"
      end if
    Case "help"
      Echo "Color Expressions by 9,1Dark`Star","-a"
      Echo "   /express on       -> Turn this script on","-a"
      Echo "   /express off       -> Turn this script off","-a"
      Echo "   /express case    -> Toggle Case-Sensitivity on/off","-a"
      Echo "   /express whole  -> Toggle whole word matching on/off","-a"
      Echo "Tip: Pressing ctrl+o at the beginning of your message can temporarily turn off this script.","-a"
     
    Case ""
      Msg = "Color expressions are: "
      if Power=1 then Msg = Msg & "on;"
      If Power=0 then Msg = Msg & "off;"
      if IgnoreCase=1 then Msg = Msg & " Expressions are case insensitive"
      if IgnoreCase=0 then Msg = Msg & " Expressions are case sensitive"
      if WholeWords=1 then Msg = Msg & " and matching whole words only."
      Echo Msg,"-a"
      Echo "For help, type '/express help'","-a"
    Case Else
      Echo "For help, type '/express help'","-a"
  End Select
elseif power=0 then
  OUTTEXT = Text
elseif left(Text,1)="" then
  OUTTEXT = Mid(Text,2)
else
  Set Regex = new RegExp
  Regex.Global = True
  if ignorecase then Regex.IgnoreCase = True
  For Each Expression in Expressions.keys
    if wholewords=1 then
      Regex.pattern = "\b" & Expression & "\b"
    else
      Regex.pattern = Expression
    end if
    Set matches = Regex.Execute(Text)
    For Each Match in matches
      Text = Replace(Text,Match,"" & Expressions.item(Expression) & match & "",1,1)
    Next
  Next
  OUTTEXT = Text
end if
End Function
This message brought to you by the Wonderful Wizard of Oz.

DarkStar

  • Full Member
  • ***
  • Posts: 135
  • Scripts for Praise
    • CorpseCorp
Re: Color Expressions
« Reply #1 on: October 28, 2008, 01:45:20 AM »
Also, if you have an idea for something you want to match but not quite sure how to write the regular expression, post your idea and myself (and others im sure) will try to help you.
This message brought to you by the Wonderful Wizard of Oz.