def generate_all_user_commissions(): users_ids = database_mongo.get_all_users_list_ids() for i in range(len(users_ids)): u = get_user(users_ids[i]) u.commissions = {} u.commissions = commission.make_user_commissions() database_mongo.save_user(u)
async def embed_ten_pull(ctx): u = user.get_user(ctx.author.id) if u.primogems < 1600: await error.embed_not_enough_primo(ctx) return pulls, five = ten_pull(u) if five: color = discord.Color.gold() else: color = discord.Color.purple() f = discord.File(pulls[0].URL_icon, f"{pulls[0].URL_name}-icon.png") embed = discord.Embed(title=f"{u.nickname}\'s 10x Wish", color=color) embed.set_thumbnail(url=f"attachment://{pulls[0].URL_name}-icon.png") text = "" for i in pulls: if i.rarity == 5: text += prefix.fiveStarPrefix if i.rarity == 4: text += prefix.fourStarPrefix if i.rarity == 3: text += prefix.threeStarPrefix text += i.name + "\n" embed.add_field(name = "_ _", value = text, inline=False) u.primogems -= 1600 u.update_equiped_weapons() await commission.check_wish_complete(ctx, u, 10) database_mongo.save_user(u) asyncio.get_event_loop().create_task(display_pull(ctx, embed, f, pulls[0].rarity, False))
def update_user_characters(): user_ids = database_mongo.get_all_users_list_ids() for _id in user_ids: u = get_user(_id) chars = u.characters for name in chars.keys(): chars[name] = get_character_from_dict(chars, name).get_dict() u.characters = chars database_mongo.save_user(u)
def update_user_weapons(): user_ids = database_mongo.get_all_users_list_ids() for _id in user_ids: u = get_user(_id) weaps = u.weapons for name in weaps.keys(): weaps[name] = get_weapon_from_dict(weaps, name).get_dict() u.weapons = weaps database_mongo.save_user(u)
async def embed_create_blackjack_final(ctx, u, bot_hand, player_hand, winner, amount, _type): if _type == "p": u.primogems -= amount else: u.mora -= amount if winner == "u": embed = discord.Embed(title=f"{u.nickname}'s BlackJack Game", color=discord.Color.green()) text = "" if _type == "p": u.primogems += amount * 2 text = f"You won {formatter_custom.number_format(amount*2)}x Primogems" else: u.mora += amount * 2 text = f"You won {formatter_custom.number_format(amount*2)}x Mora" embed.add_field(name="You Won!", value=text) elif winner == "b": embed = discord.Embed(title=f"{u.nickname}'s BlackJack Game") embed.add_field(name="It was a tie.", value="You got your money back.") if _type == "p": u.primogems += amount else: u.mora += amount else: embed = discord.Embed(title=f"{u.nickname}'s BlackJack Game", color=discord.Color.red()) if _type == "p": text = f"You lost {formatter_custom.number_format(amount)}x Primogems" database_mongo.add_to_jackpot_primo(amount) else: text = f"You lost {formatter_custom.number_format(amount)}x Mora" database_mongo.add_to_jackpot_mora(amount) embed.add_field(name="You lost.", value=text) await commission.check_target_complete(ctx, u, "gamble", 1) database_mongo.save_user(u) text = "" for c in bot_hand: if text == "": text += f"{c}" else: text += f", {c}" check, total = check_21(bot_hand) embed.add_field(name=f"Yapa's Final Hand -> {total}", value=text, inline=False) text = "" for c in player_hand: if text == "": text += f"{c}" else: text += f", {c}" check, total = check_21(player_hand) embed.add_field(name=f"{u.nickname}'s Final Hand -> {total}", value=text, inline=False) return embed
def create_user(name, ID): newU = User(ID, name, name, "", "none", 1, 0, 0, 240, 0, 0, {}, {}, {}, 50000, 8000, 0, 0, 0, "", "", "", {}, {}, commission.make_user_commissions(), { "1": {}, "2": {}, "3": {}, "4": {} }, True) shop.generate_shop(ID) traveler = character.get_character("traveler-anemo") newU.add_character(traveler) database_mongo.save_user(newU)
def clear_user_xp(): users_ids = database_mongo.get_all_users_list_ids() for i in range(len(users_ids)): u = get_user(users_ids[i]) u.reset_level() for char_key in u.characters.keys(): char = character.get_character_from_dict(u.characters, char_key) char.xp = 0 u.characters[char_key] = char.get_dict() for weap_key in u.weapons.keys(): weap = weapon.get_weapon_from_dict(u.weapons, weap_key) weap.xp = 0 u.weapons[weap_key] = weap.get_dict() database_mongo.save_user(u)
def update_users(): users_ids = database_mongo.get_all_users_list_ids() for i in range(len(users_ids)): u = get_user(users_ids[i]) for char_key in u.characters.keys(): char = character.get_character_from_dict(u.characters, char_key) char_DB = character.get_character(char.name) char.URL_icon = char_DB.URL_icon char.URL_portrait = char_DB.URL_portrait char.description = char_DB.description char.constellations = char_DB.constellations char.constellation_name = char_DB.constellation_name u.characters[char_key] = char.get_dict() for weap_key in u.weapons.keys(): weap = weapon.get_weapon_from_dict(u.weapons, weap_key) weap_DB = weapon.get_weapon(weap.name) weap.URL_icon = weap_DB.URL_icon u.weapons[weap_key] = weap.get_dict() database_mongo.save_user(u)
async def embed_single_pull(ctx): u = user.get_user(ctx.author.id) if u.primogems < 160: await error.embed_not_enough_primo(ctx) return if u.five_pity >= 89: (p, t), five, four = pull(False, True, u) elif u.four_pity >= 9: (p, t), five, four = pull(True, False, u) else: (p, t), five, four = pull(False, False, u) text = "" if five: color = discord.Color.gold() text = prefix.fiveStarPrefix + p.name u.five_pity = 0 u.four_pity = 0 elif four: color = discord.Color.purple() text = prefix.fourStarPrefix + p.name u.five_pity += 1 u.four_pity = 0 else: color = discord.Color.blue() text = prefix.threeStarPrefix + p.name u.five_pity += 1 u.four_pity += 1 if t == "c": file = discord.File(p.URL_portrait, f"{p.URL_name}-portrait.png") embed = discord.Embed(title=text, color=color) embed.set_image(url=f"attachment://{p.URL_name}-portrait.png") else: file = discord.File(p.URL_icon, f"{p.URL_name}-icon.png") embed = discord.Embed(title=text, color=color) embed.set_image(url=f"attachment://{p.URL_name}-icon.png") u.primogems -= 160 u.update_equiped_weapons() await commission.check_wish_complete(ctx, u, 1) database_mongo.save_user(u) asyncio.get_event_loop().create_task(display_pull(ctx, embed, file, p.rarity, True))
def replace_weapon_name(old_URL_name, correct_URL_name, correct_name): users_ids = database_mongo.get_all_users_list_ids() for _id in users_ids: u = get_user(_id) user_weapons = u.weapons if old_URL_name in user_weapons.keys(): dict = user_weapons[old_URL_name] vortex = weapon.Weapon( correct_name, correct_URL_name, f"Images/Weapons/{correct_URL_name}-icon.png", dict["weapon_type"], dict["total"], dict["rarity"], dict["refinement"], dict["attack"], dict["substat"], dict["substat_value"], dict["level"], dict["xp"]) del user_weapons[old_URL_name] user_weapons[correct_URL_name] = vortex.get_dict() u.weapons = user_weapons for c in u.characters.keys(): char = character.dict_to_char(u.characters[c]) if len(char.weapon_equiped.keys()) > 0: if char.weapon_equiped["URL_name"] == old_URL_name: char.weapon_equiped = u.weapons[correct_URL_name] u.characters[c] = char.get_dict() database_mongo.save_user(u)
async def embed_exchange_weapon(ctx, bot, u: User, weap1_name, receiver: User, weap2_name): disclaimer = "Character info does not carry through trades." if not u.does_weapon_exist(weap1_name): await error.embed_get_weapon_suggestions(ctx, u, weap1_name) return if not receiver.does_weapon_exist(weap2_name): await error.embed_get_weapon_suggestions(ctx, receiver, weap2_name) return u_c = u.get_character(weap1_name) r_c = receiver.get_character(weap2_name) confirm = await formatter_custom.confirmation(ctx, bot, disclaimer) if not confirm: await ctx.send("Trade Cancelled.") return receiver_user = await bot.fetch_user(receiver._id) confirm = await formatter_custom.confirmation_specific( ctx, bot, receiver_user, disclaimer) if not confirm: await ctx.send("Trade Cancelled.") return u.remove_weapon(weap1_name) receiver.remove_weapon(weap2_name) u.add_weapon(weapon.get_weapon(weap2_name)) receiver.add_weapon(weapon.get_weapon(weap1_name)) database_mongo.save_user(u) database_mongo.save_user(receiver) embed = discord.Embed(title="Exchange Successful!", color=discord.Color.green()) embed.add_field(name=f"{u.nickname}'s Exchange Summary:", value=f"{u_c.name} ➟ {r_c.name}", inline=False) embed.add_field(name=f"{receiver.nickname}'s Exchange Summary:", value=f"{r_c.name} ➟ {u_c.name}", inline=False) await ctx.send(f"{ctx.author.mention}{receiver_user.mention}", embed=embed)
def clear_user_desc(): users_ids = database_mongo.get_all_users_list_ids() for i in range(len(users_ids)): u = get_user(users_ids[i]) u.change_description("No Description") database_mongo.save_user(u)
async def embed_blackjack(ctx, bot, u, amount, _type): if _type == "p": if u.primogems < amount: await error.embed_not_enough_primo(ctx) return else: if u.mora < amount: await error.embed_not_enough_mora(ctx) return deck = card.make_deck() card.shuffle(deck) card.shuffle(deck) card.shuffle(deck) bot_hand = [] player_hand = [] bot_hand.append(deck.pop()) bot_hand.append(deck.pop()) player_hand.append(deck.pop()) player_hand.append(deck.pop()) game = await ctx.send( embed=embed_create_blackjack(u, bot_hand, player_hand)) rea_hit = await game.add_reaction("💥") rea_stay = await game.add_reaction("🤚") def check(reaction, user): return str(reaction.emoji) in [ "💥", "🤚" ] and reaction.message == game and user == ctx.author while True: try: reaction, user = await bot.wait_for("reaction_add", timeout=30, check=check) if str(reaction.emoji) == "💥": player_hand.append(deck.pop()) win, total = check_21(player_hand) if win or (total < 21 and len(player_hand) == 5): bot_go = True while bot_go: bot_go = bot_decision(bot_hand, deck) bot_win, bot_total = check_21(bot_hand) if bot_win or (bot_total < 21 and len(bot_hand) == 5): await game.edit( embed=await embed_create_blackjack_final( ctx, u, bot_hand, player_hand, "b", amount, _type)) else: await game.edit( embed=await embed_create_blackjack_final( ctx, u, bot_hand, player_hand, "u", amount, _type)) await game.clear_reactions() break elif total > 21: await game.edit(embed=await embed_create_blackjack_final( ctx, u, bot_hand, player_hand, "y", amount, _type)) await game.clear_reactions() break else: bot_go = bot_decision(bot_hand, deck) await game.edit( embed=embed_create_blackjack(u, bot_hand, player_hand)) await game.remove_reaction(reaction, user) elif str(reaction.emoji) == "🤚": win, total = check_21(player_hand) bot_go = True while bot_go: bot_go = bot_decision(bot_hand, deck) bot_win, bot_total = check_21(bot_hand) await game.edit(embed=await embed_create_blackjack_final( ctx, u, bot_hand, player_hand, check_winner(win, bot_win, total, bot_total), amount, _type )) await game.clear_reactions() break else: await game.remove_reaction(reaction, user) except asyncio.TimeoutError: await ctx.send( f"{ctx.author.mention}, You took too long, Now the game is cancelled." ) tax_amount = 0 if _type == "p": if amount < 160: tax_amount = amount // 2 else: tax_amount = amount // 5 u.primogems -= tax_amount database_mongo.add_to_jackpot_primo(tax_amount) await ctx.send( f"{ctx.author.mention}, {formatter_custom.number_format(tax_amount)} Primogems has been taxed to prevent abuse." ) else: if amount < 10000: tax_amount = amount // 2 else: tax_amount = amount // 5 u.mora -= tax_amount database_mongo.add_to_jackpot_mora(tax_amount) await ctx.send( f"{ctx.author.mention}, {formatter_custom.number_format(tax_amount)} Mora has been taxed to prevent abuse." ) database_mongo.save_user(u) await game.clear_reactions() break
async def buy(self, ctx, u, amount): if self.amount == 0: await error.embed_out_of_stock(ctx) return if self.amount != -1 and self.amount < amount: await error.embed_not_enough_items_to_purchase( ctx, self.item["name"]) return if self.cost_type == "p": currency = u.primogems e = error.embed_not_enough_primo elif self.cost_type == "m": currency = u.mora e = error.embed_not_enough_mora elif self.cost_type == "sd": currency = u.star_dust e = error.embed_not_enough_star_dust elif self.cost_type == "sg": currency = u.star_glitter e = error.embed_not_enough_star_glitter amnt = amount if currency < (amnt * self.cost): await e(ctx) return currency -= (amnt * self.cost) if self.cost_type == "p": u.primogems = currency elif self.cost_type == "m": u.mora = currency elif self.cost_type == "sd": u.star_dust = currency elif self.cost_type == "sg": u.star_glitter = currency my_item = item.get_item(self.item) for i in range(amnt): if my_item.group == "currency": if my_item.URL_name.startswith("primogems"): u.primogems += my_item.count elif my_item.URL_name.startswith("mora"): u.mora += my_item.count elif my_item.group.startswith("character"): u.add_character(character.get_character(my_item.URL_name)) elif my_item.group.startswith("weapon"): u.add_weapon(weapon.get_weapon(my_item.URL_name)) else: u.add_item(my_item) if self.amount != -1: self.amount -= 1 database_mongo.save_user(u) embed = discord.Embed( title="Purchase Successful", description= f"{u.nickname} purchased {formatter_custom.number_format(int(my_item.count * amount))} {my_item.name}.", color=discord.Color.green()) await ctx.send(embed=embed)
def reset_timers(_id): u = get_user(_id) u.last_daily = "" u.last_weekly = "" database_mongo.save_user(u)
def recharge_all_resin(): users_ids = database_mongo.get_all_users_list_ids() for i in range(len(users_ids)): u = get_user(users_ids[i]) u.recharge_resin() database_mongo.save_user(u)
def reset_daily_commissions(_id): u = get_user(_id) u.commissions = {} u.commissions = commission.make_user_commissions() database_mongo.save_user(u)