diff options
Diffstat (limited to 'itemdb.py')
-rw-r--r-- | itemdb.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/itemdb.py b/itemdb.py new file mode 100644 index 0000000..34bde26 --- /dev/null +++ b/itemdb.py @@ -0,0 +1,27 @@ + +from loggers import debuglog + +item_names = {0: 'GP'} + + +def load_itemdb(dbfile='itemdb.txt'): + with open(dbfile, 'rt') as f: + for l in f.readlines(): + try: + sn, sr = l.split(' ', 1) + item_id = int(sn) + item_name = sr[:-1] if sr.endswith('\n') else sr + item_names[item_id] = item_name + except ValueError: + pass + + debuglog.info("Loaded itemdb from %s", dbfile) + return item_names + + +def item_name(item_id, mplus=False): + name = item_names.get(item_id, 'Item' + str(item_id)) + if mplus: + return '[@@{}|{}@@]'.format(item_id, name) + else: + return name |