1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
class Addon(object):
def onAddonAdd(self, IRC, **params):
# Stuff you want the Addon to do when added or inserted into the addon
# list of an IRC instance.
print "onAddonAdd:", IRC, params
def onAddonRem(self, IRC):
# Stuff you want the Addon to do when removed from the addon list of an
# IRC instance.
print "onAddonRem:", IRC
def onSessionOpen(self, IRC):
# Called when the thread handling the IRC instance is started.
print "onSessionOpen:", IRC
def onSessionClose(self, IRC):
# Called when the thread handling the IRC instance is terminated.
print "onSessionClose:", IRC
def onConnectAttempt(self, IRC):
# Called when a connection attempt is made.
print "onConnectAttempt:", IRC
def onConnectFail(self, IRC, exc, excmsg, tb):
# Called when a connection fails.
print "onConnectFail:", IRC, exc, excmsg, tb
def onConnect(self, IRC):
# Called when a connection is established.
print "onConnect:", IRC
def onRegistered(self, IRC):
# Called when registration is complete.
print "onRegistered:", IRC
def onDisconnect(self, IRC, expected):
# Called when a connection is terminated.
print "onDisconnect:", IRC
def onRecv(self, IRC, line, origin=None, cmd=None, target=None, targetprefix=None, params=None, extinfo=None):
# Called when a line of data is received from the IRC server. If line also matches ":origin cmd target [params] :[extinfo]",
# then other variables are provided, with origin and target
# automatically converted to Channel and User instances as needed.
pass
def onSend(self, IRC, origin, line, cmd=None, target=None, targetprefix=None, params=None, extinfo=None):
# Called when a line of data is sent to the IRC server. If line also matches "cmd target [params] :[extinfo]",
# then other variables are provided, with target automatically converted to Channel and User instances as needed.
# The variable origin refers to a class instance voluntarily
# identifying itself as that which requested data be sent.
pass
def onMOTD(self, IRC, motdgreet, motd, motdend):
# Called when MOTD is received.
print "onMOTD:", motdgreet
for line in motd:
print line
print motdend
def onJoin(self, IRC, user, channel):
# Called when somebody joins a channel, includes bot.
print "onJoin:", user, channel
def onMeJoin(self, IRC, channel):
# Called when the bot enters the channel.
print "onMeJoin:", channel
def onChanMsg(self, IRC, user, channel, targetprefix, msg):
# Called when someone sends a PRIVMSG to channel.
print "onChanMsg: [%s%s] <%s> %s" % (targetprefix, channel.name, user.nick, msg)
def onChanAction(self, IRC, user, channel, targetprefix, action):
# Called when someone sends an action (/me) to channel.
print "onChanAction: [%s%s] *%s %s" % (targetprefix, channel.name, user.nick, action)
def onSendChanMsg(self, IRC, origin, channel, targetprefix, msg):
# Called when bot sends a PRIVMSG to channel.
# The variable origin refers to a class instance voluntarily
# identifying itself as that which requested data be sent.
print "onSendChanMsg: [%s%s] <%s> %s" % (targetprefix, channel.name, IRC.identity.nick, msg)
def onSendChanAction(self, IRC, origin, channel, targetprefix, action):
# origin is the source of the channel message
# Called when bot sends an action (/me) to channel.
# The variable origin refers to a class instance voluntarily
# identifying itself as that which requested data be sent.
print "onSendChanAction: [%s%s] *%s %s" % (targetprefix, channel.name, IRC.identity.nick, action)
def onPrivMsg(self, IRC, user, msg):
# Called when someone sends a PRIVMSG to the bot.
print "onPrivMsg: <%s> %s" % (user.nick, msg)
def onPrivAction(self, IRC, user, action):
# Called when someone sends an action (/me) to the bot.
print "onPrivAction: *%s %s" % (user.nick, action)
def onSendPrivMsg(self, IRC, origin, user, msg):
# Called when bot sends a PRIVMSG to a user.
# The variable origin refers to a class instance voluntarily
# identifying itself as that which requested data be sent.
print "onSendPrivMsg: <%s> %s" % (IRC.identity.nick, msg)
def onSendPrivAction(self, IRC, origin, user, action):
# Called when bot sends an action (/me) to a user.
# The variable origin refers to a class instance voluntarily
# identifying itself as that which requested data be sent.
print "onSendPrivAction: *%s %s" % (IRC.identity.nick, action)
def onNickChange(self, IRC, user, newnick):
# Called when somebody changes nickname.
print "onNickChange:", user, newnick
def onMeNickChange(self, IRC, newnick):
# Called when the bot changes nickname.
print "onMeNickChange:", newnick
def onPart(self, IRC, user, channel, partmsg):
# Called when somebody parts the channel, includes bot.
print "onPart:", user, channel, partmsg
def onMePart(self, IRC, channel, partmsg):
# Called when the bot parts the channel.
print "onMePart:", channel, partmsg
def onKick(self, IRC, kicker, channel, kicked, kickmsg):
# Called when somebody is kicked from the channel, includes bot.
print "onKick:", kicker, channel, kicked, kickmsg
def onMeKick(self, IRC, channel, kicked, kickmsg):
# Called when the bot kicks somebody from the channel.
print "onMeKick:", channel, kicked, kickmsg
def onMeKicked(self, IRC, kicker, channel, kickmsg):
# Called when the bot is kicked from the channel.
print "onMeKicked:", kicker, channel, kickmsg
def onQuit(self, IRC, user, quitmsg):
# Called when somebody quits IRC.
print "onQuit:", user, quitmsg
def onNames(self, IRC, channel, channame, endmsg, nameslist):
# Called when a NAMES list is received.
print "onNames:", channel, channame, endmsg, nameslist
def onWhois(self, IRC, **whoisdata):
# Called when a WHOIS reply is received.
print "onWhois:", whoisdata
def onWho(self, IRC, params, wholist, endmsg):
# Called when a WHO list is received.
print "onWho:", params
for item in wholist:
print item
print endmsg
def onList(self, IRC, chanlistbegin, chanlist, endmsg):
# Called when a channel list is received.
print "onList:", chanlistbegin
for item in chanlist:
print item
print endmsg
def onTopic(self, IRC, channel, topic):
# Called when channel topic is received via 332 response.
print "onTopic:", channel, topic
def onTopicSet(self, IRC, user, channel, topic):
# Called when channel topic is changed.
print "onChannelSet:", user, channel, topic
def onChanModeSet(self, IRC, user, channel, modedelta):
# Called when channel modes are changed.
# modedelta is a list of tuples of the format ("+x", parameter), ("+x",
# None) if no parameter is provided.
print "onChanModeSet:", user, channel, modedelta
def onChannelModes(self, IRC, channel, modedelta):
# Called when channel modes are received via 324 response.
print "onChannelModes:", channel, modedelta
def onBan(self, IRC, user, channel, banmask):
# Called when a ban is set.
print "onBan:", user, channel, banmask
def onMeBan(self, IRC, user, channel, banmask):
# Called when a ban matching bot is set.
print "Help! I'm being banned!", user, channel, banmask
def onUnban(self, IRC, user, channel, banmask):
# Called when a ban is removed.
print "onUnban:", user, channel, banmask
def onMeUnban(self, IRC, user, channel, banmask):
# Called when a ban on the bot is removed.
print "Squeee!!! I've been unbanned!", user, channel, banmask
def onOp(self, IRC, user, channel, modeuser):
# Called when user gives ops to modeuser is set.
print "onOp:", user, channel, modeuser
def onMeOp(self, IRC, user, channel):
# Called when user ops bot.
print "onMeOp", user, channel
def onDeop(self, IRC, user, channel, modeuser):
# Called when user deops modeuser.
print "onDeop:", user, channel, modeuser
def onMeDeop(self, IRC, user, channel):
# Called when user deops bot.
print "onMeDeop", user, channel
# There are a few other event handlers supported by the irc.Connection class. Furthermore, one can program
# numeric-based handlers to handle numeric events that are not captured by
# a named event handler as follows:
def onNNN(self, IRC, params, extinfo):
# Where NNN is a three-digit (leading zeros if necessary) code used to
# handle a numeric NNN event.
pass
|