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.")
21 debug("Scrappy bot started.")
23 self
.nickname
= 'Scrappy'
24 self
.username
= 'scrappy'
25 self
.realname
= 'Scrappy Bot'
29 self
.irc
= '' #this will be the socket
30 self
.c
= '' #Thomas, explain this to me later
32 #Experimental stuff for dynamic modules
34 self
.privmsg_events
= []
35 self
.pubmsg_events
= []
36 #self.what_other_events? = []
41 """Parse the commandline args and print a usage message if incorrect."""
42 if len(sys
.argv
) < 3: #Need at least server and nick
46 s
= sys
.argv
[1].split(":", 1)
53 print "Error: Erroneous port."
56 self
.nickname
= sys
.argv
[2]
57 for ch
in sys
.argv
[3:]:
58 self
.chanlist
.append('#%s' % ch
)
60 def print_usage(self
):
61 print 'Usage: %s <server[:port]> <nickname> [channel 1 channel 2 ... channelN]' % sys
.argv
[0]
65 self
.irc
= irclib_scrappy
.IRC()
67 self
.c
= self
.irc
.server().connect(self
.server
,
68 self
.port
, self
.nickname
,
69 username
=self
.username
,ircname
=self
.realname
)
70 except irclib
.ServerConnectionError
, x
:
73 #if all goes well, register handlers
74 self
.c
.add_global_handler("welcome", self
.on_connect
)
75 self
.c
.add_global_handler("disconnect", self
.on_disconnect
)
76 self
.c
.add_global_handler("privmsg", self
.on_privmsg
)
77 self
.c
.add_global_handler("pubmsg", self
.on_pubmsg
)
79 #register some phony modules for testing
80 self
.register_module("My phony module", 'foo', 'foo')
81 self
.register_module("Another phony module", 'foo', 'foo')
82 self
.pubmsg_events
.append(externfunc
)
83 self
.pubmsg_events
.append(deadline
)
84 self
.privmsg_events
.append(deadline
)
87 #nothng after this executes
88 self
.irc
.process_forever()
94 def on_connect(self
, c
, event
):
95 for ch
in self
.chanlist
:
96 if irclib_scrappy
.is_channel(ch
) :
99 def on_pubmsg(self
, c
, event
):
100 arg
= event
.arguments()[0]
103 nick
= irclib_scrappy
.nm_to_n(event
.source())
104 user
= irclib_scrappy
.nm_to_u(event
.source())
105 host
= irclib_scrappy
.nm_to_h(event
.source())
107 if arg
[0] == self
.cmdchar
:
113 #dispatch the command
114 for func
in self
.pubmsg_events
:
115 func(c
,[nick
,user
,host
,iscmd
,cmd
])
117 def on_privmsg(self
, c
, event
):
118 cmd
= event
.arguments()[0]
121 nick
= irclib_scrappy
.nm_to_n(event
.source())
122 user
= irclib_scrappy
.nm_to_u(event
.source())
123 host
= irclib_scrappy
.nm_to_h(event
.source())
125 if cmd
[0] == self
.cmdchar
:
126 c
.privmsg(nick
,"You privmsged me, you don't need to " +
127 "prefix commands with %s" % self
.cmdchar
)
131 #dispatch the command
132 for func
in self
.privmsg_events
:
133 func(c
,[nick
,user
,host
,iscmd
,cmd
])
136 def on_disconnect(self
, c
, event
):
142 def register_module(self
, name
, eventlist
, function
):
143 self
.modulelist
.append(name
)
145 def list_modules(self
):
146 """List currently loaded modules."""
147 for mod
in self
.modulelist
:
151 if(__name__
== "__main__"):