Changeset 44
- Timestamp:
- 07/24/07 16:22:56 (18 months ago)
- Location:
- trunk/awkbot
- Files:
-
- 5 modified
- 1 moved
-
bin/awkpp.awk (modified) (1 diff)
-
etc/awkbot.conf (modified) (2 diffs)
-
lib/awkbot.awk (modified) (3 diffs)
-
lib/awkbot_db_mysql.awk (modified) (1 diff)
-
lib/awkpaste.awk (moved) (moved from trunk/awkbot/awkpaste.awk) (1 diff)
-
lib/cgi-lib.awk (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/awkbot/bin/awkpp.awk
r8 r44 10 10 #include <ord.awk> 11 11 #include <assert.awk> 12 # include <config.awk>12 # #include <config.awk> 13 13 #include <getopt.awk> 14 14 #define STRAPPED 1 -
trunk/awkbot/etc/awkbot.conf
r8 r44 2 2 # IRC Stuff 3 3 <irc> 4 nickname awkbot 5 altnick awkbot_ 4 nickname awkbot-test 5 altnick awkbot_test 6 6 username awkbot 7 7 realname AWK IRC bot … … 14 14 # channel blacksun 15 15 debug 1 16 startup PRIVMSG NickServ :identify darwin16 # startup PRIVMSG NickServ :identify darwin 17 17 </irc> 18 18 -
trunk/awkbot/lib/awkbot.awk
r43 r44 82 82 else target = nick 83 83 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"] "\\+\\+") { 91 87 direct = 1 92 88 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) 94 97 } 95 98 else { … … 114 117 } 115 118 # It's only numbers and stuff 116 else if (c_msg ~ /^[0-9 *+\/() -]*$/) {119 else if (c_msg ~ /^[0-9^.*+\/() -]*$/) { 117 120 action = "bc -q" 118 print c_msg |& action 121 print "scale=10" |& action 122 print c_msg |& action 123 print "quit" |& action 119 124 action |& getline a 120 125 close(action) 121 irc_privmsg(target, address a) 126 irc_privmsg(target, address (a + 0)) 127 # Coerce the result into an array 122 128 } 123 129 else { … … 131 137 if (match(arg[1], /^(.*)--$/, t)) awkbot_db_karma_dec(t[1]) 132 138 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 } 135 163 } 136 164 -
trunk/awkbot/lib/awkbot_db_mysql.awk
r8 r44 74 74 function awkbot_db_forget (question) { 75 75 mysql_finish(mysql_query("DELETE FROM qna WHERE question = " \ 76 mysql_quote(question)))76 mysql_quote(question))) 77 77 return 1 78 78 } 79 80 function 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 1 1 #!/usr/bin/awk -f 2 2 3 #include <cgi-lib.awk> 4 3 5 BEGIN { 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] 7 11 } 8 12 } -
trunk/awkbot/lib/cgi-lib.awk
r8 r44 1 #!/usr/bin/awk -f2 3 1 BEGIN { 4 2 if (ENVIRON["REQUEST_METHOD"] == "POST") … … 6 4 if (ENVIRON["REQUEST_METHOD"] == "GET") 7 5 _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" 8 9 } 9 10 10 function params (Query ,Each,Pairs,i) {11 split(_cgilib_in, Pairs, /\&/)11 function cgi_params (query ,each,pairs,i) { 12 split(_cgilib_in, pairs, /\&/) 12 13 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] 16 17 } 17 18 } 19 20 function 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 }