Thanks to visit codestin.com
Credit goes to github.com

Skip to content
/ BakaBot Public

Discord Bot and Web Scraper for the Czech online schooling system "Bakaláři"

License

Notifications You must be signed in to change notification settings

Patai5/BakaBot

Repository files navigation

BakaBot

BakaBot is a Discord bot and web scraper designed for the Czech online schooling system Bakaláři. Receive real-time updates on new grades, schedule changes, and more directly in your Discord server!


⚠️ Not Maintained Anymore

This project is no longer maintained as I no longer have access to the Bakaláři system... Feel free to fork and modify it for your own use though :)

Anyway, here are some of the funniest bits of code I somehow managed to write along the way :P I started on this project back when I was just learning to code, so there are still some gems left inside:

  • `return min(fieldsLen, 4) - 1` the professional way 😎
    def get_stage(message: disnake.Message) -> int:
    """Gets the stage of the embed and returns as int"""
    fieldsLen = len(message.embeds[0].fields)
    if fieldsLen > 1:
    if fieldsLen > 2:
    if fieldsLen > 3:
    return 3
    return 2
    return 1
    return 0
  • Files >>> PostgreSQL + MongoDB combined 🗿
    # Writes to the database
    def write_db(key: str, value: Any) -> None:
    with open(f"db/{key}.dat", "wb") as f:
    pickle.dump(value, f, protocol=2)
    # Reads a from the database by key. Returns none if the key doesn't exist
    def read_db(key: str) -> Any | None:
    try:
    with open(f"db/{key}.dat", "rb") as f:
    return pickle.load(f)
    except:
    return None
  • 🪜🎢 `tab`➡️`tab`➡️`tab`➡️ (only 8 indentation deep 🥱)
    async def execute(self) -> None:
    for user in self.message.reactions:
    if user.me:
    for reaction in Reactions.REACTIONS:
    if reaction.queryMessagesDatabase:
    reactionDatabase: list[MessageTimer] | None = read_db(reaction.queryMessagesDatabase)
    if reactionDatabase is None:
    raise ValueError("Reaction database not found")
    for message in reactionDatabase:
    if self.message.id == message.message.id:
    await reaction.execute(self)
    honorable mentions 🥀
    messages = await MessageTimers.query_messages(cls.queryMessagesDatabase, client)
    if messages:
    for message in messages:
    if message.edited_at:
    editedFromNowSec = (datetime.datetime.now(datetime.timezone.utc) - message.edited_at).seconds
    if editedFromNowSec > 300:
    await MessageTimers.delete_message(message, cls.queryMessagesDatabase, client)
    else:
    asyncio.ensure_future(
    MessageTimers.delete_message(
    message,
    cls.queryMessagesDatabase,
    for timer in MessageTimers.timers_reactions:
    if linkedMessage == timer.message:
    # Checks if the message remove time was changed while sleeping
    if reactionTimer.removeAt == timer.removeAt:
    try:
    textChanel = getTextChannel(linkedMessage.channelId, client)
    fetchedMessage = await textChanel.fetch_message(linkedMessage.id)
    except:
    print(
    f"""Couldn't get the desired message! Was probably removed!:\n
    message_id: {linkedMessage.id}, message_channel: {linkedMessage.channelId}"""
    )
  • Old commit from when main.py was still at its peak 😭🙏 https://github.com/Patai5/BakaBot/blob/b4135ae91a26ff9ddba22b9bcb29909373093431/main.py

Features

  • 📅 Schedule Notifications: Get real-time Discord notifications when your school schedule changes.
  • 📚 Grade Alerts: Stay up to date with your latest grades, delivered directly to your Discord.
  • ☀️ Daily Schedule Reminders: Receive notifications each morning with your schedule for the day.
  • Upcoming Lessons Alerts: Be notified about upcoming lessons and events.
  • 🌐 Bakaláři Server Status: Monitor the current status of your Bakaláři server.
  • 📆 Custom Schedule Requests: Use the /schedule command to fetch your schedule for any given day.

Usage examples

  • 📅 Get immediate Discord notifications for any changes detected in your school schedule

    View changes presented in user-friendly HTML/CSS generated images using Pyppeteer

image

  • 📚 Stay informed about your latest grades 💀

    Get instant updates on your grades with easy-to-read notifications.

image > image

  • ☀️ Receive daily morning notifications about the day's schedule

    Start your day with a helpful reminder of your upcoming lessons.

image

  • ⏰ Get notifed about the upcoming lessons

    Receive timely alerts for upcoming lessons to stay prepared.

image

  • 🌐 Keep track of Bakaláři server's online status

    Monitor the server status to check if Bakaláři is online.

image

  • 📆 Use the /schedule command to get the schedule for any specific day

    Easily fetch the schedule for any day with a simple command.

image

Instalation

  1. Clone the repository:

    git clone https://github.com/Patai5/BakaBot.git
    cd BakaBot
  2. Setup your .env file:

    Copy the example .env file and configure it with your Discord bot credentials.

    cp .env.example .env
  3. Create a virtual environment (Optional but recommended)

    python -m venv env
  4. Activate the virtual environment:

    • On Windows:
      env\Scripts\activate.bat
    • On macOS/Linux:
      source env/bin/activate
  5. Install dependencies:

    pip install -e .

    (If you're contributing to the project, install development dependencies)

    pip install -e .[dev]
  6. Install Playwright:

    playwright install
  7. Start the bot:

    python -m src.main
  8. Setup the bot: Once the bot is running, use the /setup command in your Discord server to configure it.

Docker

To run the bot using Docker, execute:

docker-compose up --build -d

About

Discord Bot and Web Scraper for the Czech online schooling system "Bakaláři"

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages