Changeset 43 for trunk

Show
Ignore:
Timestamp:
07/12/07 19:08:23 (17 months ago)
Author:
scott
Message:

Added BC support''

  • Direct messages of any nature, which consist of only numbers mathematical operators and parenthesis are piped to bc -q, and back.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/awkbot/lib/awkbot.awk

    r8 r43  
    7777 
    7878function irc_handler_privmsg (nick, host, recipient, message, arg  \ 
    79     ,direct,target,address,action,t,q,a) { 
     79    ,direct,target,address,action,c_msg,argc,t,q,a) { 
    8080 
    8181    if (recipient ~ /^#/) target = recipient 
    8282    else                  target = nick 
    8383 
     84    # Unfortunately, the API doesn't tell me how many arguments are 
     85    # available...but I need the number of arguments to join.  I might want to 
     86    # fix this some day. 
     87    argc = 0 
     88    for (key in arg) argc++  
     89 
    8490    if (substr(arg[1], 0, length(irc["nickname"])) == irc["nickname"]) { 
    8591        direct  = 1 
    8692        shift(arg) 
     93        c_msg   = join(arg, 0, argc, OFS) 
    8794    } 
    8895    else { 
    8996        direct  = (target != recipient) 
     97        # It's either privmsg, or they're not talking to us, so the clean 
     98        # message is the whole message. 
     99        c_msg   = message 
    90100    } 
    91101 
     
    102112            awkbot_db_answer(arg[1], join(arg, 3, sizeof(arg), " ")) 
    103113            irc_privmsg(target, address "Okay") 
     114        } 
     115        # It's only numbers and stuff 
     116        else if (c_msg ~ /^[0-9*+\/() -]*$/) { 
     117            action = "bc -q" 
     118            print c_msg |& action 
     119            action |& getline a 
     120            close(action) 
     121            irc_privmsg(target, address a) 
    104122        } 
    105123        else {