Rearrange files, add links

trunk
mio 2018-09-16 04:48:50 +00:00
parent f0103c73db
commit 5f8f89988b
4 changed files with 55 additions and 6 deletions

View File

@ -4,15 +4,25 @@ from sys import exit
from time import sleep from time import sleep
class Util:
"""Utility functions."""
def yml(self, yml_file):
"Open a YAML file and return a dictionary of values."
fh = open(yml_file, "r")
data = yaml.safe_load(fh)
fh.close()
return data
class IRC: class IRC:
"""Methods for basic IRC communication.""" """Methods for basic IRC communication."""
def config(self, conf): def config(self, conf):
"""Load runtime settings from a YAML config file, and returns a """Load runtime settings from a YAML config file, and returns a
dictionary of config values.""" dictionary of config values."""
yml = open(conf, "r") self.util = Util()
cfg = yaml.safe_load(yml) cfg = self.util.yml(conf)
yml.close()
self.server = (cfg["server"]["host"], cfg["server"]["port"]) self.server = (cfg["server"]["host"], cfg["server"]["port"])
self.channels = cfg["channels"] self.channels = cfg["channels"]
self.bot_nick = cfg["bot_nick"] self.bot_nick = cfg["bot_nick"]

View File

@ -1,6 +1,7 @@
import yaml
from random import randint from random import randint
from irc import IRC from itte import IRC, Util
class Ramen: class Ramen:
@ -8,8 +9,12 @@ class Ramen:
def main(self): def main(self):
"""Instantiate an IRC object and attach the listeners.""" """Instantiate an IRC object and attach the listeners."""
# Load yaml sources used by request handlers
self.util = Util()
self.links = self.util.yml("ramenkan/links.yml")
# Init irc object
self.irc = IRC() self.irc = IRC()
self.cfg = self.irc.config("ramen.config.sample.yml") self.cfg = self.irc.config("ramenkan/config.sample.yml")
self.irc.run(self.add_listeners) self.irc.run(self.add_listeners)
def add_listeners(self, cxt): def add_listeners(self, cxt):
@ -20,6 +25,7 @@ class Ramen:
self.irc.listen(cxt, "help", self.rollcall) self.irc.listen(cxt, "help", self.rollcall)
self.irc.listen(cxt, "water " + self.cfg["bot_nick"], self.water) self.irc.listen(cxt, "water " + self.cfg["bot_nick"], self.water)
self.irc.listen(cxt, "botsnack " + self.cfg["bot_nick"], self.botsnack) self.irc.listen(cxt, "botsnack " + self.cfg["bot_nick"], self.botsnack)
self.irc.listen(cxt, "rklink", self.link)
def quit(self, cxt): def quit(self, cxt):
"""Disconnect from the server and quit.""" """Disconnect from the server and quit."""
@ -30,7 +36,7 @@ class Ramen:
"一、二、三、らーめん缶! " "一、二、三、らーめん缶! "
"Hello, I am a ramen vending machine. " "Hello, I am a ramen vending machine. "
"Please type a code for service: " "Please type a code for service: "
"!help " "!help !rklink - "
"Support: +81 012-700-1MIO どうぞめしあがれ。" "Support: +81 012-700-1MIO どうぞめしあがれ。"
) )
self.irc.reply(cxt, resp) self.irc.reply(cxt, resp)
@ -47,6 +53,11 @@ class Ramen:
def botsnack(self, cxt): def botsnack(self, cxt):
self.irc.reply(cxt, "Ramen time anytime! 自o(´▽`)/") self.irc.reply(cxt, "Ramen time anytime! 自o(´▽`)/")
def link(self, cxt):
rand = randint(0, len(self.links)-1)
self.irc.reply(cxt, self.links[rand]["title"] + " " + \
self.links[rand]["link"])
app = Ramen() app = Ramen()
app.main() app.main()

28
ramenkan/links.yml 100644
View File

@ -0,0 +1,28 @@
- title: Shin-Yokohama Ramen Museum, Yokohama
link: http://www.raumen.co.jp/english/
- title: Ramen Street, Tokyo
link: https://en.wikipedia.org/wiki/Ramen_street
- title: Sapporo Ramen Republic
link: http://www.sapporo-esta.jp/ramen
# Instant noodles
- title: Momofuku Ando, inventor of instant ramen (1958)
link: https://www.nissin.com/en_jp/about/founder/
- title: Instant cup noodles (1971)
link: https://en.wikipedia.org/wiki/Cup_Noodles
- title: Instant noodles as emergency food in disaster relief
link: https://instantnoodles.org/en/activities/support.html
- title: Samyang, the first Korean instant ramen (1963)
link: https://en.wikipedia.org/wiki/Samyang_ramen
# Ramen in pop culture
- title: Flower Boy Ramen Shop, romantic comedy drama (2011)
link: https://en.wikipedia.org/wiki/Flower_Boy_Ramen_Shop
- title: The Ramen Girl, romantic comedy film (2008)
link: https://en.wikipedia.org/wiki/The_Ramen_Girl
- title: Ms. Koizumi Loves Ramen Noodles, manga series (2013-)
link: https://en.wikipedia.org/wiki/Ms._Koizumi_Loves_Ramen_Noodles
- title: Muteki Kanban Musume, manga series (2002-2006)
link: https://en.wikipedia.org/wiki/Muteki_Kanban_Musume
- title: Detective Conan - Ramen So Good, It's to Die For, anime episode (2012)
link: https://www.detectiveconanworld.com/wiki/Ramen_So_Good,_It%27s_to_Die_For
- title: Ramen Teh, film (2018)
link: https://en.wikipedia.org/wiki/Ramen_Teh