git @ Cat's Eye Technologies mzstorkipiwanbotbotbot / 89a149a
My other bot is also an extremely pointless bot. catseye 9 years ago
2 changed file(s) with 87 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 # Rtype -- an IRC bot written in R, the Language of the Future.
1 # Written by Chris Pressey of Cat's Eye Technologies.
2 # This work is hereby placed in the public domain.
3
4 # This bot's personality is modeled after that of a cat I knew once.
5 # Please forgive its inhospitable nature; it had a hard life.
6
7 args <- commandArgs(trailing=TRUE)
8 if (length(args) != 3) {
9 cat("Usage: R ... --args botname irc.server.net '#channel'\n", file=stderr())
10 quit(status=1)
11 }
12
13 bot <- args[1]
14 server <- args[2]
15 channel <- args[3]
16
17 hunt <- function(haystack, needle) {
18 return(length(grep(needle, haystack, fixed=TRUE)) > 0)
19 }
20
21 irc <- socketConnection(host=server, port=6667, blocking=TRUE, open="a+b")
22
23 shove <- function(s) {
24 cat(s,file=irc)
25 cat(s,file=stderr())
26 }
27
28 action <- function(channel, s) {
29 shove(paste("PRIVMSG", channel, ":\x01ACTION", s, "\x01\n"))
30 }
31
32 grab <- function() {
33 line <- readLines(con=irc, n=1)
34 cat(paste(">", line, "\n"), file=stderr())
35 return(line)
36 }
37
38 state <- 0
39 done <- FALSE
40
41 while (!done) {
42 line <- grab()
43 if (length(line) == 0) { next }
44 if (state == 0) {
45 # I suppose this might only apply to certain servers.
46 # (And to the case where you are not running ident.)
47 loc <- hunt(line, "No Ident response")
48 if (loc) {
49 shove(paste("USER", bot, bot, bot, bot, "\n"))
50 shove(paste("NICK", bot, "\n"))
51 shove(paste("JOIN", channel, "\n"))
52 state <- 1
53 }
54 }
55 if (state == 1) {
56 xform <- gsub('^:(.*?)\\!(.*?)\\s+PRIVMSG\\s+(.*?)\\s+\\:(.*?)$', '\\1\u2603\\2\u2603\\3\u2603\\4', line, perl=TRUE)
57 if (length(xform) == 0) { next }
58 if (xform != line) {
59 parts <- strsplit(xform, '\u2603', fixed=TRUE)
60 nick <- parts[[1]][1]
61 in_channel <- parts[[1]][3]
62 message <- parts[[1]][4]
63 if (in_channel == channel & length(grep(bot, message, fixed=TRUE)) > 0) {
64 choice = sample(1:4, 1)
65 if (choice == 1) {
66 action(channel, paste("scowls at", nick))
67 } else if (choice == 2) {
68 action(channel, paste("groans"))
69 } else if (choice == 3) {
70 action(channel, paste("hisses"))
71 } else if (choice == 4) {
72 shove(paste("PRIVMSG", channel, ":groan\n"))
73 }
74 }
75 }
76 }
77 loc <- hunt(line, "PING")
78 if (loc) {
79 shove("PONG :irc.irc.irc\n")
80 }
81 if (!isOpen(irc)) {
82 done <- TRUE
83 }
84 }
0 #!/bin/sh
1 R --no-restore --no-save --no-readline --slave --file=bot.R --args $*