diff --git a/config.yaml b/config.yaml index 221f679..75b01b4 100644 --- a/config.yaml +++ b/config.yaml @@ -234,8 +234,13 @@ LOOPS: ### COMMANDS ### ################## +# The options for ROLE are: +# - None (all users can use this command) +# - Admin (Only users with the discord admin role) +# You can also fill in a custom role name that you use in your server to only enable it for users that have that role +# If you want multiple roles then use a comma like `ROLE: Admin, Pro` + COMMANDS: - # Role options are: None and Admin ANALYZE: ENABLED: True ROLE: None @@ -244,10 +249,6 @@ COMMANDS: ENABLED: True ROLE: None - FOLLOW: - ENABLED: True - ROLE: None - HELP: ENABLED: True ROLE: None @@ -256,15 +257,15 @@ COMMANDS: ENABLED: True ROLE: None - SENTIMENT: + RESTART: ENABLED: True - ROLE: None + ROLE: Admin - STOCK: + SENTIMENT: ENABLED: True ROLE: None - RESTART: + STOCK: ENABLED: True ROLE: None @@ -278,7 +279,8 @@ LISTENERS: ON_RAW_REACTION_ADD: ENABLED: True CHANNEL: 💸┃highlights - ROLE: None + ROLE: Admin + # Sends a custom message when a member joins ON_MEMBER_JOIN: ENABLED: True diff --git a/src/cogs/commands/restart.py b/src/cogs/commands/restart.py index 137334c..166500b 100644 --- a/src/cogs/commands/restart.py +++ b/src/cogs/commands/restart.py @@ -1,14 +1,11 @@ import os import sys -import discord -import pandas as pd -from discord.commands import Option from discord.commands.context import ApplicationContext from discord.ext import commands from util.disc_util import conditional_role_decorator -from util.vars import config, get_json_data, logger +from util.vars import config class Restart(commands.Cog): diff --git a/src/cogs/listeners/on_raw_reaction_add.py b/src/cogs/listeners/on_raw_reaction_add.py index 2a876c7..b232af9 100644 --- a/src/cogs/listeners/on_raw_reaction_add.py +++ b/src/cogs/listeners/on_raw_reaction_add.py @@ -65,7 +65,16 @@ async def on_raw_reaction_add( ): await self.classify_reaction(reaction, message) elif str(reaction.emoji) == "💸": - await self.highlight(message, reaction.member) + # Check if user has the role or is an admin + if config["LISTENERS"]["ON_RAW_REACTION_ADD"]["ROLE"] != "None": + if ( + config["LISTENERS"]["ON_RAW_REACTION_ADD"]["ROLE"] + in reaction.member.roles + or reaction.member.guild_permissions.administrator + ): + await self.highlight(message, reaction.member) + else: + await self.highlight(message, reaction.member) elif str(reaction.emoji) == "❤️": await self.send_dm(message, reaction.member) diff --git a/src/util/disc_util.py b/src/util/disc_util.py index ad3719e..12cf7ef 100644 --- a/src/util/disc_util.py +++ b/src/util/disc_util.py @@ -12,6 +12,14 @@ def noop_decorator(func): def conditional_role_decorator(role: str): + if "," in role: + roles = role.split(",") + # remove whitespace + roles = [r.strip() for r in role] + # capitalize + roles = [r.capitalize() for r in role] + return commands.has_any_role(*roles) + role = role.capitalize() if role == "Admin": return commands.has_permissions(administrator=True) @@ -19,7 +27,6 @@ def conditional_role_decorator(role: str): return noop_decorator return commands.has_role(role) - # multiple roles: commands.has_any_role("Big Cheese", "Medium Cheese") def get_guild(bot: commands.Bot) -> discord.Guild: diff --git a/src/util/yf_data.py b/src/util/yf_data.py index 256ed19..e2d6be0 100644 --- a/src/util/yf_data.py +++ b/src/util/yf_data.py @@ -16,8 +16,9 @@ def yf_info(ticker: str, do_format_change: bool = True): + # This can be blocking try: - stock_info = Ticker(ticker, asynchronous=False).price + stock_info = Ticker(ticker, asynchronous=True).price except Exception as e: logger.error(f"Error in getting Yahoo Finance data for {ticker}: {e}") return None