Add toot error handling

trunk
mio 2018-10-10 16:48:05 +00:00
parent a09f7b1d7e
commit edeff5469d
3 changed files with 20 additions and 11 deletions

View File

@ -43,13 +43,13 @@ class IRC:
self.connect(self.server, self.bot_nick) self.connect(self.server, self.bot_nick)
self.join_channels(self.channels) self.join_channels(self.channels)
while 1: while 1:
sleep(2)
data = self.receive() data = self.receive()
self.keepalive(data) self.keepalive(data)
self.msg = self.parse(data, self.req_prefix) self.msg = self.parse(data, self.req_prefix)
for c in self.channels: for c in self.channels:
# Pass in a context dict for handlers # Pass in a context dict for handlers
listen_hook({"msg": self.msg, "listen_chan": c}) listen_hook({"msg": self.msg, "listen_chan": c})
sleep(1)
def connect(self, server, bot_nick): def connect(self, server, bot_nick):
"""Connect to the server and sends user/nick information.""" """Connect to the server and sends user/nick information."""
@ -72,6 +72,7 @@ class IRC:
def keepalive(self, line): def keepalive(self, line):
"""Stay connected to a server by responding to server pings.""" """Stay connected to a server by responding to server pings."""
if resp != []:
resp = line.split(" ", 1)[1] resp = line.split(" ", 1)[1]
if ("PING " + resp) in line: if ("PING " + resp) in line:
self.send("PONG", resp) self.send("PONG", resp)

View File

@ -156,17 +156,23 @@ class Ramen:
"""Handle to display a photo link.""" """Handle to display a photo link."""
self.irc.reply(cxt, self.rand(self.photos["ticket"])) 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): def toot(self, cxt):
"""Handle post ramen to Mastodon.""" """Handle post ramen to Mastodon."""
pick = self.pick_ramen() self.toot_wrapper(cxt, self.pick_ramen())
self.masto.toot(pick)
self.irc.reply(cxt, pick + " " + self.misc["toot"])
def toot_veggie(self, cxt): def toot_veggie(self, cxt):
"""Handle post veggie ramen to Mastodon.""" """Handle post veggie ramen to Mastodon."""
pick = self.pick_ramen(veggie=True) self.toot_wrapper(cxt, self.pick_ramen(veggie=True))
self.masto.toot(pick)
self.irc.reply(cxt, pick + " " + self.misc["toot"])
app = Ramen() app = Ramen()

View File

@ -22,4 +22,6 @@ botsnack:
- "CHIKIN RAAAAAMEN━━━(゜∀゜)━━━!!!!!" - "CHIKIN RAAAAAMEN━━━(゜∀゜)━━━!!!!!"
- "Ramen time anytime! 自o(´▽` )/" - "Ramen time anytime! 自o(´▽` )/"
toot: "Now shared with Mastodon! ()" toot:
success: "Now shared with Mastodon! ()"
error: "Hyuuuuu! Sorry, I can't seem to toot right now. Ask me again later."