Code:
on 1:Text:!calc *:*: {
  if ($isOnExceptionList($chan)) { halt }
  if ($flood) { halt }
  if ($evilreply) { halt }
  msg # Calc: $2- = $calc($2-)
}


I suspect regex is the best way to help with this, but I don't know how to use regex for this. Reading through information regarding regex I still haven't found what I'm after. I'm looking for a way to take the $2-, and have it find every mathematical operator, change it to the appropriate identifier (deleting all instances of the $ character before doing creating the identifiers), then evaluate the string with $eval prior to using $calc on it. It needs to only match identifiers used for math, or those that I specify if I make custom ones, so as to prevent a type of exploit that would allow a person to run commands I don't want just anyone running (no tricks with $quit or the like). Anyone know how to set this up?

By the way, you can ignore the first 3 lines in the On Text trigger. The first one prevents the script from running in channels where people don't want scripts running, the second one just makes sure I don't get flooded with requests, and the third one is a joke thing I can enable for laughs. The order is intentional, so I don't plan on putting them in the same line.

Edit: I created something with some help in a chat, but it doesn't seem to work.

Code:
alias -l makeIdentifiers {
  var %arg $remove($1-,$chr(36))
  var %regexIdentifierMatch \b[A-Za-z]+\(
  var %matches $regex(Identifiers,%arg,%regexIdentifierMatch)
  echo -s Matches: $+ %matches
  var %a 1
  while (%a <= %matches) {
    var %match $regml(Identifiers,%a)
    echo -s Match: $+ %match
    if ($istok($identifierList,%match,44)) {
      var %arg $replace(%arg,%match,$chr(32) $+ $chr(36) $+ %match)
    }
    inc %a
  }
  return %arg
}

The first echo says one value was matched, but the second echo is blank, it shows Match:, but not the matched value. The string passed through it was ceil(2.5). It seems $regml is returning $null.

Last edited by KageNoOni; 29/05/10 01:39 AM.