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
26 #Experimental stuff for dynamic modules
28 #self.privmsg_events = []
29 #self.pubmsg_events = []
30 #self.what_other_events? = []
35 """Parse the commandline args and print a usage message if incorrect."""
36 if len(sys
.argv
) < 3: #Need at least server and nick
40 s
= sys
.argv
[1].split(":", 1)
47 print "Error: Erroneous port."
50 self
.nickname
= sys
.argv
[2]
51 for ch
in sys
.argv
[3:]:
52 self
.chanlist
.append('#%s' % ch
)
55 print 'Usage: %s <server[:port]> <nickname> [channel 1 channel 2 ... channelN]' % sys
.argv
[0]
59 self
.irc
= irclib_scrappy
.IRC()
61 self
.c
= self
.irc
.server().connect(self
.server
, self
.port
, self
.nickname
)
62 except irclib
.ServerConnectionError
, x
:
65 #if all goes well, register handlers
66 self
.c
.add_global_handler("welcome", self
.on_connect
)
67 self
.c
.add_global_handler("disconnect", self
.on_disconnect
)
68 self
.c
.add_global_handler("privmsg", self
.on_privmsg
)
69 self
.c
.add_global_handler("pubmsg", self
.on_pubmsg
)
71 #register some phony modules for testing
72 self
.register_module("My phony module", 'foo', 'foo')
73 self
.register_module("Another phony module", 'foo', 'foo')
76 #nothng after this executes
77 self
.irc
.process_forever()
83 def on_connect(self
, c
, event
):
84 for ch
in self
.chanlist
:
85 if irclib_scrappy
.is_channel(ch
) :
88 def on_pubmsg(self
, c
, event
):
89 arg
= event
.arguments()[0]
90 nick
= irclib_scrappy
.nm_to_n(event
.source())
91 user
= irclib_scrappy
.nm_to_u(event
.source())
92 host
= irclib_scrappy
.nm_to_h(event
.source())
94 if arg
[0] == self
.cmdchar
:
100 def on_privmsg(self
, c
, event
):
101 cmd
= event
.arguments()[0]
102 nick
= irclib_scrappy
.nm_to_n(event
.source())
103 user
= irclib_scrappy
.nm_to_u(event
.source())
104 host
= irclib_scrappy
.nm_to_h(event
.source())
106 #dispatch the command
108 def on_disconnect(self
, c
, event
):
114 def register_module(self
, name
, eventlist
, function
):
115 self
.modulelist
.append(name
)
117 def list_modules(self
):
118 """List currently loaded modules."""
119 for mod
in self
.modulelist
:
123 if(__name__
== "__main__"):