async def leaderboard(self, ctx): """ Show server leaderboard """ everyone = self.db.cursor.execute("SELECT * FROM Users").fetchall() lb: list = self.db.cursor.execute( "SELECT * FROM Users ORDER BY balance DESC").fetchmany(5) server_total: int = 0 fields: list = [] for entry in everyone: server_total += entry[4] for i, entry in enumerate(lb): entry_user = await self.bot.fetch_user(entry[2]) fields.append({ "name": f"{i+1}. {u.discordify(str(entry_user))}", "value": f"({str(round(entry[4]/server_total*100, 1))}%) ${'{:,}'.format(entry[4])}" }) embed_dict = { "title": f"Leaderboard (${server_total})", "type": "rich", "timestamp": datetime.datetime.now().isoformat(), "color": 0x00cc99, "fields": fields, "author": { "name": u.discordify(str(self.bot.user)), "icon_url": str(self.bot.user.avatar_url) } } await ctx.send(embed=discord.Embed.from_dict(embed_dict))
async def open_inventory(self, ctx, user: discord.Member = None): """ Open your inventory Args: user (`discord.Member`, optional): If specified will open user's inventory instead of own. Defaults to `None`. """ if not user: user = ctx.author inv = self.get_inventory_from_d_id(user.id) description = "" if not inv: description = "Your inventory is empty :( Get some items from airdrops!" else: for _id in inv: item = self.get_item_from_id(_id) description = description + f"{item['name']} [#{_id}]: {item['desc']}\n" description.strip() embed_dict = { "title":"Inventory", "type": "rich", "timestamp": datetime.datetime.now().isoformat(), "color": 0x6275be, "description": description, "author": { "name": u.discordify(str(user)), "icon_url": str(user.avatar_url) } } await ctx.send(embed=discord.Embed.from_dict(embed_dict))
async def balance(self, ctx, user: discord.Member = None): """ Returns you or another user's balance Args: user (`discord.Member`, optional): User to get balance for. Defaults to `None`. """ if not user: user = ctx.author points = self.get_balance_from_d_id(user.id) th: list = self.get_transaction_history_from_id(user.id) description: str = "" if th: description = "Transaction History\nYour 3 recent transactions\n\n" for entry in th: entry: dict if entry["amount"] > 0: emoji = "🟩" else: emoji = "🟥" if len(entry["place"]) > 20: entry["place"] = entry["place"][:20] entry["place"][19] = "…" description = description + f"{emoji} {entry['place'].ljust(20,'.')} ${str(entry['amount'])}\n" embed_dict = { "title": f"${str(points)}", "description": description, "type": "rich", "timestamp": datetime.datetime.now().isoformat(), "color": 0x00ff00, "author": { "name": u.discordify(str(user)), "icon_url": str(user.avatar_url) } } await ctx.send(embed=discord.Embed.from_dict(embed_dict))
async def m_outcome(self): self.embed_dict = { "title": "Game/Outcome", "color": 0x00ff00, "fields": [ { "name": "Game Outcome", "value": f"${self.game_outcome}", "inline": True }, { "name": "Session Outcome", "value": f"${self.session_outcome}", "inline": True }, { "name": "Current Balance", "value": f"${self.cog.econ.get_balance_from_d_id(self.player.id)}", "inline": True }, ], "author": { "name": u.discordify(str(self.player)), "icon_url": str(self.player.avatar_url) }, "footer": { "text": "Directions: ✅: Home | ❌: Exit" } } await self.msg.edit(embed=discord.Embed.from_dict(self.embed_dict)) await self.msg.add_reaction("✅") await self.msg.add_reaction("❌") await sleep(0.3) def check(payload: discord.RawReactionActionEvent): return payload.user_id != self.bot.user and str(payload.emoji) in [ "✅", "❌" ] and payload.message_id == self.msg.id response = await self.bot.wait_for("raw_reaction_add", check=check) if str(response.emoji) == "✅": self.gsm.set_state(self.state_menu) if str(response.emoji) == "❌": self.gsm.set_state(self.state_exit)
def __init__(self, bot, ctx): """ Hub to play all your games Args: bot (`commands.Bot`): `commands.Bot` instance ctx (`commands.Context`): Command context """ self.bot = bot self.alive = True self.msg = None self.embed_dict = { "title": "Game Hub", "type": "rich", "timestamp": datetime.datetime.now().isoformat(), "color": 0x0000ff, "fields": [], "author": { "name": u.discordify(str(self.bot.user)), "icon_url": str(self.bot.user.avatar_url) } } self.bet: float = 0 self.prev_bet: float = 0 self.game_outcome: float = 0 self.session_outcome: float = 0 self.games_played = 0 self.ctx = ctx self.player = ctx.author self.emoji: str = "" self.cog: games = self.bot.get_cog("games") self.state_menu = "menu", self.menu self.state_betting = "betting", self.betting self.state_game = "game", self.m_game self.state_error = "error", self.error self.state_outcome = "outcome", self.m_outcome self.state_exit = "exit", self.m_exit self.gsm: StateManager = StateManager([ self.state_menu, self.state_betting, self.state_game, self.state_error, self.state_outcome, self.state_exit ], self.state_menu)
async def error(self): self.embed_dict = { "title": "Game Hub/Error", "type": "rich", "timestamp": datetime.datetime.now().isoformat(), "color": 0xff0000, "fields": [{ "name": "Error", "value": "It appears your game has errored...", "inline": True }], "author": { "name": u.discordify(str(self.bot.user)), "icon_url": str(self.bot.user.avatar_url) }, "footer": { "text": "Directions: ⬅️: Home | ❌: Exit" } } await self.msg.edit(embed=discord.Embed.from_dict(self.embed_dict)) await self.msg.clear_reactions() await self.msg.add_reaction("⬅️") await self.msg.add_reaction("❌") await sleep(0.3) def check(payload: discord.RawReactionActionEvent): return payload.user_id != self.bot.user and str(payload.emoji) in [ "🔴", "🟠", "🟡", "🟢", "🔵", "🟣", "⚫", "✅", "❌", "⬅️" ] and payload.message_id == self.msg.id response = await self.bot.wait_for("raw_reaction_add", check=check) if str(response.emoji) == "⬅️": self.gsm.set_state(self.state_menu) if str(response.emoji) == "❌": self.gsm.set_state(self.state_exit)
async def view_item(self, ctx, item_id: int): """ Inspect an item Args: item_id (`int`): ID of the item you want to inspect """ item = self.get_item_from_id(item_id) embed_dict = { "title": item["name"], "type": "image", "description": item["desc"], "image": {"url": item["texture_url"]}, "timestamp": datetime.datetime.now().isoformat(), "color": 0x6275be, "author": { "name": u.discordify(str(ctx.author)), "icon_url": str(ctx.author.avatar_url) } } await ctx.send(embed=discord.Embed.from_dict(embed_dict))
async def m_exit(self): self.embed_dict = { "title": "Game/Session", "color": 0x00ff00, "fields": [ { "name": "Games Played", "value": f"{self.games_played}", "inline": True }, { "name": "Session Outcome", "value": f"${self.session_outcome}", "inline": True }, { "name": "Avg. $ per Game", "value": f"${(self.session_outcome/(self.games_played if self.games_played else 1))}", "inline": True }, { "name": "Current Balance", "value": f"${self.cog.econ.get_balance_from_d_id(self.player.id)}" }, ], "author": { "name": u.discordify(str(self.player)), "icon_url": str(self.player.avatar_url) } } self.update_timestamp() await self.msg.edit(embed=discord.Embed.from_dict(self.embed_dict)) await self.msg.clear_reactions() await self.stop()
async def menu_screen(self): description = "🃏 Blackjack\n🎲 Chance Roll\n❌ Exit Hub" if self.emoji: description = description + "\n⬅️ Previous Game" self.embed_dict = { "title": "Game Hub", "description": description, "color": 0x0000ff, "author": { "name": u.discordify(str(self.bot.user)), "icon_url": str(self.bot.user.avatar_url) } } self.update_timestamp() if self.msg: await self.msg.edit(embed=discord.Embed.from_dict(self.embed_dict)) else: self.msg = await self.ctx.send( embed=discord.Embed.from_dict(self.embed_dict)) await self.msg.clear_reactions() await self.msg.add_reaction("🃏") await self.msg.add_reaction("🎲") await self.msg.add_reaction("❌") if self.emoji: await self.msg.add_reaction("⬅️")
async def request(self, ctx, sender: discord.Member, amount: float = 50, *, message: str = None): """ Request money from another user Args: sender (`discord.Member`): User you want money from amount (`float`, optional): Amount to request. Defaults to `50`. message (`str`, optional): Message to user. Defaults to `None`. """ if sender == ctx.author: await ctx.send( f"{ctx.author.mention}, you cannot request money from yourself" ) return if self.can_pay_amount(sender.id, amount): l.log( f"Money Request: {str(ctx.author)} | Amount:${amount} | Payer:{str(sender)} | Status: APPROVED,PENDING", channel=l.DISCORD) embed_dict = { "title": "Money Request [PENDING]", "type": "rich", "timestamp": datetime.datetime.now().isoformat(), "color": 0xff8800, "fields": [ { "name": "Pay To:", "value": u.discordify(str(ctx.author)), "inline": True }, { "name": "Balance:", "value": "$" + str(amount), "inline": True }, { "name": "From:", "value": u.discordify(str(sender)), "inline": True }, ] } if message: embed_dict["fields"].append({ "name": "Message:", "value": message }) embed = discord.Embed.from_dict(embed_dict) msg: dicsord.Message = await ctx.send(sender.mention, embed=embed) await msg.add_reaction("✅") await msg.add_reaction("❎") await sleep(0.3) def check(payload: discord.RawReactionActionEvent): return payload.member == sender and str(payload.emoji) in [ "✅", "❎" ] and payload.message_id == msg.id payload = await self.bot.wait_for("raw_reaction_add", check=check) if str(payload.emoji) == "✅": embed_dict["title"] = "Money Request [ACCEPTED]" embed_dict["color"] = 0x00ff00 try: self.set_balance_from_d_id( sender.id, self.get_balance_from_d_id(sender.id) - amount) self.push_transaction_history_from_id( sender.id, "Transfer", amount * -1) except Exception as e: l.log(e, l.ERR, l.DISCORD) else: self.set_balance_from_d_id( ctx.author.id, self.get_balance_from_d_id(ctx.author.id) + amount) self.push_transaction_history_from_id(ctx.author.id, "Transfer", amount) l.log( f"Money Request: {str(ctx.author)} | Amount:${amount} | Payer:{str(sender)} | Status: ACCEPTED,PAID", channel=l.DISCORD) elif str(payload.emoji) == "❎": embed_dict["title"] = "Money Request [DECLINED]" embed_dict["color"] = 0xff0000 l.log( f"Money Request: {str(ctx.author)} | Amount:${amount} | Payer:{str(sender)} | Status: DECLINED,REFUNDED", channel=l.DISCORD) self.set_balance_from_d_id( sender.id, self.get_balance_from_d_id(sender.id) + amount) embed_dict["timestamp"] = datetime.datetime.now().isoformat() await msg.edit(content=None, embed=discord.Embed.from_dict(embed_dict)) try: await msg.clear_reactions() except Exception as e: l.log(e, l.WRN, l.DISCORD) else: l.log( f"Money Request: {str(ctx.author)} | Amount:${amount} | Payer:{str(sender)} | Status: DECLINED", channel=l.DISCORD) await ctx.send( f"{ctx.author.mention}, that user has insufficient funds!")
async def pay(self, ctx, reciever: discord.Member, amount: float = 50, *, message: str = None): """ Pay another user Args: reciever (`discord.Member`): Person to pay money to amount (`float`, optional): Amount to pay. Defaults to `50`. message (`str`, optional): Message to user. Defaults to `None`. """ if reciever == ctx.author: await ctx.send( f"{ctx.author.mention}, you cannot send money to yourself") return amount = round(amount, 2) if self.can_pay_amount(ctx.author.id, amount): l.log( f"Check: {u.discordify(str(ctx.author))} | Amount:${amount} | Reciever:{str(reciever)} | Status: AWAITING APPROVAL", channel=l.DISCORD) self.set_balance_from_d_id( ctx.author.id, self.get_balance_from_d_id(ctx.author.id) - amount) embed_dict = { "title": "Check [AWAITING APPROVAL]", "type": "rich", "timestamp": datetime.datetime.now().isoformat(), "color": 0xff8800, "fields": [ { "name": "Pay To:", "value": u.discordify(str(reciever)), "inline": True }, { "name": "Balance:", "value": "$" + str(amount), "inline": True }, { "name": "From:", "value": u.discordify(str(ctx.author)), "inline": True }, ] } if message: embed_dict["fields"].append({ "name": "Message:", "value": message }) embed = discord.Embed.from_dict(embed_dict) msg: dicsord.Message = await ctx.send( f"Are you sure you want to pay this user ${amount}", embed=embed) await msg.add_reaction("✅") await msg.add_reaction("❎") await sleep(0.3) def check(payload: discord.RawReactionActionEvent): return payload.user_id == ctx.author.id and str( payload.emoji) in ["✅", "❎" ] and payload.message_id == msg.id payload = await self.bot.wait_for("raw_reaction_add", check=check) if str(payload.emoji) == "✅": embed_dict["title"] = "Check [PENDING]" l.log( f"Check: {str(ctx.author)} | Amount:${amount} | Reciever:{str(reciever)} | Status: APPROVED,PENDING", channel=l.DISCORD) elif str(payload.emoji) == "❎": await msg.delete() await ctx.message.delete() self.set_balance_from_d_id( ctx.author.id, self.get_balance_from_d_id(ctx.author.id) + amount) l.log( f"Check: {str(ctx.author)} | Amount:${amount} | Reciever:{str(reciever)} | Status: CANCELED", channel=l.DISCORD) embed = discord.Embed.from_dict(embed_dict) await msg.edit(content=reciever.mention, embed=embed) await sleep(0.3) def check(payload: discord.RawReactionActionEvent): return payload.member == reciever and str(payload.emoji) in [ "✅", "❎" ] and payload.message_id == msg.id payload = await self.bot.wait_for("raw_reaction_add", check=check) if str(payload.emoji) == "✅": embed_dict["title"] = "Check [ACCEPTED]" embed_dict["color"] = 0x00ff00 try: self.set_balance_from_d_id( reciever.id, self.get_balance_from_d_id(reciever.id) - amount) self.push_transaction_history_from_id( ctx.author.id, "Transfer", -1 * amount) except Exception as e: l.log(e, l.ERR, l.DISCORD) else: self.set_balance_from_d_id( ctx.author.id, self.get_balance_from_d_id(ctx.author.id) + amount) self.set_balance_from_d_id( reciever.id, self.get_balance_from_d_id(reciever.id) + amount) self.push_transaction_history_from_id(reciever.id, "Transfer", amount) l.log( f"Check: {str(ctx.author)} | Amount:${amount} | Reciever:{str(reciever)} | Status: ACCEPTED,PAID", channel=l.DISCORD) elif str(payload.emoji) == "❎": embed_dict["title"] = "Check [DECLINED]" embed_dict["color"] = 0xff0000 l.log( f"Check: {str(ctx.author)} | Amount:${amount} | Reciever:{str(reciever)} | Status: DECLINED,REFUNDED", channel=l.DISCORD) self.set_balance_from_d_id( ctx.author.id, self.get_balance_from_d_id(ctx.author.id) + amount) embed_dict["timestamp"] = datetime.datetime.now().isoformat() await msg.edit(content=None, embed=discord.Embed.from_dict(embed_dict)) try: await msg.clear_reactions() except Exception as e: l.log(e, l.WRN, l.DISCORD) else: l.log( f"Check: {str(ctx.author)} | Amount:${amount} | Reciever:{str(reciever)} | Status: BANK DECLINED", channel=l.DISCORD) await ctx.send( f"{str(ctx.author.mention)}, you only have ${self.get_balance_from_d_id(ctx.author.id)}" )
async def info(self, ctx, user: discord.Member = None): """ Get server or user info Args: user (`discord.Member`, optional): If defined gets user info instead of server info. Defaults to `None`. """ server_mode = True if not user else False if server_mode: perma_link = "" for invite in await ctx.guild.invites(): invite: discord.Invite if not invite.revoked and invite.max_age == 0 and not invite.temporary and invite.max_uses == 0: perma_link = str(invite) break owner = await self.bot.fetch_user(ctx.guild.owner_id) created = datetime.strptime(str(ctx.guild.created_at), self.discord_time_format) embed_dict: dict = { "type": "rich", "timestamp": datetime.now().isoformat(), "color": 0x6495ed, "fields": [{ "name": "Owner", "value": u.discordify(str(owner)), "inline": True }, { "name": "Server Created", "value": created.strftime("%m/%d/%Y %H:%M"), "inline": True }, { "name": "Members", "value": str(ctx.guild.member_count), "inline": True }, { "name": "Region", "value": str(ctx.guild.region), "inline": True }, { "name": "Boosters", "value": str(ctx.guild.premium_subscription_count), "inline": True }], "author": { "name": u.discordify(ctx.guild.name), "icon_url": str(ctx.guild.icon_url) }, "footer": { "text": f"ID: {ctx.guild.id}" } } if ctx.guild.description: embed_dict["description"] = ctx.guild.description if perma_link: embed_dict["fields"].append({ "name": "Perma Link", "value": perma_link, "inline": True }) await ctx.send(embed=discord.Embed.from_dict(embed_dict)) else: embed_dict: dict = { "title": str(user), "type": "rich", "color": user.color.value, "timestamp": datetime.now().isoformat(), "fields": [{ "name": "Account Created", "value": datetime.strptime( str(user.created_at), self.discord_time_format).strftime("%m/%d/%Y %H:%M"), "inline": True }, { "name": "Status", "value": user.status[0], "inline": True }], "author": { "name": u.discordify(str(user)), "icon_url": str(user.avatar_url) }, "footer": { "text": f"ID: {user.id}" } } if user.activity: if type(user.activity) == discord.Spotify: embed_dict["fields"].append({ "name": "Activity", "value": "Spotify", "inline": True }) embed_dict["fields"].append({ "name": "Song", "value": f"{user.activity.title} - {', '.join(user.activity.artists)} - {user.activity.album}", "inline": True }) else: embed_dict["fields"].append({ "name": "Activity", "value": user.activity.name, "inline": True }) if user.premium_since: embed_dict["fields"].append({ "name": "Nitro Since", "value": datetime.strptime( str(user.premium_since), self.discord_time_format).strftime("%m/%d/%Y %H:%M"), "inline": True }) await ctx.send(embed=discord.Embed.from_dict(embed_dict))
async def check(self, streamerChannel: discord.TextChannel) -> bool: """ Checks if a streamer is live and announces it Args: streamerChannel (`discord.TextChannel`): Channel to announce in Returns: `bool`: If check succeeds """ for streamer in self.db.cursor.execute("SELECT * FROM Users").fetchall(): if not streamer[0]: continue username = streamer[0] message_id = streamer[1] discord_id = streamer[2] response = streamer[3] l.log(f"\tChecking if {username} is live...") headers = { "User-Agent": "Your user agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36 OPR/63.0.3368.51 (Edition beta)", "Client-ID": secrets.data["twitch_client_id"], "Authorization": f"Bearer {secrets.data['twitch_secret']}" } r = requests.get(f"https://api.twitch.tv/helix/streams?user_login={username}", headers=headers) try: streamData = r.json()["data"] except KeyError: l.log(f"\t\tTwitch error: {r.json()['error']}: {r.json()['status']}", l.ERR) continue if type(streamData) == list and streamData: streamData = streamData[0] r.close() if streamData: r = requests.get(f"https://api.twitch.tv/helix/games?id={streamData['game_id']}", headers=headers) gameData = r.json()["data"] if type(gameData) == list and gameData: gameData = gameData[0] r.close() import time user: discord.User = await self.bot.fetch_user(int(streamer[2])) embed_dict = { "title": streamData["title"], "url": f"https://twitch.tv/{username}", "type": "url", "timestamp": datetime.datetime.fromtimestamp(time.mktime(time.strptime(streamData["started_at"], "%Y-%m-%dT%H:%M:%SZ")), datetime.timezone.utc).isoformat(), "footer": {"text": "Started streaming at (UTC):"}, "color": 0x8000ff, "fields": [ {"name": "Game", "value": gameData["name"], "inline": True}, {"name": "Viewers", "value": streamData["viewer_count"], "inline": True} ], "author": { "name": u.discordify(str(user)), "icon_url": str(user.avatar_url) }, "thumbnail": { "url": gameData["box_art_url"].format(width=390, height=519), "width": 390, "height": 519 }, "image": { "url": streamData["thumbnail_url"].format(width=1280, height=720), "width": 1280, "height": 720 } } embed = discord.Embed.from_dict(embed_dict) if not message_id: l.log(f"\t\t{username} is now live, announcing stream...") if "--debug" not in argv: msg = await streamerChannel.send(f"@everyone {user.mention} is live!", embed=embed) else: msg = await streamerChannel.send(f"{user.mention} is live!", embed=embed) self.db.cursor.execute("UPDATE Users SET message_id=? WHERE twitch_username=?", (msg.id, username)) self.db.db.commit() elif response != streamData: msg = await streamerChannel.fetch_message(streamer[1]) l.log(f"\t\tUpdating {username}\'s live message...") if "--debug" not in argv: msg = await msg.edit(content=f"@everyone {user.mention} is live!", embed=embed) else: msg = await msg.edit(content=f"{user.mention} is live!", embed=embed) self.db.cursor.execute("UPDATE Users SET response=? WHERE twitch_username=?", (json.dumps(streamData), username)) self.db.db.commit() elif message_id: l.log(f"\t\t{username} is no longer live, deleting message...") try: msg = await streamerChannel.fetch_message(streamer[1]) await msg.delete() except: l.log(f"\t\t\tNo message to delete...") self.db.cursor.execute("UPDATE Users SET message_id=?,response=? WHERE twitch_username=?", (None, "{}", username)) self.db.db.commit() return True
async def game(self): self.econ.set_balance_from_d_id( self.player.id, self.econ.get_balance_from_d_id(self.player.id) - self.bet) l.log(f"Blackjack start: {str(self.player)} | Bet:${self.bet}", channel=l.DISCORD) self.playing = True self.embed_dict = { "title": "Ongoing 21 Game", "type": "rich", "color": 0xffdd00, "author": { "name": u.discordify(str(self.player)), "icon_url": str(self.player.avatar_url) }, "footer": { "text": "Directions: 🔴: Stand | 🟢: Hit" } } if self.boost: self.embed_dict["footer"] = { "text": f"Directions: 🔴: Stand | 🟢: Hit | {self.boost}x Boost applied" } await self.update_embed(self.dealer_hand, self.player_hand) if (self.total(self.dealer_hand) == 21 and len(self.dealer_hand) == 2) or (self.total(self.player_hand) == 21 and len(self.player_hand) == 2): self.playing = False self.gsm.set_state(self.state_outcome) return if not self.in_hub: self.msg = await self.ctx.send( embed=discord.Embed.from_dict(self.embed_dict)) else: await self.msg.edit(embed=discord.Embed.from_dict(self.embed_dict)) await self.msg.add_reaction("🔴") await self.msg.add_reaction("🟢") while self.playing: await sleep(0.3) def check(payload: discord.RawReactionActionEvent): return payload.user_id == self.player.id and str( payload.emoji) in ["🔴", "🟢" ] and payload.message_id == self.msg.id payload = await self.bot.wait_for("raw_reaction_add", check=check) if str(payload.emoji) == "🟢": self.hit(self.player_hand) if self.total(self.player_hand) > 21: self.playing = False await self.update_embed(self.dealer_hand, self.player_hand) elif str(payload.emoji) == "🔴": self.playing = False while self.total(self.dealer_hand) < 17 or self.s17_hit(): self.hit(self.dealer_hand) await self.update_embed(self.dealer_hand, self.player_hand) await self.msg.edit(embed=discord.Embed.from_dict(self.embed_dict)) await self.msg.clear_reactions() self.gsm.set_state(self.state_outcome)
async def airdrop_spawner(self): chance = random.randint(1, 100) if debugging: return if chance < 60: l.log("Airdrop Spawned") money = random.randint(10, 1000) embed_dict = { "title": "Airdrop!", "description": f"Money: ${money}\n", "type": "rich", "timestamp": datetime.datetime.now().isoformat(), "color": 0xff8800, "author": { "name": u.discordify(str(self.bot.user)), "icon_url": str(self.bot.user.avatar_url) } } rand_id = random.randint(1, 10) try: item = self.items.get_item_from_id(rand_id) except: item = None if item: embed_dict["description"] = embed_dict[ "description"] + f"Items: 1x {item['name']}" embed = discord.Embed.from_dict(embed_dict) channel = await self.bot.fetch_channel( ylcb_config.data["discord"]["event_channel_id"]) if debugging: msg: discord.Message = await channel.send(embed=embed) else: msg: discord.Message = await channel.send("@here", embed=embed) await msg.add_reaction("🛄") await sleep(0.3) def check(payload: discord.RawReactionActionEvent): return payload.user_id != self.bot.user and str( payload.emoji) == "🛄" and payload.message_id == msg.id try: payload = await self.bot.wait_for("raw_reaction_add", check=check, timeout=300) except TimeoutError: await msg.delete() claimed = False user = await self.bot.fetch_user(payload.user_id) reason = "" try: self.econ.set_balance_from_d_id( payload.user_id, self.econ.get_balance_from_d_id(payload.user_id) + money) self.econ.push_transaction_history_from_id( payload.user_id, "Airdrop", money) if item: self.items.add_item_to_inventory_from_d_id( payload.user_id, item["id"]) except Exception as e: reason = str(e) else: claimed = True l.log(f"{str(user)} claimed an airdrop worth ${money}", channel=l.DISCORD) if claimed: embed_dict["title"] = "Claimed!" embed_dict["timestamp"] = datetime.datetime.now().isoformat() embed_dict["color"] = 0x00ff00 embed_dict["author"] = { "name": u.discordify(str(user)), "icon_url": str(user.avatar_url) } else: embed_dict["title"] = "Error!" embed_dict["timestamp"] = datetime.datetime.now().isoformat() embed_dict["color"] = 0xff0000 embed_dict[ "description"] = f"Error: There was an error collecting airdrop rewards\nReason: {reason}" embed = discord.Embed.from_dict(embed_dict) await msg.edit(content=None, embed=embed)
async def betting_screen(self): self.update_timestamp() self.embed_dict = { "title": f"Bet: ${str(self.bet)}", "color": 0x0000ff, "fields": [ { "name": "🔴", "value": "+$1", "inline": True }, { "name": "🟠", "value": "+$5", "inline": True }, { "name": "🟡", "value": "+$10", "inline": True }, { "name": "🟢", "value": "+$50", "inline": True }, { "name": "🔵", "value": "+$100", "inline": True }, { "name": "🟣", "value": "+$500", "inline": True }, { "name": "⚫", "value": "+$1000", "inline": True }, { "name": "✅", "value": "Start Game", "inline": True }, ], "author": { "name": u.discordify(str(self.bot.user)), "icon_url": str(self.bot.user.avatar_url) } } if self.prev_bet: self.embed_dict["fields"].append({ "name": "⬅️", "value": "Last Bet", "inline": True }) await self.msg.edit(embed=discord.Embed.from_dict(self.embed_dict))