Skip to content

Commit

Permalink
modified: bot.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Revulate committed Oct 16, 2024
1 parent 5d6a528 commit 8600ab0
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,12 @@ def __init__(self):
self.refresh_token = os.getenv("REFRESH_TOKEN")
nick = os.getenv("BOT_NICK")
prefix = os.getenv("COMMAND_PREFIX", "#")
channels = os.getenv("TWITCH_CHANNELS", "").split(",")
self.initial_channels = [
channel.strip() for channel in channels if isinstance(channel, str) and channel.strip()
]
channels = os.getenv("TWITCH_CHANNELS", "").strip().split(",")
self.initial_channels = [channel.strip() for channel in channels if channel.strip()]

# Check for missing critical environment variables
self._check_env_variables()

# Set initial_channels as an instance variable
self.initial_channels = channels

super().__init__(
token=self.token,
client_id=self.client_id,
Expand Down Expand Up @@ -233,18 +228,12 @@ def load_modules(self):

async def join_channels(self):
for channel in self.initial_channels:
if isinstance(entry, str):
channel = re.sub("[#]", "", entry).lower()
else:
# Handle the unexpected type case
self.logger.error(f"Unexpected type for entry: {type(entry)}, value: {entry}")

try:
self.logger.info(f"Attempting to join channel: {channel}")
await self._connection.join_channels([channel])
self.logger.info(f"Successfully joined channel: {channel}")
except Exception as e:
self.logger.error(f"Failed to join channel {channel}: {e}")
try:
self.logger.info(f"Attempting to join channel: {channel}")
await self._connection.join_channels([channel])
self.logger.info(f"Successfully joined channel: {channel}")
except Exception as e:
self.logger.error(f"Failed to join channel {channel}: {e}")

@commands.command(name="listcommands")
async def list_commands(self, ctx: commands.Context):
Expand Down

0 comments on commit 8600ab0

Please sign in to comment.