Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging in some cogs #120

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

discord.utils.setup_logging(level=logging.INFO, root=True)

logger = logging.getLogger(__name__)
BOT_PREFIX = config.BOT_PREFIX


Expand Down Expand Up @@ -49,6 +50,8 @@ async def load_cogs(self) -> None:
if filename.endswith('.py'):
await self.load_extension('bot.cogs.{}'.format(filename[:-3]))

logger.info('ALL COGS HAVE BEEN LOADED SUCCESSFULLY')

async def close(self) -> None:
await self.session.close()
await super().close()
Expand Down
5 changes: 5 additions & 0 deletions bot/cogs/booster.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import io
import logging
from datetime import datetime, time, timedelta, timezone

import discord
Expand All @@ -15,6 +16,8 @@
TATSU_LOG_CHANNEL_ID,
)

logger = logging.getLogger(__name__)


class Booster(commands.Cog):
def __init__(self, bot: WarnetBot) -> None:
Expand All @@ -28,6 +31,8 @@ async def on_connect(self) -> None:
async def _monthly_booster(self) -> None:
date = datetime.now(pytz.timezone('Asia/Jakarta'))
if date.day == 1:
logger.info(f'MONTHLY EXP BOOSTER IS TRIGGERED: {date.strftime("%B %Y")}')

admin_channel = self.bot.get_channel(ADMIN_CHANNEL_ID)
tatsu_log_channel = self.bot.get_channel(TATSU_LOG_CHANNEL_ID)
guild = self.bot.get_guild(GUILD_ID)
Expand Down
7 changes: 7 additions & 0 deletions bot/cogs/color.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from datetime import datetime
from typing import Optional

Expand All @@ -14,6 +15,8 @@
)
from bot.config import CustomRoleConfig

logger = logging.getLogger(__name__)


@commands.guild_only()
class Color(commands.GroupCog, group_name='warnet-color'):
Expand Down Expand Up @@ -98,6 +101,7 @@ async def add_hex_color(self, interaction: Interaction, name: str, hex: str) ->
reason="Member Request",
color=valid_color,
)
logger.info(f'NEW ROLE HAS BEEN CREATED SUCCESSFULLY. ROLE ID: {created_role.id}')

async with self.db_pool.acquire() as conn:
await conn.execute(
Expand Down Expand Up @@ -173,6 +177,7 @@ async def add_rgb_color(
reason="Member Request",
color=valid_color,
)
logger.info(f'NEW ROLE HAS BEEN CREATED SUCCESSFULLY. ROLE ID: {created_role.id}')

async with self.db_pool.acquire() as conn:
await conn.execute(
Expand Down Expand Up @@ -482,6 +487,7 @@ async def delete_color(
self.custom_role_data.pop(role_target.id)
self.custom_role_data_list = list(self.custom_role_data.keys())
await role_target.delete()
logger.info(f'ROLE ID {role_target.id} IS DELETED')

self.cache['color-list'] = None

Expand Down Expand Up @@ -564,6 +570,7 @@ async def sync_color(self, ctx: commands.Context) -> None:
if ctx.guild.get_role(data['role_id']):
self.custom_role_data[data['role_id']] = data['owner_discord_id']
self.custom_role_data_list = list(self.custom_role_data.keys())
logger.info(f'ROLE LIST HAS BEEN SYNCED SUCCESSFULLY')

self.cache['color-list'] = None

Expand Down
7 changes: 7 additions & 0 deletions bot/cogs/sticky.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import logging
from datetime import datetime
from typing import Optional, Union

Expand All @@ -9,6 +10,8 @@
from bot.bot import WarnetBot
from bot.cogs.views.sticky import StickyPagination

logger = logging.getLogger(__name__)


@commands.guild_only()
class Sticky(commands.GroupCog, group_name="sticky"):
Expand Down Expand Up @@ -105,6 +108,7 @@ async def add_sticky_message(
)

self.sticky_data[channel.id] = [msg.id, message, delay_time]
logger.info(f'NEW STICKY MESSSAGE HAS BEEN ADDED ON CHANNEL ID {channel.id}')

await self._send_interaction(
interaction,
Expand Down Expand Up @@ -239,6 +243,7 @@ async def remove_sticky_message(
await conn.execute("DELETE FROM sticky WHERE channel_id=$1;", channel.id)

self.sticky_data.pop(channel.id)
logger.info(f'NEW STICKY MESSSAGE HAS BEEN REMOVED ON CHANNEL ID {channel.id}')

await self._send_interaction(
interaction,
Expand Down Expand Up @@ -338,6 +343,8 @@ async def purge_sticky_message(
"DELETE FROM sticky WHERE channel_id=$1;", invalid_channel_id_list
)

logger.info(f'STICKY MESSSAGES HAVE BEEN PURGED')

await self._send_interaction(
interaction,
color=discord.Color.green(),
Expand Down
Loading