Skip to content

Commit

Permalink
feat(main.py): Add set_activity function to set bot's activity.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mantouisyummy committed Feb 13, 2024
1 parent a27e9d7 commit f31f7c3
Showing 1 changed file with 37 additions and 14 deletions.
51 changes: 37 additions & 14 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from os import getenv

from colorlog import ColoredFormatter
from disnake import Intents
from disnake import Intents, Streaming, Activity, Game, ActivityType
from disnake.ext.commands import CommandSyncFlags
from dotenv import load_dotenv

Expand All @@ -21,10 +21,15 @@ def main():

loop = asyncio.new_event_loop()

activity = set_activity()

bot = Bot(
logger=main_logger,
command_prefix=getenv("PREFIX", "l!"), intents=Intents.all(), loop=loop,
command_sync_flags=CommandSyncFlags.default()
command_prefix=getenv("PREFIX", "l!"),
intents=Intents.all(),
loop=loop,
activity=activity,
command_sync_flags=CommandSyncFlags.default(),
)

bot.i18n.load("locale/")
Expand All @@ -34,21 +39,41 @@ def main():
bot.run(os.environ["TOKEN"])


def set_activity():
with open("configs/activity.json", "r") as f:
activity = json.load(f)

status = activity["status"]
name = activity["name"]

match status:
case "playing":
activity = Game(name=name)
case "listening":
activity = Activity(type=ActivityType.listening, name=name)
case "streaming":
activity = Streaming(name=name, url=activity["url"])
case "watching":
activity = Activity(type=ActivityType.watching, name=name)

return activity


def setup_logging():
"""
Set up the loggings for the bot
:return: None
"""
formatter = ColoredFormatter(
'%(asctime)s %(log_color)s [%(levelname)s] %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
"%(asctime)s %(log_color)s [%(levelname)s] %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
log_colors={
'DEBUG': 'cyan',
'INFO': 'white',
'WARNING': 'yellow',
'ERROR': 'red',
'CRITICAL': 'bold_red',
}
"DEBUG": "cyan",
"INFO": "white",
"WARNING": "yellow",
"ERROR": "red",
"CRITICAL": "bold_red",
},
)

stream_handler = logging.StreamHandler()
Expand All @@ -59,9 +84,7 @@ def setup_logging():
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(formatter)

logging.basicConfig(
handlers=[stream_handler, file_handler], level=logging.INFO
)
logging.basicConfig(handlers=[stream_handler, file_handler], level=logging.INFO)


def load_extensions(bot: Bot) -> Bot:
Expand Down

0 comments on commit f31f7c3

Please sign in to comment.