2 # Thou shalt use a fixed tab size of 8
15 debug("Scrappy bot started.")
17 self
.nickname
= 'Scrappy'
18 self
.username
= 'scrappy'
19 self
.realname
= 'Scrappy Bot'
23 self
.irc
= '' #this will be the socket
24 self
.c
= '' #Thomas, explain this to me later
28 """Parse the commandline args and print a usage message if incorrect."""
29 if len(sys
.argv
) < 3: #Need at least server and nick
33 s
= sys
.argv
[1].split(":", 1)
40 print "Error: Erroneous port."
43 self
.nickname
= sys
.argv
[2]
44 for ch
in sys
.argv
[3:]:
45 self
.chanlist
.append('#%s' % ch
)
48 print 'Usage: %s <server[:port]> <nickname> [channel 1 channel 2 ... channelN]' % sys
.argv
[0]
52 self
.irc
= irclib_scrappy
.IRC()
54 self
.c
= self
.irc
.server().connect(self
.server
, self
.port
, self
.nickname
)
55 except irclib
.ServerConnectionError
, x
:
58 #if all goes well, register handlers
59 self
.c
.add_global_handler("welcome", self
.on_connect
)
60 self
.c
.add_global_handler("disconnect", self
.on_disconnect
)
61 self
.c
.add_global_handler("privmsg", self
.on_privmsg
)
62 self
.c
.add_global_handler("pubmsg", self
.on_pubmsg
)
64 self
.irc
.process_forever()
69 def on_connect(self
, c
, event
):
70 for ch
in self
.chanlist
:
71 if irclib_scrappy
.is_channel(ch
) :
74 def on_pubmsg(self
, c
, event
):
75 arg
= event
.arguments()[0]
78 cmd
= arg
.split(cmdchar
)[1]
82 def on_privmsg(self
, c
, event
):
83 cmd
= event
.arguments()[0]
86 def on_disconnect(self
, c
, event
):
91 if(__name__
== "__main__"):
93 #if(__name__ == "__main__"):
95 # if len(sys.argv) < 4:
96 # print "Usage: " + sys.argv[0] + " <server[:port]> <nickname> <channel> [channel2 channel3 ... channelN]"
99 # s = sys.argv[1].split(":", 1)
106 # print "Error: Erroneous port."
111 # nickname = sys.argv[2]
113 # irc = irclib_scrappy.IRC()
116 # c = irc.server().connect(server, port, nickname)
117 # except irclib.ServerConnectionError, x:
121 # c.add_global_handler("welcome", on_connect)
122 # c.add_global_handler("disconnect", on_disconnect)
123 # c.add_global_handler("privmsg", on_privmsg)
124 # c.add_global_handler("pubmsg", on_pubmsg)
126 # irc.process_forever()