Hook factorisation ; add new hooks : default (same comportement has previous version) and one hook before any parsing

When calling a hook, passed parameters change according to associated data variable
This commit is contained in:
Némunaire 2012-08-22 21:05:33 +02:00
commit 7e20368c10
8 changed files with 109 additions and 63 deletions

View file

@ -47,7 +47,7 @@ def fini(strend):
DATAS.delChild(DATAS.index[strend["name"]])
save()
def cmd_we(data, msg):
def cmd_we(msg):
ndate = datetime.today() + timedelta(5 - datetime.today().weekday())
ndate = datetime(ndate.year, ndate.month, ndate.day, 0, 0, 1)
msg.send_chn (
@ -55,19 +55,19 @@ def cmd_we(data, msg):
"Il reste %s avant le week-end, courage ;)",
"Youhou, on est en week-end depuis %s."))
def cmd_newyear(data, msg):
def cmd_newyear(msg):
msg.send_chn (
msg.countdown_format (datetime(datetime.today().year + 1, 1, 1, 0, 0, 1),
"Il reste %s avant la nouvelle année.",
"Nous faisons déjà la fête depuis %s !"))
def cmd_vacances(data, msg):
def cmd_vacances(msg):
msg.send_chn (
msg.countdown_format (datetime(2012, 7, 30, 18, 0, 1),
"Il reste %s avant les vacances :)",
"Profitons, c'est les vacances depuis %s."))
def start_countdown(data, msg):
def start_countdown(msg):
if msg.cmd[1] not in DATAS:
strnd = ModuleState("strend")

View file

@ -16,19 +16,19 @@ temps = dict ()
SCORES = None
def load():
global DATAS, SCORES, CONF
DATAS.setIndex("name", "player")
SCORES = QDWrapper.QDWrapper(DATAS)
GameUpdater.SCORES = SCORES
GameUpdater.CONF = CONF
GameUpdater.save = save
GameUpdater.getUser = getUser
def load(context):
global DATAS, SCORES, CONF
DATAS.setIndex("name", "player")
SCORES = QDWrapper.QDWrapper(DATAS)
GameUpdater.SCORES = SCORES
GameUpdater.CONF = CONF
GameUpdater.save = save
GameUpdater.getUser = getUser
def reload():
imp.reload(GameUpdater)
imp.reload(QDWrapper)
imp.reload(Score)
imp.reload(GameUpdater)
imp.reload(QDWrapper)
imp.reload(Score)
def help_tiny ():

View file

@ -20,7 +20,7 @@ def load(context):
context.hooks.add_hook(context.hooks.cmd_hook, Hook(cmd_sleep, "sleepytime"))
def cmd_sleep(data, msg):
def cmd_sleep(msg):
if len (msg.cmd) > 1 and re.match("[0-9]{1,2}[h':.,-]([0-9]{1,2})?[m'\":.,-]?",
msg.cmd[1]) is not None:
# First, parse the hour

View file

@ -19,7 +19,7 @@ def load(context):
context.hooks.add_hook(context.hooks.cmd_hook, Hook(cmd_syno, "synonyme"))
def cmd_syno(data, msg):
def cmd_syno(msg):
if 1 < len(msg.cmd) < 6:
for word in msg.cmd[1:]:
synos = get_synos(word)

View file

@ -8,7 +8,7 @@ from urllib.parse import quote
nemubotversion = 3.2
import module_states_file as xmlparser
import xmlparser
LANG = ["ar", "zh", "cz", "en", "fr", "gr", "it",
"ja", "ko", "pl", "pt", "ro", "es", "tr"]
@ -25,7 +25,7 @@ def load(context):
Hook(cmd_translate, "traduire"))
def cmd_translate(data, msg):
def cmd_translate(msg):
global LANG
startWord = 1
if msg.cmd[startWord] in LANG:

View file

@ -78,7 +78,7 @@ def print_station_status(msg, station):
else:
msg.send_chn("%s: station %s inconnue." % (msg.nick, station))
def ask_stations(data, msg):
def ask_stations(msg):
"""Hook entry from !velib"""
global DATAS
if len(msg.cmd) > 5: