Add program to create pipe-seperated list of badges by nick

...as well as a plugin to save the most recent nick associated with a NickServ account.
This commit is contained in:
Robert Miles 2020-02-28 13:18:51 -05:00
parent b13b0b3732
commit 08cd3173e7
3 changed files with 45 additions and 0 deletions

1
.gitignore vendored
View File

@ -114,3 +114,4 @@ dmypy.json
# data files
*.json
*.psv

30
badge_list_gen.py Normal file
View File

@ -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)

14
plugins/associate.py Normal file
View File

@ -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)