diff --git a/.gitignore b/.gitignore index 2a25b8a..117ea70 100644 --- a/.gitignore +++ b/.gitignore @@ -114,3 +114,4 @@ dmypy.json # data files *.json +*.psv diff --git a/badge_list_gen.py b/badge_list_gen.py new file mode 100644 index 0000000..7c02c81 --- /dev/null +++ b/badge_list_gen.py @@ -0,0 +1,30 @@ +import json, os.path, csv +from collections import Counter + +with open(os.path.join(os.path.dirname(__file__),"badges.json")) as f: badges = json.load(f) +with open(os.path.join(os.path.dirname(__file__),"association.json")) as f: names = json.load(f) + +users = [] + +for k in badges: + if k.startswith("__"): continue + l = [] + counter = Counter([b["name"] for b in badges[k]]) + total = 0 + for item in counter.items(): + l.append("{} (x{!s})".format(*item)) + total+=item[1] + users.append([k,", ".join(l),total]) + +users.sort(key=lambda x: -x[2]) +out = [] +for user in users: + out.append([names.get(user[0],user[0]),user[1]]) + +class PSV(csv.unix_dialect): + delimiter="|" + quoting=csv.QUOTE_NONE + +with open(os.path.join(os.path.dirname(__name__),"badge_list.psv"),"w") as f: + w = csv.writer(f,PSV) + w.writerows(out) diff --git a/plugins/associate.py b/plugins/associate.py new file mode 100644 index 0000000..1bfa026 --- /dev/null +++ b/plugins/associate.py @@ -0,0 +1,14 @@ +from plugin import DictData +BOT = None + +username_nick = DictData("association.json") + +def on_privmsg(event): + if BOT is None: return + if event.tags.get("account") is None: return + username_nick[event.tags["account"]]=event.hostmask.nick + +def register(bot): + global BOT + BOT=bot + bot.event_manager.on("privmsg",on_privmsg)