Add toot error handling
parent
a09f7b1d7e
commit
edeff5469d
9
itte.py
9
itte.py
|
@ -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,9 +72,10 @@ 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."""
|
||||||
resp = line.split(" ", 1)[1]
|
if resp != []:
|
||||||
if ("PING " + resp) in line:
|
resp = line.split(" ", 1)[1]
|
||||||
self.send("PONG", resp)
|
if ("PING " + resp) in line:
|
||||||
|
self.send("PONG", resp)
|
||||||
|
|
||||||
def join_channels(self, channels):
|
def join_channels(self, channels):
|
||||||
"""Join channels given a list of channel names."""
|
"""Join channels given a list of channel names."""
|
||||||
|
|
18
ramenkan.py
18
ramenkan.py
|
@ -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()
|
||||||
|
|
|
@ -22,4 +22,6 @@ botsnack:
|
||||||
- "CHIKIN RAAAAAMEN━━━(゜∀゜)━━━!!!!!"
|
- "CHIKIN RAAAAAMEN━━━(゜∀゜)━━━!!!!!"
|
||||||
- "Ramen time anytime! 自o(´▽` )/"
|
- "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