def GetBoard(self, game_id, flips=None): boardQuery = self.sql.sel( "SELECT card_id, owner FROM boardslots WHERE game_id = {}".format( game_id)) if not boardQuery.rowcount: return None boardDetails = boardQuery.fetchall() tempImages = [] counter = 0 for (card_id, card_owner) in boardDetails: counter = counter + 1 if card_id < 1: #generate default image tempCard = images.generate_blank_card(2, counter) tempCard = images.add_card_ownership_background( tempCard, card_owner) tempImages.append(tempCard) else: cardDetails = self.get_card(card_id) tempCard = images.generate_card_img( 2, cardDetails[0], cardDetails[1], cardDetails[2], cardDetails[3], cardDetails[4], cardDetails[5], cardDetails[6], cardDetails[7]) tempCard = images.add_card_ownership_background( tempCard, card_owner) tempImages.append(tempCard) boardImg = images.generate_board(tempImages, flips) return boardImg
async def GetHand(self, game_id, player_id, orientation, playerNum): handQuery = self.sql.sel( "SELECT card_id FROM handslots WHERE game_id = {} AND discord_id = {}" .format(game_id, player_id)) if not handQuery.rowcount: return None handDetails = handQuery.fetchall() tempImages = [] for card_id in handDetails: if card_id[0] < 1: #generate default image tempCard = images.generate_blank_card(1) tempCard = images.add_card_ownership_background( tempCard, playerNum) tempImages.append(tempCard) else: cardDetails = self.get_card(card_id[0]) tempCard = images.generate_card_img( 1, cardDetails[0], cardDetails[1], cardDetails[2], cardDetails[3], cardDetails[4], cardDetails[5], cardDetails[6], cardDetails[7]) tempCard = images.add_card_ownership_background( tempCard, playerNum) tempImages.append(tempCard) if orientation == 1: handImg = images.generate_hand(tempImages) elif orientation == 2: handImg = images.generate_hand_vert(tempImages) return handImg
async def card(self, ctx, cardSearchTerm): cardDetails = self.get_card(cardSearchTerm) if cardDetails == None: await self.client.say("That card does not exist") else: tempCard = images.generate_card_img(3, cardDetails[0], cardDetails[1], cardDetails[2], cardDetails[3], cardDetails[4], cardDetails[5], cardDetails[6], cardDetails[7]) await self.client.send_file(ctx.message.channel, tempCard.name) tempCard.close() os.remove(tempCard.name)
async def get_random_card(self, ctx): randomCard = random.randint(1, 9) cardDetails = self.get_card(randomCard) if cardDetails == None: await self.client.say("That card does not exist") else: tempCard = images.generate_card_img(3, cardDetails[0], cardDetails[1], cardDetails[2], cardDetails[3], cardDetails[4], cardDetails[5], cardDetails[6], cardDetails[7]) await self.client.send_file(ctx.message.channel, tempCard.name) tempCard.close() os.remove(tempCard.name)
def generate_deck(self, deck_id): deckDetails = self.sql.sel( "SELECT card_id FROM deckslots WHERE deck_id = {} ORDER BY slot_index" .format(deck_id)) tempImages = [] deckDetails = deckDetails.fetchall() for card_id in deckDetails: if card_id[0] < 1: #generate default image tempCard = images.generate_blank_card(1) tempCard = images.add_card_ownership_background(tempCard, 0) tempImages.append(tempCard) else: cardDetails = self.cards.get_card(card_id[0]) tempCard = images.generate_card_img( 1, cardDetails[0], cardDetails[1], cardDetails[2], cardDetails[3], cardDetails[4], cardDetails[5], cardDetails[6], cardDetails[7]) tempCard = images.add_card_ownership_background(tempCard, 0) tempImages.append(tempCard) return images.generate_hand(tempImages)
async def inventory(self, ctx): discord_id = str(ctx.message.author.id) inventorydata = self.sql.sel( "SELECT cards.card_id, cards.name, cards.top, cards.right, cards.bottom, cards.left, cards.img_path, cards.rarity, inventory.quantity FROM cards INNER JOIN inventory ON cards.card_id = inventory.item_id WHERE inventory.discord_id = {} ORDER BY cards.card_id" .format(discord_id)) if not inventorydata.rowcount: await self.client.say("Your inventory is empty, {}".format( ctx.message.author.mention)) else: card_imgs = [] for (card_id, name, top, right, bottom, left, img_path, rarity, quantity) in inventorydata: tempCard = images.generate_card_img(2, card_id, name, top, right, bottom, left, img_path, rarity) tempCard = images.add_card_amount(tempCard, card_id, quantity) card_imgs.append(tempCard) inventoryImg = images.generate_inventory(card_imgs) await self.client.send_file(ctx.message.channel, inventoryImg.name) inventoryImg.close() os.remove(inventoryImg.name)
async def randcard(self, ctx, cardSearchTerm): if not self.user_is_me(ctx): await self.client.say("Command limited to owner") return cardDetails = self.get_card(cardSearchTerm) if cardDetails == None: await self.client.say("That card does not exist") else: response = "" while True: print("Generating Card Stats with Rarity = {}: ".format( str(cardDetails[7]))) a = randomgen.card_stat_randomizer(cardDetails[7]) print(a) tempCard = images.generate_card_img(3, cardDetails[0], cardDetails[1], a['top'], a['right'], a['bottom'], a['left'], cardDetails[6], cardDetails[7]) await self.client.send_file(ctx.message.channel, tempCard.name) tempCard.close() os.remove(tempCard.name) await self.client.say("Are you okay with these stats?") response = await self.client.wait_for_message( author=ctx.message.author) response = response.clean_content.lower() if response == 'yes': self.sql.exec( "UPDATE cards SET top = {}, `right` = {}, bottom = {}, `left` = {} WHERE card_id = {}" .format(a['top'], a['right'], a['bottom'], a['left'], cardDetails[0])) await self.client.say( "Updated card with new randomized stats") return elif response == 'cancel': await self.client.say("Cancelling stat randomization")
async def character(self, ctx, *argv): if len(argv) > 1: #Check if last two arguments are integers allArgs = argv try: index = int(allArgs[-2]) picIndex = int(allArgs[-1]) allArgs = " ".join(argv[:-2]) except ValueError: picIndex = 1 try: index = int(allArgs[-1]) allArgs = " ".join(argv[:-1]) except ValueError: index = -1 picIndex = 1 else: index = -1 picIndex = 1 allArgs = argv[0] print(allArgs) cs = self.get_character(allArgs) outputString = "" if cs: if len(cs) > 1: if index == -1: counter = 1 outputString = outputString + "Found Multiple Matches: \n" for c in cs: if len(outputString) > 1800: break outputString = outputString + "{}: **{}** - ({})\n".format( str(counter), c.name, c.t_gender) counter += 1 await self.client.say(outputString) else: try: c = cs[index - 1] except: await self.client.say("Invalid index provided") try: outputString = outputString + "**{}** - ({}) found with {} favorites \n".format( c.name, c.t_gender, c.num_favorites) await self.client.say(outputString) destinationFolder = r'F:\Anime Character Images' writeFolderPath = os.path.join(destinationFolder, str(c.id)) fileName = str(c.id) + "_" + str(picIndex) + ".png" fullFilePath = os.path.join(writeFolderPath, fileName) tempCard = images.generate_card_img( 3, 0, c.name, 0, 0, 0, 0, fullFilePath, 0) await self.client.send_file(ctx.message.channel, tempCard.name) tempCard.close() os.remove(tempCard.name) except: await self.client.say("Image retrieval failed") else: c = cs[0] outputString = outputString + "**{}** - ({}) found with {} favorites \n".format( c.name, c.t_gender, c.num_favorites) await self.client.say(outputString) destinationFolder = r'F:\Anime Character Images' writeFolderPath = os.path.join(destinationFolder, str(c.id)) fileName = str(c.id) + "_" + str(1) + ".png" fullFilePath = os.path.join(writeFolderPath, fileName) tempCard = images.generate_card_img(3, 0, c.name, 0, 0, 0, 0, fullFilePath, 0) await self.client.send_file(ctx.message.channel, tempCard.name) tempCard.close() os.remove(tempCard.name) else: await self.client.say("Character not found")