Add posting to mastodon
parent
1ebf436ba9
commit
884261c783
64
ramenkan.py
64
ramenkan.py
|
@ -1,3 +1,4 @@
|
||||||
|
from mastodon import Mastodon
|
||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
from itte import IRC, Util
|
from itte import IRC, Util
|
||||||
|
@ -11,13 +12,21 @@ class Ramen:
|
||||||
# Load yaml sources used by request handlers
|
# Load yaml sources used by request handlers
|
||||||
self.util = Util()
|
self.util = Util()
|
||||||
self.rand = self.util.rand
|
self.rand = self.util.rand
|
||||||
self.std = self.util.yml("ramenkan/standard.yml")
|
self.misc = self.util.yml("ramenkan/misc.yml")
|
||||||
self.links = self.util.yml("ramenkan/links.yml")
|
self.links = self.util.yml("ramenkan/links.yml")
|
||||||
self.photos = self.util.yml("ramenkan/photos.yml")
|
self.photos = self.util.yml("ramenkan/photos.yml")
|
||||||
self.dishes = self.util.yml("ramenkan/dishes.yml")
|
self.dishes = self.util.yml("ramenkan/dishes.yml")
|
||||||
# Init irc object
|
# Init irc object
|
||||||
self.irc = IRC()
|
self.irc = IRC()
|
||||||
self.cfg = self.irc.config("ramenkan/config.yml")
|
self.cfg = self.irc.config("ramenkan/config.yml")
|
||||||
|
# Init mastodon object
|
||||||
|
self.masto = Mastodon(
|
||||||
|
api_base_url=self.cfg["mastodon"]["base_url"],
|
||||||
|
access_token=self.cfg["mastodon"]["access_token"],
|
||||||
|
client_id=self.cfg["mastodon"]["client_id"],
|
||||||
|
client_secret=self.cfg["mastodon"]["client_secret"]
|
||||||
|
)
|
||||||
|
# Init request listeners
|
||||||
self.irc.run(self.add_listeners)
|
self.irc.run(self.add_listeners)
|
||||||
|
|
||||||
def add_listeners(self, cxt):
|
def add_listeners(self, cxt):
|
||||||
|
@ -34,6 +43,7 @@ class Ramen:
|
||||||
self.irc.listen(cxt, "rkveg", self.ramen_veggie)
|
self.irc.listen(cxt, "rkveg", self.ramen_veggie)
|
||||||
self.irc.listen(cxt, "rklink", self.link)
|
self.irc.listen(cxt, "rklink", self.link)
|
||||||
self.irc.listen(cxt, "rkselfie", self.selfie)
|
self.irc.listen(cxt, "rkselfie", self.selfie)
|
||||||
|
self.irc.listen(cxt, "rktoot", self.toot)
|
||||||
|
|
||||||
def quit(self, cxt):
|
def quit(self, cxt):
|
||||||
"""Disconnect from the server and quit."""
|
"""Disconnect from the server and quit."""
|
||||||
|
@ -41,11 +51,11 @@ class Ramen:
|
||||||
|
|
||||||
def rollcall(self, cxt):
|
def rollcall(self, cxt):
|
||||||
"""Handle request for app info."""
|
"""Handle request for app info."""
|
||||||
self.irc.reply(cxt, self.std["rollcall"])
|
self.irc.reply(cxt, self.misc["rollcall"])
|
||||||
|
|
||||||
def water(self, cxt):
|
def water(self, cxt):
|
||||||
"""Handle water offer."""
|
"""Handle water offer."""
|
||||||
resp = self.std["water"]
|
resp = self.misc["water"]
|
||||||
for index, r in enumerate(resp):
|
for index, r in enumerate(resp):
|
||||||
if "{{ nick }}" in r:
|
if "{{ nick }}" in r:
|
||||||
resp.append(r.replace("{{ nick }}", cxt["msg"]["nick"]))
|
resp.append(r.replace("{{ nick }}", cxt["msg"]["nick"]))
|
||||||
|
@ -54,7 +64,7 @@ class Ramen:
|
||||||
|
|
||||||
def botsnack(self, cxt):
|
def botsnack(self, cxt):
|
||||||
"""Handle snack offer."""
|
"""Handle snack offer."""
|
||||||
self.irc.reply(cxt, self.rand(self.std["botsnack"]))
|
self.irc.reply(cxt, self.rand(self.misc["botsnack"]))
|
||||||
|
|
||||||
def make_ramen_combo(self, *args, **kwargs):
|
def make_ramen_combo(self, *args, **kwargs):
|
||||||
"""Generate a ramen dish. Optionally pass `veggie=True` for a
|
"""Generate a ramen dish. Optionally pass `veggie=True` for a
|
||||||
|
@ -110,25 +120,30 @@ class Ramen:
|
||||||
combo += self.rand(dish["tapa"] + dish["tapa-veggie"]) + "."
|
combo += self.rand(dish["tapa"] + dish["tapa-veggie"]) + "."
|
||||||
return combo
|
return combo
|
||||||
|
|
||||||
|
def pick_ramen(self, *args, **kwargs):
|
||||||
|
"""Pick a ramen dish. Optionally set vegetarian selection with
|
||||||
|
`veggie=True`."""
|
||||||
|
roll = randint(1, 100)
|
||||||
|
veggie = kwargs.get("veggie", False)
|
||||||
|
# 1% possibility of regional preset
|
||||||
|
if roll == 100 and veggie:
|
||||||
|
pick = (self.dishes["set-veggie"] + ".").capitalize()
|
||||||
|
elif roll == 100 and not veggie:
|
||||||
|
pick = (self.rand(self.dishes["set"] + \
|
||||||
|
self.dishes["set-veggie"]) + ".").capitalize()
|
||||||
|
elif roll <= 99 and veggie:
|
||||||
|
pick = self.make_ramen_combo(veggie=True)
|
||||||
|
else:
|
||||||
|
pick = self.make_ramen_combo()
|
||||||
|
return pick
|
||||||
|
|
||||||
def ramen(self, cxt):
|
def ramen(self, cxt):
|
||||||
"""Handle ramen request."""
|
"""Handle ramen request."""
|
||||||
roll = randint(1, 100)
|
self.irc.reply(cxt, self.pick_ramen())
|
||||||
# 1% possibility of regional preset
|
|
||||||
if roll == 100:
|
|
||||||
resp = (self.rand(self.dishes["set"] + \
|
|
||||||
self.dishes["set-veggie"]) + ".").capitalize()
|
|
||||||
else:
|
|
||||||
resp = self.make_ramen_combo()
|
|
||||||
self.irc.reply(cxt, resp)
|
|
||||||
|
|
||||||
def ramen_veggie(self, cxt):
|
def ramen_veggie(self, cxt):
|
||||||
"""Handle vegetarian ramen request."""
|
"""Handle vegetarian ramen request."""
|
||||||
roll = randint(1, 100)
|
self.irc.reply(cxt, self.pick_ramen(veggie=True))
|
||||||
if roll == 100:
|
|
||||||
resp = (self.dishes["set-veggie"] + ".").capitalize()
|
|
||||||
else:
|
|
||||||
resp = self.make_ramen_combo(veggie=True)
|
|
||||||
self.irc.reply(cxt, resp)
|
|
||||||
|
|
||||||
def link(self, cxt):
|
def link(self, cxt):
|
||||||
"""Handle to display a titled link."""
|
"""Handle to display a titled link."""
|
||||||
|
@ -140,6 +155,19 @@ 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(self, cxt):
|
||||||
|
"""Handle post ramen to Mastodon."""
|
||||||
|
pick = self.pick_ramen()
|
||||||
|
self.masto.toot(pick)
|
||||||
|
self.irc.reply(cxt, pick + " " + self.misc["toot"])
|
||||||
|
|
||||||
|
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"])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app = Ramen()
|
app = Ramen()
|
||||||
app.main()
|
app.main()
|
||||||
|
|
|
@ -33,7 +33,7 @@ condiment:
|
||||||
- butter
|
- butter
|
||||||
- chili oil
|
- chili oil
|
||||||
- rayu # Japanese chili oil
|
- rayu # Japanese chili oil
|
||||||
- chili pepper
|
- chili peppers
|
||||||
- chili sauce
|
- chili sauce
|
||||||
- sesame oil
|
- sesame oil
|
||||||
- dashi # fish and seaweed stock
|
- dashi # fish and seaweed stock
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
rollcall:
|
rollcall:
|
||||||
"一、二、三、らーめん缶!
|
"一、二、三、らーめん缶!
|
||||||
Hello, I am a ramen vending machine. Please type a code for service:
|
Hello, I am a ramen vending machine. Please type a code for service:
|
||||||
!help !ramen !veggieramen !rklink !rkselfie
|
!help !ramen !veggieramen !rklink !rkselfie !rktoot
|
||||||
- Support: +81 012-700-1MIO どうぞめしあがれ。"
|
- Support: +81 012-700-1MIO どうぞめしあがれ。"
|
||||||
|
|
||||||
water:
|
water:
|
||||||
|
@ -21,3 +21,5 @@ water:
|
||||||
botsnack:
|
botsnack:
|
||||||
- "CHIKIN RAAAAAMEN━━━(゜∀゜)━━━!!!!!"
|
- "CHIKIN RAAAAAMEN━━━(゜∀゜)━━━!!!!!"
|
||||||
- "Ramen time anytime! 自o(´▽` )/"
|
- "Ramen time anytime! 自o(´▽` )/"
|
||||||
|
|
||||||
|
toot: "Now shared with Mastodon! (^v^)"
|
Loading…
Reference in New Issue