Skip to content

Commit 5ed05d6

Browse files
committed
Replace single hook with hook generator to fix help text
1 parent d643512 commit 5ed05d6

1 file changed

Lines changed: 12 additions & 15 deletions

File tree

plugins/foods.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import asyncio
21
import codecs
32
import json
43
import os
54
import re
65
from collections import namedtuple, defaultdict
7-
from itertools import chain
86

97
from cloudbot import hook
108
from cloudbot.util import textgen
@@ -98,16 +96,15 @@ def make_cmd_list(value):
9896
return value
9997

10098

101-
@asyncio.coroutine
102-
@hook.command(*chain.from_iterable(make_cmd_list(food.commands) for food in BASIC_FOOD))
103-
def basic_food(text, triggered_command, action):
104-
# Find the first food in BASIC_FOOD that matches the triggered command
105-
for food in BASIC_FOOD:
106-
cmd_list = make_cmd_list(food.commands)
107-
if triggered_command in cmd_list or any(cmd.startswith(triggered_command) for cmd in cmd_list):
108-
break
109-
else:
110-
# The triggered command didn't match any loaded foods, WTF!?!?
111-
return "{} matched an unknown food in foods.py. Congrats! You found a bug! " \
112-
"Please report this right away.".format(triggered_command)
113-
action(basic_format(text, basic_food_data[food.name], food.unitname))
99+
def basic_food(food):
100+
def func(text, action):
101+
action(basic_format(text, basic_food_data[food.name], food.unitname))
102+
103+
func.__name__ = food.name
104+
func.__doc__ = "<user> - gives {} to [user]".format(food.unitname)
105+
return func
106+
107+
108+
for food in BASIC_FOOD:
109+
globals()[food.name] = hook.command(*make_cmd_list(food.commands))(basic_food(food))
110+

0 commit comments

Comments
 (0)