Skip to content

Commit

Permalink
Release/v1.0.0 (#11)
Browse files Browse the repository at this point in the history
* updated readme

- added loguru env var for setting log level

* fixed small error being thrown when initial bot command msg gets deleted before cleanup

* cleaned up unused variables, and added more logging

- removed unused os.environ from react_roles since var isn't used
- added logging to uptime command
  • Loading branch information
seekheart authored Feb 18, 2024
1 parent c1e0087 commit b5cf990
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ DISCORD_BOT_TOKEN=<YOUR TOKEN FROM BEFORE HERE>
MOD_AUDIT_CHANNEL_ID=<Moderation Audit Channel ID here>
ROLE_MESSAGE_ID=<Message to react to for role assignment here>
MODERATOR_ROLES=<roles here separated by `,` for example `a,b,c`>
LOGURU_LEVEL=<LOG LEVEL>
```
2. Source the env file you created and run the `app.py`
3 changes: 3 additions & 0 deletions jainy_bot/commands/moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ async def clean(self, ctx: commands.Context, user: discord.Member, num_msg: int)

deleted = []
async for msg in ctx.channel.history(limit=1000):
if msg.id == ctx.message.id:
logger.debug(f'Skipping initial bot command message: {msg.content}')
continue
if len(deleted) == num_msg:
break
if msg.author == user:
Expand Down
7 changes: 5 additions & 2 deletions jainy_bot/commands/uptime.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from datetime import datetime, timedelta
from discord.ext import commands
from loguru import logger


def _format_time(t: timedelta) -> str:
def format_time(t: timedelta) -> str:
logger.debug(f'Got timedelta = {t}')
h, m, s = str(t).split(':')
return f'{h} Hours {m} Minutes {s} Seconds'

Expand All @@ -15,5 +17,6 @@ def __init__(self, bot: commands):
@commands.command()
async def uptime(self, ctx: commands):
"""Get the uptime for bot"""
logger.info(f'Generating uptime information')
delta = datetime.now() - self.start_time
await ctx.send(f"Uptime: {_format_time(delta)}")
await ctx.send(f"Uptime: {format_time(delta)}")
10 changes: 8 additions & 2 deletions jainy_bot/commands/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,11 @@ async def send_reply_message(ctx: commands.Context, message: str) -> None:
"""
logger.info(f'Sending reply message to {ctx.author.display_name} in channel {ctx.channel.name}')
await ctx.send(message)
await ctx.message.delete()

try:
await ctx.message.delete()
except discord.ext.commands.errors.CommandInvokeError as e:
logger.warning(f'Original bot command invoked could be deleted')
logger.error(e)
except discord.ext.commands.UserNotFound or discord.NotFound as e:
logger.error(f'User = {ctx.author.display_name} who invoked command is no longer found')
logger.error(e)
6 changes: 0 additions & 6 deletions jainy_bot/react_roles.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import os
import discord

role_message_id = int(os.environ.get("ROLE_MESSAGE_ID"))
if not role_message_id:
raise AttributeError("ROLE_MESSAGE_ID not set!")


emoji_to_role = {
discord.PartialEmoji(name='🍖'): 1197959991315927101,
discord.PartialEmoji(name='🪦'): 800444883897942086,
Expand Down

0 comments on commit b5cf990

Please sign in to comment.