Changeset 44

Show
Ignore:
Timestamp:
07/24/07 16:22:56 (18 months ago)
Author:
scott
Message:

Merged live copy of awkbot into repository

  • Moved awkpaste.awk into lib/ where it belongs
Location:
trunk/awkbot
Files:
5 modified
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/awkbot/bin/awkpp.awk

    r8 r44  
    1010#include <ord.awk> 
    1111#include <assert.awk> 
    12 #include <config.awk> 
     12# #include <config.awk> 
    1313#include <getopt.awk> 
    1414#define STRAPPED 1 
  • trunk/awkbot/etc/awkbot.conf

    r8 r44  
    22# IRC Stuff 
    33<irc> 
    4     nickname awkbot 
    5     altnick awkbot_ 
     4    nickname awkbot-test 
     5    altnick awkbot_test 
    66    username awkbot 
    77    realname AWK IRC bot 
     
    1414#    channel blacksun 
    1515    debug 1 
    16     startup PRIVMSG NickServ :identify darwin 
     16#    startup PRIVMSG NickServ :identify darwin 
    1717</irc> 
    1818 
  • trunk/awkbot/lib/awkbot.awk

    r43 r44  
    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  
    90     if (substr(arg[1], 0, length(irc["nickname"])) == irc["nickname"]) { 
     84    # A special case... 
     85    if (substr(arg[1], 0, length(irc["nickname"])) == irc["nickname"] && 
     86            arg[1] !~ irc["nickname"] "\\+\\+") { 
    9187        direct  = 1 
    9288        shift(arg) 
    93         c_msg   = join(arg, 0, argc, OFS) 
     89 
     90        # Unfortunately, the API doesn't tell me how many arguments are 
     91        # available...but I need the number of arguments to join.  I might want 
     92        # to fix # this some day. 
     93        argc = 0 
     94        for (key in arg) argc++  
     95 
     96        c_msg   = join(arg, 1, argc + 1, OFS) 
    9497    } 
    9598    else { 
     
    114117        } 
    115118        # It's only numbers and stuff 
    116         else if (c_msg ~ /^[0-9*+\/() -]*$/) { 
     119        else if (c_msg ~ /^[0-9^.*+\/() -]*$/) { 
    117120            action = "bc -q" 
    118             print c_msg |& action 
     121            print "scale=10" |& action 
     122            print c_msg      |& action 
     123            print "quit"     |& action 
    119124            action |& getline a 
    120125            close(action) 
    121             irc_privmsg(target, address a) 
     126            irc_privmsg(target, address (a + 0))  
     127                # Coerce the result into an array 
    122128        } 
    123129        else { 
     
    131137    if (match(arg[1], /^(.*)--$/, t)) awkbot_db_karma_dec(t[1]) 
    132138 
    133     if (arg[1] == "awkdoc") 
    134         irc_privmsg(target, address awkdoc(arg[2])) 
     139    if (arg[1] == "awkdoc") { 
     140        if (arg[2]) { 
     141            irc_privmsg(target, address awkdoc(arg[2])) 
     142        } 
     143        else { 
     144            irc_privmsg(target, address "Usage is awkdoc < identifier >") 
     145        } 
     146    } 
     147    else if (arg[1] == "awkinfo") { 
     148        if (arg[2]) { 
     149            a = awkbot_db_info(arg[2]) 
     150 
     151            if (a) { 
     152                irc_privmsg(target, address a) 
     153            } 
     154            else { 
     155                irc_privmsg(target, address "I don't know anything about " \ 
     156                        arg[2]) 
     157            } 
     158        } 
     159        else { 
     160            irc_privmsg(target, address "Usage is awkinfo < keyword >") 
     161        } 
     162    } 
    135163} 
    136164 
  • trunk/awkbot/lib/awkbot_db_mysql.awk

    r8 r44  
    7474function awkbot_db_forget (question) { 
    7575    mysql_finish(mysql_query("DELETE FROM qna WHERE question = " \ 
    76         mysql_quote(question))) 
     76                mysql_quote(question))) 
    7777    return 1 
    7878} 
     79 
     80function awkbot_db_info (keyword    ,result,rv,row) { 
     81    rv = mysql_query("select keyword, text from info where keyword like " \ 
     82            mysql_quote(keyword "%")) 
     83 
     84    if (mysql_fetch_assoc(rv, row)) {  
     85        result = row["keyword"] row["text"] 
     86    } 
     87    else { 
     88        result = 0 
     89    } 
     90 
     91    mysql_finish(rv) 
     92 
     93    return result 
     94} 
  • trunk/awkbot/lib/awkpaste.awk

    r8 r44  
    11#!/usr/bin/awk -f 
    22 
     3#include <cgi-lib.awk> 
     4 
    35BEGIN { 
    4     params(Query) 
    5     for (key in Query) { 
    6         print key, ":", Query[key] 
     6    cgi_params(query) 
     7    cgi_headers("text/plain") 
     8 
     9    for (key in query) { 
     10        print key, ":", query[key] 
    711    } 
    812} 
  • trunk/awkbot/lib/cgi-lib.awk

    r8 r44  
    1 #!/usr/bin/awk -f 
    2  
    31BEGIN { 
    42    if (ENVIRON["REQUEST_METHOD"] == "POST")  
     
    64    if (ENVIRON["REQUEST_METHOD"] == "GET") 
    75        _cgilib_in = ENVIRON["QUERY_STRING"] 
     6 
     7# Set this globally so we don't have to ensure it happens anywhere else... 
     8    ORS = "\r\n" 
    89} 
    910 
    10 function params (Query    ,Each,Pairs,i) { 
    11     split(_cgilib_in, Pairs, /\&/) 
     11function cgi_params (query    ,each,pairs,i) { 
     12    split(_cgilib_in, pairs, /\&/) 
    1213    i = 0     
    13     while (Pairs[++i]) { 
    14         split(Pairs[i], Each, /=/) 
    15         Query[Each[1]] = Each[2] 
     14    while (pairs[++i]) { 
     15        split(pairs[i], each, /=/) 
     16        query[each[1]] = each[2] 
    1617    } 
    1718} 
     19 
     20function cgi_headers (content_type, headers) { 
     21    print "Content-Type:", content_type 
     22     
     23    for (key in headers) { 
     24        print key ":", headers[key] 
     25    } 
     26 
     27    printf ORS 
     28}