All pastes #973261 Raw Edit

acronym script

public text v1 · immutable
·published 2008-04-06 00:20 UTC
rendered paste body
; initialize the first few acronyms
alias acronym.init {
  ; add the values to our table
  /hadd acronym afk Away From Keyboard
  /hadd acronym brb Be Right Back
  /hadd acronym gtg Got To Go
  /hadd acronym lol Laughing Out Loud
  /hadd acronym ttyl Talk To You Later
}

; Intiilize the table
on *:START: {
  ; create the hash table of 100 items (size of 10)
  /hmake acronym 10
  ; Load our hash file if it's there, other wise initialize the hash table
  if ($isFile(acronyms.hsh)) {
    ; file exists, now we load it
    /hload acronym acronyms.hsh
  }
  else {
    ; the file does not exist.  Now we initialize, and save
    /acronym.init
    /hsave -o acronym acronyms.hsh
  }
}

; Save the table
on *:EXIT: {
  ; save our table on exit
  /hsave -o acronym acronyms.hsh
  ; clear the used memory
  /hfree acronym
}

; replace acronyms with their proper meaning
on *:INPUT:#: {
  ; first make sure the text entered isn't a command
  if ($left($1, 1) !isin $+(/,$readini($mircini, text, commandchar))) {
    ; search for words to replace
    var %w = 1
    var %text
    var %acro = [<acronym>]
    ; loop through each word looking through a match
    while ($gettok($1-, %w, 32) != $null) {
      var %word = $ifmatch
      ; find the word in our table
      if ($hget(acronym, %word) != $null) var %text = %text $replace(%acro, <acronym>, $ifmatch)
      else var %text = %text %word
      ; Increase Counter Variable
      /inc %w
      //echo -a W = %w  TEXT = %text ACRO = %acro  WORD = %word
    }
    ; send the message to the channel
    /msg $chan %text
    ; stop the "double talk"
    /halt
    //echo -a hello?
    //echo -a did it halt? $halted
  }
}