async def trade(message): verbs = ["traded", "trades", "gave", "gives"] tl = getTokens(message.content.lower()) for v in verbs: if v in tl: vLoc = tl.index(v) break if vLoc == 0 or vLoc == len(tl) - 1: await faith.send_message(message.channel, "Sorry, I can't understand who traded.") return giver = Tier.getName(tl[vLoc - 1]) if giver == None: await faith.send_message(message.channel, "Sorry, I can't understand who gave that piece.") return if "to" in tl: oLoc = tl.index("to") + 1 if oLoc >= len(tl): await faith.send_message( "I'm sorry, I can't understand your grammar...") return taker = Tier.getName(tl[oLoc]) else: taker = Tier.getName(tl[vLoc + 1]) if taker == None: await faith.send_message(message.channel, "Sorry, I can't understand who got that piece.") return for r in await Tier.trade(giver, taker): await faith.send_message(message.channel, r) return
async def tierCount(message): m = message.content.lower() tokens = getTokens(message.content) name = None for i in range(len(tokens)): if tokens[i] == "does" and i+2 < len(tokens) and tokens[i+2] == "have": name = Tier.getName(tokens[i+1]) break if tokens[i] == "s": name = Tier.getName(tokens[i+1]) break if name == None: await faith.send_message(message.channel, "Sorry, I can't get that name right...") return slot = Tier.getSlot(m) if slot: await faith.send_message(message.channel, name.capitalize() + " has " + Tier.pieceDesc(name, slot) + " " + slot + ".") else: count = 0 for s in Armory.slots: if Tier.rec[name][s] != None: count += 1 await faith.send_message(message.channel, name.capitalize() + " has %d tier pieces." % count) for s in Armory.slots: p = Tier.rec[name][s] if p != None: await faith.send_message(message.channel, s + ": " + Tier.pieceDesc(name, s))
async def wonPiece(message): if message.author.id not in officers: await faith.send_message("Only officers can do that.") return piece = Tier.extractPiece(message.content) slot = Tier.getSlot(message.content) loc = message.content.find(":") if loc == -1: loc = message.content.lower().find("won") #todo what if not found, is that possible tokens = getTokens(message.content[0:loc]) else: tokens = getTokens(message.content[loc:len(message.content)]) names = [] for t in tokens: if t == "and": continue #idiot-proof name = Tier.getName(t) if name == None: await faith.send_message(message.channel, "Cannot find " + t) continue names.append(name) for name in names: await faith.send_message(message.channel, Tier.winStr(name, slot, piece)) await Tier.award(names, slot, piece)
async def deletePiece(message): if message.author.id not in officers: await faith.send_message("Only officers can do that.") return slot = Tier.getSlot(message.content) tokens = getTokens(message.content) name = None for i in range(1, len(tokens)): if tokens[i] == "s": name = Tier.getName(tokens[i-1]) break if tokens[i-1] == "from": name = Tier.getName(tokens[i]) break if name == None: await faith.send_message(message.channel, "Can't find the player.") return oldPieceDesc = await Tier.forceOverwrite(name, slot, None) await faith.send_message(message.channel, "Deleted " + name.capitalize() + "'s " + oldPieceDesc + " " + slot + ".")
async def missingEnch(msg): tLst = getTokens(msg.content) name = getQuoted(msg.content) if not name: index = listIndex(tLst, "missing") if index > 0: name = Tier.getName(tLst[index-1]) if name: await faith.send_message(msg.channel, "missing gem: %d" % await Armory.missingGemsCount(name)) eLst = await Armory.missingEnch(name) if len(eLst) == 0: await faith.send_message(msg.channel, "Fully enchanted.") else: await faith.send_message(msg.channel, "Missing ench: " + ppStrLst(eLst)) else: await faith.send_message(message.channel, "Can't parse name or NYI.")
def deletePiece(message): m = message.content.lower() return (Tier.getSlot(m) and any(key in getTokens(m) for key in ["delete", "remove", "scrap", "scratch"]) and ("'s" in m or "from" in m))
def wonPiece(message): return (Tier.getSlot(message.content) and Tier.extractPiece(message.content) and any(key in message.content.lower() for key in ["won", ":"]))
async def raidEnd(message): reply = random.choice(["Good work tonight, and good night guys :)", "Hope you guys had fun and got some gears!"]) await faith.send_message(message.channel, reply) Tier.raidOver() return