Skip to content

Commit 02f5898

Browse files
fix: more lint errors
1 parent f55c099 commit 02f5898

File tree

7 files changed

+41
-25
lines changed

7 files changed

+41
-25
lines changed

gitcord/bot.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from .config import config
1111
from .events import setup_events
12-
from .utils.logger import logger
12+
from .utils.logger import main_logger as logger
1313

1414

1515
class GitCordBot(commands.Bot):
@@ -57,16 +57,17 @@ async def _load_cogs(self) -> None:
5757
except Exception as e:
5858
logger.error("Failed to load cogs: %s", e)
5959

60-
async def on_command_error(self, ctx: commands.Context, error: commands.CommandError) -> None:
60+
async def on_command_error(self, context, error):
6161
"""Global command error handler."""
6262
logger.error("Global command error: %s", error)
63-
6463
if isinstance(error, commands.CommandNotFound):
65-
await ctx.send("Command not found. Try `!hello` or `!ping`!")
64+
await context.send("Command not found. Try `!hello` or `!ping`!")
6665
elif isinstance(error, commands.MissingPermissions):
67-
await ctx.send("You don't have permission to use this command!")
66+
await context.send("You don't have permission to use this command!")
67+
elif isinstance(error, commands.CommandError):
68+
await context.send(f"A command error occurred: {error}")
6869
else:
69-
await ctx.send(f"An error occurred: {error}")
70+
raise error
7071

7172

7273
async def main() -> None:

gitcord/cogs/general.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import requests
1212
from bs4 import BeautifulSoup
1313

14-
from ..utils.logger import logger
14+
from ..utils.logger import main_logger as logger
1515
from ..utils.helpers import format_latency, create_embed
1616

1717

@@ -90,8 +90,10 @@ async def fetchurl_prefix(self, ctx: commands.Context, url: str) -> None:
9090
color=discord.Color.red()
9191
)
9292
await ctx.send(embed=embed)
93-
94-
except Exception as e:
93+
except discord.DiscordException as e:
94+
logger.error("Discord error in fetchurl command: %s", e)
95+
await ctx.send("A Discord error occurred.")
96+
except Exception as e: # pylint: disable=broad-except
9597
logger.error("Error in fetchurl command: %s", e)
9698
embed = create_embed(
9799
title="❌ Unexpected Error",
@@ -167,8 +169,10 @@ async def fetchurl(self, interaction: discord.Interaction, url: str) -> None:
167169
color=discord.Color.red()
168170
)
169171
await interaction.followup.send(embed=embed)
170-
171-
except Exception as e:
172+
except discord.DiscordException as e:
173+
logger.error("Discord error in fetchurl command: %s", e)
174+
await interaction.followup.send("A Discord error occurred.")
175+
except Exception as e: # pylint: disable=broad-except
172176
logger.error("Error in fetchurl command: %s", e)
173177
embed = create_embed(
174178
title="❌ Unexpected Error",
@@ -222,4 +226,4 @@ async def on_command_error(self, ctx: commands.Context, error: commands.CommandE
222226

223227
async def setup(bot: commands.Bot) -> None:
224228
"""Set up the General cog."""
225-
await bot.add_cog(General(bot))
229+
await bot.add_cog(General(bot))

gitcord/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ def activity_name(self, value: str) -> None:
4444

4545

4646
# Global configuration instance
47-
config = Config()
47+
config = Config()

gitcord/events.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
import discord
77
from discord.ext import commands
88

9-
from .utils.logger import logger
9+
from .utils.logger import main_logger as logger
1010
from .config import config
1111

1212

13-
class EventHandler:
13+
class EventHandler: # pylint: disable=too-few-public-methods
1414
"""Handles Discord bot events."""
1515

1616
def __init__(self, bot: commands.Bot):
@@ -43,7 +43,10 @@ async def _send_restart_messages(self) -> None:
4343
try:
4444
await channel.send("Bot has restarted successfully!")
4545
logger.info("Sent restart message to %s in %s", channel.name, guild.name)
46-
except Exception as e:
46+
except discord.DiscordException as e:
47+
logger.error("Failed to send message to %s in %s: %s",
48+
channel.name, guild.name, e)
49+
except Exception as e: # pylint: disable=broad-except
4750
logger.error("Failed to send message to %s in %s: %s",
4851
channel.name, guild.name, e)
4952
break # Only send to the first available channel
@@ -63,7 +66,9 @@ async def _sync_commands(self) -> None:
6366
synced_global = await self.bot.tree.sync()
6467
logger.info("Synced %d command(s) globally", len(synced_global))
6568

66-
except Exception as e:
69+
except discord.DiscordException as e:
70+
logger.error("Failed to sync commands: %s", e)
71+
except Exception as e: # pylint: disable=broad-except
6772
logger.error("Failed to sync commands: %s", e)
6873

6974

gitcord/utils/helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def format_latency(latency: float) -> str:
2121
return f"{round(latency * 1000)}ms"
2222

2323

24+
# pylint: disable=too-many-arguments, too-many-positional-arguments
2425
def create_embed(
2526
title: str,
2627
description: str,

gitcord/utils/logger.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,31 @@ def setup_logger(name: str = "gitcord", level: int = logging.INFO) -> logging.Lo
2424
if not logger.handlers:
2525
handler = logging.StreamHandler()
2626
formatter = logging.Formatter(
27-
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
27+
'%(asctime)s - %(name)s - %(levelname)s - '
28+
'%(message)s'
29+
)
30+
handler.setFormatter(
31+
formatter
2832
)
29-
handler.setFormatter(formatter)
3033
logger.addHandler(handler)
3134

3235
return logger
3336

3437

35-
def log_error(logger: logging.Logger, error: Exception, context: Optional[str] = None) -> None:
38+
def log_error(log_instance: logging.Logger, error: Exception, context: Optional[str] = None) -> None:
39+
3640
"""
3741
Log an error with context.
3842
3943
Args:
40-
logger: Logger instance
44+
log_instance: Logger instance
4145
error: Exception to log
4246
context: Optional context string
4347
"""
4448
message = f"Error: {error}"
4549
if context:
4650
message = f"{context} - {message}"
47-
logger.error(message, exc_info=True)
48-
51+
log_instance.error(message, exc_info=True) # pylint: disable=line-too-long
4952

5053
# Default logger instance
51-
logger = setup_logger()
54+
main_logger = setup_logger()

setup_env.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ def create_env_file():
4141
print("✅ .env file created successfully!")
4242
print("You can now run the bot with: python main.py")
4343

44-
except Exception as e:
44+
except OSError as e:
4545
print(f"Error creating .env file: {e}")
46+
except Exception as e: # pylint: disable=broad-except
47+
print(f"Unexpected error: {e}")
4648

4749

4850
def main():

0 commit comments

Comments
 (0)