diff --git a/itte.py b/itte.py index 66a5cb4..de5b37e 100644 --- a/itte.py +++ b/itte.py @@ -43,13 +43,13 @@ class IRC: self.connect(self.server, self.bot_nick) self.join_channels(self.channels) while 1: - sleep(2) data = self.receive() self.keepalive(data) self.msg = self.parse(data, self.req_prefix) for c in self.channels: # Pass in a context dict for handlers listen_hook({"msg": self.msg, "listen_chan": c}) + sleep(1) def connect(self, server, bot_nick): """Connect to the server and sends user/nick information.""" @@ -72,9 +72,10 @@ class IRC: def keepalive(self, line): """Stay connected to a server by responding to server pings.""" - resp = line.split(" ", 1)[1] - if ("PING " + resp) in line: - self.send("PONG", resp) + if resp != []: + resp = line.split(" ", 1)[1] + if ("PING " + resp) in line: + self.send("PONG", resp) def join_channels(self, channels): """Join channels given a list of channel names.""" diff --git a/ramenkan.py b/ramenkan.py index 9b9cdad..8f0bb31 100755 --- a/ramenkan.py +++ b/ramenkan.py @@ -156,17 +156,23 @@ class Ramen: """Handle to display a photo link.""" self.irc.reply(cxt, self.rand(self.photos["ticket"])) + def toot_wrapper(self, cxt, txt): + """Wrap around the Mastodon library's toot command for basic error + handling.""" + try: + self.masto.toot(txt) + self.irc.reply(cxt, txt + " " + self.misc["toot"]["success"]) + except: + self.irc.reply(cxt, self.misc["toot"]["error"]) + pass + def toot(self, cxt): """Handle post ramen to Mastodon.""" - pick = self.pick_ramen() - self.masto.toot(pick) - self.irc.reply(cxt, pick + " " + self.misc["toot"]) + self.toot_wrapper(cxt, self.pick_ramen()) def toot_veggie(self, cxt): """Handle post veggie ramen to Mastodon.""" - pick = self.pick_ramen(veggie=True) - self.masto.toot(pick) - self.irc.reply(cxt, pick + " " + self.misc["toot"]) + self.toot_wrapper(cxt, self.pick_ramen(veggie=True)) app = Ramen() diff --git a/ramenkan/misc.yml b/ramenkan/misc.yml index c09f6c0..03132f7 100644 --- a/ramenkan/misc.yml +++ b/ramenkan/misc.yml @@ -22,4 +22,6 @@ botsnack: - "CHIKIN RAAAAAMEN━━━(゜∀゜)━━━!!!!!" - "Ramen time anytime! 自o(´▽` )/" -toot: "Now shared with Mastodon! (^v^)" +toot: + success: "Now shared with Mastodon! (^v^)" + error: "Hyuuuuu! Sorry, I can't seem to toot right now. Ask me again later."