async def owners(self, c, n, m): query = m.split(" ")[0] if len(m) < 1: await out.msg(self, modname, c, [f"need item name."]) return total = 0 stats = {} for item in list(oveninv.find(item=query)): if not item["name"] in stats: stats[item["name"]] = 0 stats[item["name"]] += 1 total += 1 output = "" ctr = 0 until = 7 for i in sorted(stats.items(), key=lambda i: i[1], reverse=True): if ctr == until: break percentage = (i[1] * 100) / total output += "{} (×{}, {:.0f}%), ".format(nohighlight(i[0]), i[1], percentage) ctr += 1 output = output[:-2] # trim ', ' await out.msg(self, modname, c, [f"top {query} owners: {output}"])
async def richest(self, c, n, m): total = 0 stats = {} if len(m) > 0: results = oveninv.find(item=m) else: results = oveninv.find() for item in list(results): price = DEFAULT_PRICE if item["item"] in baked_goods: price = baked_goods[item["item"]] / 10 if not item["name"] in stats: stats[item["name"]] = 0 stats[item["name"]] += price total += price output = "" ctr = 0 until = 7 for i in sorted(stats.items(), key=lambda i: i[1], reverse=True): if ctr == until: break percentage = (i[1] * 100) / total output += "{} (${:.2f}, {:.1f}%), ".format(nohighlight(i[0]), i[1], percentage) ctr += 1 output = output[:-2] # trim ', ' await out.msg( self, modname, c, [f"richest users: {output} (total wealth: ${total:,.2f})"] )
async def noisiest(self, chan, src, msg): stats = {} total = 0 logs = [] targetchan = chan if len(msg) > 0 and msg[:1] == "#": targetchan = msg try: logs = get_all_logs(targetchan, msg) except: await out.msg(self, modname, chan, [self.err_invalid_logfile]) return for item in logs: if not item["user"] in stats: stats[item["user"]] = 0 stats[item["user"]] += 1 total += 1 output = "" ctr = 0 until = 7 for i in sorted(stats.items(), key=lambda i: i[1], reverse=True): if ctr == until: break percentage = "{0:.2f}".format(i[1] * 100 / total) output += "{} ({}%, {} msgs), ".format(nohighlight(i[0]), percentage, i[1]) ctr += 1 output = output[:-2] # trim ', ' await out.msg(self, modname, chan, [f"top talkers at {targetchan}: {output}"])
async def get_stats_by_phrase(self, chan, src, msg, phrases, label): stats = {} total = 0 logs = [] targetchan = chan if len(msg) > 0 and msg[:1] == "#": targetchan = msg try: logs = get_all_logs(targetchan, msg) except: await out.msg(self, modname, chan, [self.err_invalid_logfile]) return for item in logs: if any(phrase in item["msg"] for phrase in phrases): if not item["user"] in stats: stats[item["user"]] = 0 stats[item["user"]] += 1 output = "" ctr = 0 until = 7 for i in sorted(stats.items(), key=lambda i: i[1], reverse=True): if ctr == until: break output += "{} ({} msgs), ".format(nohighlight(i[0]), i[1]) ctr += 1 output = output[:-2] # trim ', ' await out.msg(self, modname, chan, [f"{label} people at {targetchan}: {output}"])
async def give(self, c, n, m): m = m.split(" ") if len(m) < 2: await out.msg(self, modname, c, [f"you can't give air!"]) return if _count_item(n, m[1]) < 1: await out.msg(self, modname, c, [msgs["DONT_HAVE_ANY"].format(m[1])]) return try: _transfer_item(n, m[0], m[1], 1) except InventoryNotFound: await out.msg(self, modname, c, [msgs["USER_NOT_FOUND"]]) return receiver = nohighlight(m[0]) await out.msg(self, modname, c, [f"you gave {receiver} a {m[1]}!"])
async def giveall(self, c, n, m): m = m.split(" ") if len(m) < 2: await out.msg(self, modname, c, [f"you can't give air!"]) return itemcount = _count_item(n, m[1]) if itemcount < 1: await out.msg(self, modname, c, [msgs["DONT_HAVE_ANY"].format(m[1])]) return try: _transfer_item(n, m[0], m[1], itemcount) except InventoryNotFound: await out.msg(self, modname, c, [msgs["USER_NOT_FOUND"]]) return receiver = nohighlight(m[0]) # TODO: pluralize properly await out.msg(self, modname, c, [f"you gave {receiver} your {m[1]}(s)!"])
msgs = { "INV_EMPTY": "you look into the oven and see nothing", "BAKE_RESULT": "you bake your items, and out pops a {}!", "BAKE_SMOKING": "the oven begins to smoke...", "BAKE_EXPLODE": "the oven explodes!", "BAKE_MURDER": "{} brutally murders the ducc amidst its terrified quaccs and stuffs it into the oven.", "BAKE_NEED_TWO": "you need at least two items", "DONT_HAVE_ENOUGH": "you don't have enough of {}", "DONT_HAVE_ANY": "you don't have any {}", "USER_NOT_FOUND": "that user doesn't exist", "FOOD_NOM_NOM": "nom nom nom", "DUCK_GONE_GONE": "you lose your hold on the ducc and it flies away!", } baked_goods = { nohighlight("khuxkm"): 50, nohighlight("jan6"): 50, nohighlight("login"): 50, "spam": 2, "flour": 6, "pizza": 10, "pancake": 28, "water": 20, "ration": 38, "egg": 30, "rice": 40, "bread": 40, "pie": 58, "bird": 50, "tortilla": 65, "cookie": 74,