Add badgeinfo, plus QoL improvements

This commit is contained in:
Robert Miles 2020-04-27 10:36:13 -04:00
parent 0f9a57199f
commit bdad8e79b4
1 changed files with 24 additions and 4 deletions

View File

@ -1,4 +1,5 @@
import plugin, badge, random, json, traceback, requests, io, importlib
from pluralslib import plural, are
from bot import IRCLine
from collections import Counter
importlib.reload(badge)
@ -47,19 +48,21 @@ def on_privmsg(event):
elif timeouts.get(event.target,0)>0:
timeouts[event.target]-=1
if event.message=="!botlist" or event.message=="!rollcall":
respond(event,"Hi! I'm the badger! I give out badges randomly. "+("Commands you can use include 'listbadges' and 'transmute'." if account is not None else "To get started, log in to a services account! (/msg NickServ help)")+" Source: https://ttm.sh/Eyx")
respond(event,"Hi! I'm the badger! I give out badges randomly. "+("Commands you can use include 'listbadges', 'transmute', and 'badgeinfo'." if account is not None else "To get started, log in to a services account! (/msg NickServ help)")+" Source: https://ttm.sh/Eyx")
def on_cmd_help(event):
if BOT is None: return
account = event.tags.get("account",None)
if len(event.parts)==0:
respond(event,"Hi! I'm the badger! I give out badges randomly. "+("Commands you can use include 'listbadges' and 'transmute'." if account is not None else "To get started, log in to a services account! (/msg NickServ help)"))
respond(event,"Hi! I'm the badger! I give out badges randomly. "+("Commands you can use include 'listbadges', 'transmute', and 'badgeinfo'. Use 'help <command>' for more help." if account is not None else "To get started, log in to a services account! (/msg NickServ help)"))
return None
if account is None: return
if event.parts[0]=="listbadges":
respond(event,"Lists the badges in your possession. Usage: listbadges")
elif event.parts[0]=="transmute":
respond(event,"Transmutes 3 or more badges into one, possibly rarer, badge. Usage: transmute <badge one> <badge two> <badge three> [badge four...]")
elif event.parts[0]=="badgeinfo":
respond(event,"Gives info on the rarity of a badge. Usage: badgeinfo all OR badgeinfo <badge one> [<badge two> <badge three>...]")
def on_cmd_listbadges(event):
if BOT is None: return
@ -67,7 +70,7 @@ def on_cmd_listbadges(event):
if account is None: return
counts = Counter([x.name for x in population.value.badges.get(account,"")])
ret = []
for item in counts.items():
for item in sorted(list(counts.items()),key=lambda x: -badge_weights[x[0]]):
ret.append("{} (x{!s})".format(*item))
if len(counts.items())==0:
respond(event,"You don't have any badges yet! Just stay active in the channel and you'll get one eventually.")
@ -81,8 +84,9 @@ def on_cmd_transmute(event):
if len(event.parts)<3:
respond(event,"You must insert at least 3 badges for use in transmutation.")
return
badges_given = [(x[0].upper())+x[1:].lower() for x in event.parts]
try:
badge_result = population.value.transmute(account,*event.parts)
badge_result = population.value.transmute(account,*badges_given)
except badge.UserDoesntHaveEnoughBadges:
respond(event,"You must have at least one (1) of each badge you wish to use in the transmutation.")
return
@ -96,14 +100,29 @@ def on_cmd_transmute(event):
url = r.text.strip()
except: pass
respond(event,"Something went wrong! Error: "+url)
respond(event,"If you lost badges because of this error, please tell khuxkm which badges and he will refund you.")
return
respond(event,"You put in the {!s} badges above, and out pops a {}!".format(len(event.parts),badge_result))
population.value.give_badge(account,badge_result,False)
population.save("badges.json")
def on_cmd_badgeinfo(event):
bag = population.value.population
if "all" in event.parts:
event.data["parts"]=sorted(list(set(badge.name for badge in bag)),key=lambda x: -badge_weights[x])
for badge in event.parts:
badge = badge[0].upper()+badge[1:].lower()
b = [obadge for obadge in bag if obadge.name==badge]
count = len(b)
normal = len([x for x in b if x.normal])
rarity = population.value.rarity(badge)
respond(event,"There {} {} in existence, {!s} of them randomly generated (effective rarity of {:0.2%})".format(are(count),plural(count,badge),normal,rarity))
def admin_givebadge(event):
print(event.name,event.data)
try:
account, badge = event.parts[:2]
badge = badge[0].upper()+badge[1:].lower()
normal=True
if len(event.parts)==3 and event.parts[2].lower() in ("n","no","f","false"): normal=False
population.value.give_badge(account,badge,normal)
@ -117,4 +136,5 @@ def register(bot):
bot.event_manager.on("command_help",on_cmd_help)
bot.event_manager.on("command_listbadges",on_cmd_listbadges)
bot.event_manager.on("command_transmute",on_cmd_transmute)
bot.event_manager.on("command_badgeinfo",on_cmd_badgeinfo)
bot.event_manager.on("admin_givebadge",admin_givebadge)