Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit 626bfa1

Browse files
hiddnboogheta
authored andcommitted
ircbot: twitterbot can connect to more IRC networks
The bot now waits for the 001 welcome message before sending JOINs and PRIVMSGs, allowing it to successfully connect to more IRC networks.
1 parent 5041650 commit 626bfa1

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

twitter/ircbot.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,18 @@ def __init__(self, configFilename):
153153
self.irc = irclib.IRC()
154154
self.irc.add_global_handler('privmsg', self.handle_privmsg)
155155
self.irc.add_global_handler('ctcp', self.handle_ctcp)
156-
self.irc.add_global_handler('umode', self.handle_umode)
156+
self.irc.add_global_handler('welcome', self.handle_welcome)
157157
self.ircServer = self.irc.server()
158158

159+
self.welcome_received = False
159160
self.sched = Scheduler(
160161
(SchedTask(self.process_events, 1),
161162
SchedTask(self.check_statuses, 120)))
162163
self.lastUpdate = (datetime.utcnow() - timedelta(minutes=10)).utctimetuple()
163164

164165
def check_statuses(self):
166+
if not self.welcome_received:
167+
return
165168
debug("In check_statuses")
166169
try:
167170
updates = reversed(self.twitter.statuses.home_timeline())
@@ -226,18 +229,16 @@ def handle_ctcp(self, conn, evt):
226229
elif args[0] == 'CLIENTINFO':
227230
conn.ctcp_reply(source, "CLIENTINFO PING VERSION CLIENTINFO")
228231

229-
def handle_umode(self, conn, evt):
232+
def handle_welcome(self, conn, evt):
230233
"""
231-
QuakeNet ignores all your commands until after the MOTD. This
232-
handler defers joining until after it sees a magic line. It
233-
also tries to join right after connect, but this will just
234-
make it join again which should be safe.
234+
Undernet and QuakeNet ignore all your commands until it receives 001. This
235+
handler defers joining until after it sees a magic line.
235236
"""
236-
args = evt.arguments()
237-
if (args and args[0] == '+i'):
238-
channels = self.config.get('irc', 'channel').split(',')
239-
for channel in channels:
240-
self.ircServer.join(channel)
237+
self.welcome_received = True
238+
channels = self.config.get('irc', 'channel').split(',')
239+
for channel in channels:
240+
self.ircServer.join(channel)
241+
self.check_statuses()
241242

242243
def privmsg_channels(self, msg):
243244
return_response=True
@@ -288,13 +289,11 @@ def unfollow(self, conn, evt, name):
288289
get_prefix('inform'), userNick, name))
289290

290291
def _irc_connect(self):
292+
self.welcome_received = False
291293
self.ircServer.connect(
292294
self.config.get('irc', 'server'),
293295
self.config.getint('irc', 'port'),
294296
self.config.get('irc', 'nick'))
295-
channels=self.config.get('irc', 'channel').split(',')
296-
for channel in channels:
297-
self.ircServer.join(channel)
298297

299298
def run(self):
300299
self._irc_connect()

0 commit comments

Comments
 (0)