commit 3013e131634a2749c2a80a3cfbb211058f670454 Author: Boyan Date: Mon May 26 20:59:40 2025 +0200 Structure diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3e3b65f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +run.sh +.env/ +__pycache__/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..3d91bb5 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +## DemocracyBot +Discord bot for managing democratic invitations to join a server. + +### Workflow +```mermaid +graph TD; + A[User] -->|Tells bot to invite a user| B[Bot]; + B -->|Creates a poll| C[Poll]; + C --> |If 50% active members vote yes| D[Invite User]; + C --> |If 50% active members vote no| E[Do not invite user]; +``` + +### Active users +We keep track of active users by checking for activity[^1]. No messages are logged, only the fact that a user has been active. + + + +[^1]: Message, reaction, or voice activity in the last 30 days. \ No newline at end of file diff --git a/src/cogs/__init__.py b/src/cogs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/cogs/activitymonitor.py b/src/cogs/activitymonitor.py new file mode 100644 index 0000000..3013c38 --- /dev/null +++ b/src/cogs/activitymonitor.py @@ -0,0 +1,11 @@ +import os +from discord.ext import commands +import logging + +class ActivityMonitorCog(commands.Cog): + def __init__(self, bot): + self.bot = bot + +async def setup(bot): + await bot.add_cog(ActivityMonitorCog(bot)) + diff --git a/src/cogs/frengiver.py b/src/cogs/frengiver.py new file mode 100644 index 0000000..90a4f11 --- /dev/null +++ b/src/cogs/frengiver.py @@ -0,0 +1,11 @@ +import os +from discord.ext import commands +import logging + +class FrenGiverCog(commands.Cog): + def __init__(self, bot): + self.bot = bot + +async def setup(bot): + await bot.add_cog(FrenGiverCog(bot)) + diff --git a/src/cogs/poll.py b/src/cogs/poll.py new file mode 100644 index 0000000..496b98d --- /dev/null +++ b/src/cogs/poll.py @@ -0,0 +1,11 @@ +import os +from discord.ext import commands +import logging + +class PollCog(commands.Cog): + def __init__(self, bot): + self.bot = bot + +async def setup(bot): + await bot.add_cog(PollCog(bot)) + diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..d5cdc4a --- /dev/null +++ b/src/main.py @@ -0,0 +1,41 @@ +import os +import logging +import asyncio +from discord.ext import commands +import discord + +logging.basicConfig( + level=logging.INFO, + format="%(asctime)s [%(levelname)s] %(message)s", + datefmt="%Y-%m-%d %H:%M:%S", +) + +intents = discord.Intents.default() +intents.message_content = True +bot = commands.Bot(command_prefix="!", intents=intents) + +async def load_cogs(): + cog_directory = "cogs" + for filename in os.listdir(cog_directory): + if filename.endswith(".py") and not filename.startswith("__"): + cog_name = f"{cog_directory}.{filename[:-3]}" + try: + await bot.load_extension(cog_name) # Await load_extension + logging.info(f"Loaded cog: {cog_name}") + except Exception as e: + logging.error(f"Failed to load cog {cog_name}: {e}") + +@bot.event +async def on_ready(): + logging.info(f"Logged in as {bot.user} (ID: {bot.user.id})") + logging.info("Bot is ready.") + +async def main(): + async with bot: + await load_cogs() + await bot.start(os.getenv("DISCORD_BOT_TOKEN")) + +# Run the bot +if __name__ == "__main__": + asyncio.run(main()) +