async def checker(self): """ Twitch check loop """ l.log("Checking twitch...") if await self.check(self.bot.get_channel(utils.ylcb_config.data["discord"]["announcement_channel_id"])): l.log("Check Successful")
async def outcome_func(self): points = self.cog.econ.get_balance_from_d_id(self.player.id) _cfg = self.cog.config.data["games"]["chance"] embed_dict = { "title": "It\'s a push!", "type": "rich", "timestamp": datetime.datetime.now().isoformat(), "color": 0xffdd00, "fields": [{ "name": "You scored:", "value": self.p_score, "inline": True }, { "name": "I scored:", "value": self.cpu_score, "inline": True }] } self.boost = self.cog.items.get_boost_from_d_id(self.player.id) multiplier = 1 + self.boost if self.p_score > self.cpu_score: multiplier = _cfg["small_multiplier"] + self.boost if self.p_score == 2: multiplier = _cfg["large_multiplier"] + self.boost payout = self.bet * multiplier self.outcome = payout - self.bet self.cog.econ.set_balance_from_d_id(self.player.id, points + payout) self.cog.econ.push_transaction_history_from_id( self.player.id, "Chance Roll", self.outcome) if not self.in_hub: embed_dict["color"] = 0x00ff00 embed_dict["title"] = f"You won ${self.outcome}!" elif self.cpu_score > self.p_score: self.outcome = self.bet * -1 if not self.in_hub: embed_dict["color"] = 0xff0000 embed_dict["title"] = f"You lost ${self.bet}!" self.cog.econ.push_transaction_history_from_id( self.player.id, "Chance Roll", self.outcome) elif self.cpu_score == self.p_score: self.cog.econ.set_balance_from_d_id(self.player.id, points + self.bet) l.log( f"Chance outcome: {str(self.player)}:{self.p_score} | Bet:${self.bet} | Multiplier:{multiplier}x ({self.boost}) | CPU:{self.cpu_score}", channel=l.DISCORD) if not self.in_hub: try: await self.msg.edit(embed=discord.Embed.from_dict(embed_dict)) except: self.msg = await self.ctx.send( embed=discord.Embed.from_dict(embed_dict)) await self.stop()
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"Chance start: {str(self.player)} | Bet:${self.bet}", channel=l.DISCORD) self.playing = True self.p_score = random.randint(2, 12) self.cpu_score = random.randint(2, 12) self.gsm.set_state(self.state_outcome)
async def go_broke(self, ctx): """ Go broke """ try: self.set_balance_from_d_id(ctx.author.id, 0) self.clear_transaction_history_from_id(ctx.author.id) except Exception as e: l.log(e, l.ERR, l.DISCORD) else: await ctx.send(f"{ctx.author.mention}, congrats you're broke...")
async def set_balance(self, ctx, user: discord.Member, amount: float = 0): """Set the given user's balance to amount""" try: self.set_balance_from_d_id(user.id, amount) self.clear_transaction_history_from_id(user.id) self.push_transaction_history_from_id(user.id, "Admin Set Amount", amount) except Exception as e: l.log(e, l.ERR, l.DISCORD) else: await ctx.send( f"{ctx.author.mention}, {user.mention}'s balance is now ${amount}" )
async def add_balance(self, ctx, user: discord.Member, amount: float): """Add an amount to the given user's balance""" try: self.set_balance_from_d_id( user.id, self.get_balance_from_d_id(user.id) + amount) self.push_transaction_history_from_id(ctx.author.id, "Admin Added Amount", amount) except Exception as e: l.log(e, l.ERR, l.DISCORD) else: await ctx.send( f"{ctx.author.mention}, {user.mention}'s balance is now ${self.get_balance_from_d_id(user.id)}" )
async def can_user_play(self, ctx, _cfg: dict, bet: float, points: float, msg: discord.Message = None) -> bool: """ Checks if a user can play a game with given arguments Args: _cfg (`dict`): Game config bet (`float`): How much the user is betting points (`float`): Amount in user's bank msg (`discord.Message`, optional): Message to edit instead of send a new one Returns: `bool`: if user can play game """ bet = round(bet, 2) if not _cfg["enabled"]: await ctx.send( f"{ctx.author.mention}, this game has been disabled by an admin." ) return False if points < bet: if not msg: await ctx.send( f"{ctx.author.mention}, you only have ${points} to bet!") if msg: await msg.edit( f"{ctx.author.mention}, you only have ${points} to bet") return False if _cfg["min_bet"] < 1: _cfg["min_bet"] = 1 self.config.updateFile() l.log("min_bet was lower than 1, min_bet was set to 1", l.FLG) if bet > _cfg["max_bet"] and _cfg["max_bet"] != 0: await ctx.send( f"{ctx.author.mention}, the max bet is {_cfg['max_bet']}") return False return True
async def streamer(self, ctx, twitch_username: str, user: discord.Member = None): """ Makes user an authorized streamer and adds to live announcements Args: twitch_username (`str`): User's twitch username. user (`discord.Member`, optional): User to make streamer if not self. Defaults to `None` """ if not user: user = ctx.author if u.streamer(user): await ctx.send(f"{ctx.author.mention}, that user is already a streamer.") return l.log("streamer check 1") # await self.bot.fetch_guild(ylcb_config.data["discord"]["guild_id"]).get_role(ylcb_config.data["discord"]["streamer_role_id"]) await user.add_roles(ctx.guild.get_role(ylcb_config.data["discord"]["streamer_role_id"])) l.log("streamer check 2") self.db.cursor.execute("UPDATE Users SET twitch_username=? WHERE discord_id=?", (twitch_username, user.id)) self.db.db.commit() l.log("streamer check 3") await ctx.send(f"{user.mention}, {ctx.author.mention} has made you a streamer!")
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 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 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 on_command_error(ctx, error): l.log(str(error), lvl=l.ERR, channel=l.DISCORD) embed = discord.Embed(title="Error!", color=0xff0000, description=f"There was an error proccessing your command!\nReason: {str(error)}") embed.timestamp(datetime.datetime) await ctx.send(embed=embed) return super().cog_command_error(ctx, error)
def set_state(self, new_state): for old_state in self.states: if old_state == new_state: l.log(f"Set State:{new_state}->{self.state}") self.state = new_state
async def add_to_inventory(self, ctx, user: discord.Member, item_id: int): """Adds item to inventory""" try: self.add_item_to_inventory_from_d_id(user.id, item_id) except Exception as e: l.log(e, l.ERR, l.DISCORD) else: await ctx.send(f"{ctx.author.mention}, {self.get_item_from_id(item_id)['name']} was added to {user.mention}'s inventory")
async def set_booster(self, ctx, user: discord.Member, booster_value: int): """Set a user's booster value""" try: self.set_boost_from_d_id(user.id, booster_value) except Exception as e: l.log(e, l.ERR, l.DISCORD) else: await ctx.send(f"{ctx.author.mention}, {user.mention}'s booster value was set to {booster_value}")
async def outcome_func(self): self.multiplier = 1 + self.boost _cfg = self.cog.config.data["games"]["blackjack"] self.embed_dict["fields"] = [{ "name": "Dealer's hand:", "value": self.readable(self.dealer_hand), "inline": True }, { "name": "Dealer's value:", "value": self.total(self.dealer_hand), "inline": True }, { "name": "Bet:", "value": f"${self.bet}", "inline": True }, { "name": "My hand:", "value": self.readable(self.player_hand), "inline": True }, { "name": "My value:", "value": self.total(self.player_hand), "inline": True }] if self.boost: self.embed_dict["footer"] = {"text": f"{self.boost}x boost used"} else: self.embed_dict["footer"] = None if (self.total(self.player_hand) > self.total(self.dealer_hand) or self.total(self.dealer_hand) > 21) and self.total( self.player_hand) <= 21: ## if won self.multiplier = _cfg["small_multiplier"] + self.boost if self.total(self.player_hand) == 21 and len( self.player_hand) == 2: self.multiplier = _cfg["large_multiplier"] + self.boost payout = self.bet * self.multiplier self.outcome = payout - self.bet self.cog.econ.set_balance_from_d_id( self.player.id, self.cog.econ.get_balance_from_d_id(self.player.id) + payout) self.cog.econ.push_transaction_history_from_id( self.player.id, "Blackjack", self.outcome) if not self.in_hub: self.embed_dict["color"] = 0x00ff00 self.embed_dict["title"] = f"You won ${self.outcome}!" elif self.total(self.dealer_hand) > self.total( self.player_hand) or self.total( self.player_hand) > 21: ## if lost self.outcome = self.bet * -1 self.cog.econ.push_transaction_history_from_id( self.player.id, "Blackjack", self.outcome) if not self.in_hub: self.embed_dict["color"] = 0xff0000 self.embed_dict["title"] = f"You lost ${self.bet}!" else: ## if push self.outcome = 0 self.cog.econ.set_balance_from_d_id( self.player.id, self.cog.econ.get_balance_from_d_id(self.player.id) + self.bet) if not self.in_hub: self.embed_dict["title"] = "Push!" self.embed_dict["color"] = 0xffdd00 self.cog.items.reset_boost_from_d_id(self.player.id) l.log( f"Blackjack outcome: {str(self.player)}:{Blackjack.total(self.player_hand)} | Bet:${self.bet} | Multiplier:{self.multiplier}x ({self.boost}) | CPU:{Blackjack.total(self.dealer_hand)}", channel=l.DISCORD) if not self.in_hub: await self.msg.edit(embed=discord.Embed.from_dict(self.embed_dict)) await self.stop()
async def set_inventory(self, ctx, user: discord.Member, items: str): """Set's a user's inventory value""" try: self.set_inventory_from_d_id(user.id, ",".split(items)) except Exception as e: l.log(e, l.ERR, l.DISCORD) else: await ctx.send(f"{ctx.author.mention}, {user.mention}'s inventory value was set to {items}")
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 remove_from_inventory(self, ctx, user: discord.Member, item_id: int): """Removes item from inventory""" try: self.trash_item_from_d_id(user.id, item_id) except Exception as e: l.log(e, l.ERR, l.DISCORD) else: await ctx.send(f"{ctx.author.mention}, {self.get_item_from_id(item_id)['name']} was removed from {user.mention}'s inventory")
@u.is_dev() async def reload_ext(ctx, *ext: tuple): """ Reloads an extension Args: ext (`str`, optional): Extension to reload, if `None` reloads all. Defaults to `None`. """ if not ext: for extension in bot.extensions: bot.reload_extension(extension) await ctx.send(f"{ctx.author.mention}, all extensions reloaded") return bot.reload_extension(ext) await bot.on_ready() await ctx.send(f"{ctx.author.mention}, {ext} reloaded") @reload_ext.error async def reload_ext_error(ctx, error): if isinstance(error, commands.CheckFailure): await ctx.send(f"{ctx.author.mention}, this command can only be used by developers") if isinstance(error, commands.ExtensionNotFound) or isinstance(error, commands.ExtensionNotLoaded): await ctx.send(f"{ctx.author.mention}, this extension does not exist") l.log("Starting script...") if debugging: l.log("Debug mode on", lvl=l.WRN) bot.run(secrets.data["dev_token"]) else: bot.run(secrets.data["token"])