aboutsummaryrefslogtreecommitdiffstats
path: root/main.py
blob: 6c8c35b6a803604b5fddd2189e17ea8ceafb51e0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# This file is part of Senator Sperma
# Licensed under the GPL-3.0 License
# Copyright (C) 2026 Salmonik @ salmonik@tuta.io
# https://codeberg.org/salmonik/senator-sperma

import asyncio
import logging
import os
import sys
import argparse

import discord
from discord.ext import commands
from dotenv import load_dotenv

from cogs.utils import settings


def setup_logging(debug: bool = False):
    """Configure logging based on debug flag."""
    level = logging.DEBUG if debug else logging.INFO
    logging.basicConfig(
        level=level,
        format="%(levelname)s - %(filename)s - %(name)s - %(message)s",
        handlers=[logging.StreamHandler(sys.stdout)],
    )


# Create a new event loop and set it as the current loop
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

intents = discord.Intents.all()
bot = commands.Bot(intents=intents, loop=loop)


@bot.event
async def on_ready():
    logger = logging.getLogger(__name__)
    logger.info("ŁUKASZ SPERMA AKTYWACJA")

    channel_id = os.getenv("STATUS_CHANNEL_ID")
    if channel_id:
        channel = bot.get_channel(int(channel_id))
        if channel:
            await channel.send("ŁUKASZ SPERMA AKTYWACJA")

    await settings.load_settings()


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Run Senator Sperma bot")
    parser.add_argument("--debug", action="store_true", help="Enable debug logging")
    args, unknown = parser.parse_known_args()

    load_dotenv()
    setup_logging(args.debug)

    extensions = [
        "cogs.vclogs",
        "cogs.compression",
        "cogs.tts",
        "cogs.web",
        "cogs.ai",
        "cogs.conversion",
        "cogs.math_commands",
        "cogs.downloader",
        "cogs.say",
        "cogs.assistant",
        "cogs.music.play_commands",
        "cogs.music.stop",
        "cogs.music.join",
        "cogs.search",
        "cogs.trigger",
        "cogs.cron",
        "cogs.qr",
        "cogs.plot",
        "cogs.voice",
    ]

    try:
        for i, extension in enumerate(extensions, 1):
            bot.load_extension(extension)
            logging.getLogger(__name__).info(f"Loaded {i}/{len(extensions)} extensions")

        token = os.getenv("TOKEN")
        if not token:
            raise ValueError(
                "No token provided. Please set the TOKEN environment variable."
            )

        bot.run(token)

    except Exception as e:
        logging.getLogger(__name__).error(f"Error starting the bot: {e}")
        sys.exit(1)