File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import asyncio
21import codecs
32import json
43import os
54import re
65from collections import namedtuple , defaultdict
7- from itertools import chain
86
97from cloudbot import hook
108from 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+
You can’t perform that action at this time.
0 commit comments