Add toot error handling
parent
a09f7b1d7e
commit
edeff5469d
3
itte.py
3
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,6 +72,7 @@ class IRC:
|
|||
|
||||
def keepalive(self, line):
|
||||
"""Stay connected to a server by responding to server pings."""
|
||||
if resp != []:
|
||||
resp = line.split(" ", 1)[1]
|
||||
if ("PING " + resp) in line:
|
||||
self.send("PONG", resp)
|
||||
|
|
18
ramenkan.py
18
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()
|
||||
|
|
|
@ -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."
|
||||
|
|
Loading…
Reference in New Issue