2 # Thou shalt use a fixed tab size of 8
13 def externfunc(c
,list):
16 if list[4] == "deadline" and list[3]:
17 c
.privmsg(list[0],"The deadline for SoC has expired.")
23 debug("Scrappy bot started.")
25 self
.nickname
= 'Scrappy'
26 self
.username
= 'scrappy'
27 self
.realname
= 'Scrappy Bot'
31 self
.irc
= '' #this will be the socket
32 self
.c
= '' #Thomas, explain this to me later
34 #Experimental stuff for dynamic modules
36 self
.privmsg_events
= []
37 self
.pubmsg_events
= []
38 self
.onload_events
= []
39 self
.onquit_events
= []
40 #self.what_other_events? = []
42 #load modules(currently in main())
44 self
.onload_events
.append(loadme
)
52 """Parse the commandline args and print a usage message if incorrect."""
53 if len(sys
.argv
) < 3: #Need at least server and nick
57 s
= sys
.argv
[1].split(":", 1)
64 print "Error: Erroneous port."
67 self
.nickname
= sys
.argv
[2]
68 for ch
in sys
.argv
[3:]:
69 self
.chanlist
.append('#%s' % ch
)
71 def print_usage(self
):
72 print 'Usage: %s <server[:port]> <nickname> [channel 1 channel 2 ... channelN]' % sys
.argv
[0]
76 self
.irc
= irclib_scrappy
.IRC()
78 self
.c
= self
.irc
.server().connect(self
.server
,
79 self
.port
, self
.nickname
,
80 username
=self
.username
,ircname
=self
.realname
)
81 except irclib_scrappy
.ServerConnectionError
, x
:
84 #if all goes well, register handlers
85 self
.c
.add_global_handler("welcome", self
.on_connect
)
86 self
.c
.add_global_handler("disconnect", self
.on_disconnect
)
87 self
.c
.add_global_handler("privmsg", self
.on_privmsg
)
88 self
.c
.add_global_handler("pubmsg", self
.on_pubmsg
)
90 #register some phony modules for testing
91 self
.register_module("My phony module", 'foo', 'foo')
92 self
.register_module("Another phony module", 'foo', 'foo')
93 self
.pubmsg_events
.append(externfunc
)
94 self
.pubmsg_events
.append(deadline
)
95 self
.privmsg_events
.append(deadline
)
98 #nothng after this executes
99 self
.irc
.process_forever()
105 def on_connect(self
, c
, event
):
106 for ch
in self
.chanlist
:
107 if irclib_scrappy
.is_channel(ch
) :
110 def on_pubmsg(self
, c
, event
):
111 arg
= event
.arguments()[0]
114 nick
= irclib_scrappy
.nm_to_n(event
.source())
115 user
= irclib_scrappy
.nm_to_u(event
.source())
116 host
= irclib_scrappy
.nm_to_h(event
.source())
120 if arg
[0] == self
.cmdchar
:
126 #dispatch the command
127 for func
in self
.pubmsg_events
:
128 func(c
,[nick
,user
,host
,iscmd
,cmd
])
130 def on_privmsg(self
, c
, event
):
131 cmd
= event
.arguments()[0]
134 nick
= irclib_scrappy
.nm_to_n(event
.source())
135 user
= irclib_scrappy
.nm_to_u(event
.source())
136 host
= irclib_scrappy
.nm_to_h(event
.source())
138 if cmd
[0] == self
.cmdchar
:
139 c
.privmsg(nick
,"You privmsged me, you don't need to " +
140 "prefix commands with %s" % self
.cmdchar
)
145 #dispatch the command
146 for func
in self
.privmsg_events
:
147 func(c
,[nick
,user
,host
,iscmd
,cmd
])
150 def on_disconnect(self
, c
, event
):
151 for func
in self
.onquit_events
:
157 for func
in self
.onload_events
:
163 def register_module(self
, name
, eventlist
, function
):
164 self
.modulelist
.append(name
)
166 def list_modules(self
):
167 """List currently loaded modules."""
168 for mod
in self
.modulelist
:
172 if(__name__
== "__main__"):