Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rivixer committed Sep 9, 2024
2 parents 50bd70e + cc5d247 commit 30e0514
Show file tree
Hide file tree
Showing 10 changed files with 698 additions and 33 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,13 @@ prototype_json.json
registered_users.json
student_indexes.txt
registration_codes.json

# Plugins
plugins/*
!plugins/example
plugins/packages/*
!plugins/packages/
!plugins/packages/install.sh
plugins/requirements/*
!plugins/requirements/
!plugins/requirements/install.sh
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ COPY requirements.txt .
# Install the dependencies
RUN python -m pip install -r requirements.txt

# Copy the plugin packages into the container
COPY plugins/packages/ /app/plugins/packages/

# Give the packages/install.sh file execute permissions and run it.
# After installation, remove the packages directory and the apt cache
RUN chmod +x /app/plugins/packages/install.sh && \
bash -x /app/plugins/packages/install.sh && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /app/plugins/packages

# Copy the plugin requirements into the container
COPY plugins/requirements/ /app/plugins/requirements/

# Give the requirements/install.sh file execute permissions, run it
# and remove the requirements directory after installation
RUN chmod +x /app/plugins/requirements/install.sh && \
bash -x /app/plugins/requirements/install.sh && \
rm -rf /app/plugins/requirements

# Copy the local files into the container
COPY . /app/

Expand Down
37 changes: 37 additions & 0 deletions plugins/example/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# SPDX-License-Identifier: MIT
"""An example plugin cog.
This cog is an example of how to create a plugin cog.
It is ignored and cannot be loaded by the bot.
"""

from __future__ import annotations

from typing import TYPE_CHECKING

import nextcord
from nextcord.ext import commands
from nextcord.interactions import Interaction

if TYPE_CHECKING:
from sggwbot.sggw_bot import SGGWBot


class ExampleCog(commands.Cog):
"""An example plugin cog."""

__slots__ = ("bot",)

_bot: SGGWBot

def __init__(self, bot: SGGWBot):
self._bot = bot

@nextcord.slash_command(name="example", description="Example command")
async def _example(self, interaction: Interaction) -> None:
await interaction.response.send_message("Hello, world!", ephemeral=True)


def setup(bot: SGGWBot):
"""Loads the ExampleCog cog."""
bot.add_cog(ExampleCog(bot))
3 changes: 3 additions & 0 deletions plugins/example/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"enabled": true
}
35 changes: 35 additions & 0 deletions plugins/packages/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# This script will install all packages listed
# in the files in the plugins/packages directory.
# The files should contain a list of packages, one per line.
# The files should be named the same as the plugin
# they are associated with and have a .txt extension.

apt-get update

for file in ./plugins/packages/*; do

# Skip this file
if [ "$file" == "./plugins/packages/install.sh" ]; then
continue
fi

# Check if the file is a regular file and not a directory
if [ -f "$file" ]; then
# Ensure the file has LF line endings
sed -i 's/\r$//' "$file"

echo "Installing packages for $file"
apt-get --no-install-recommends install -y $(cat "$file")

if [ $? -eq 0 ]; then
echo "Packages from $file installed successfully."
else
echo "Failed to install packages from $file." >&2
fi
else
echo "$file is not a valid file and will be skipped." >&2
fi

done
33 changes: 33 additions & 0 deletions plugins/requirements/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# This script will install all packages listed
# in the files in the plugins/requirements directory.
# The files should contain a list of packages, one per line.
# The files should be named the same as the plugin
# they are associated with and have a .txt extension.

for file in ./plugins/requirements/*; do

# Skip this file
if [ "$file" == "./plugins/requirements/install.sh" ]; then
continue
fi

# Check if the file is a regular file and not a directory
if [ -f "$file" ]; then
echo "Installing Python packages for $file"

# Install the packages listed in the current file using pip
python -m pip install -r "$file"

# Check if the pip installation was successful
if [ $? -eq 0 ]; then
echo "Packages from $file installed successfully."
else
echo "Failed to install packages from $file." >&2
fi
else
echo "$file is not a valid file and will be skipped." >&2
fi

done
Binary file modified requirements.txt
Binary file not shown.
20 changes: 20 additions & 0 deletions sggwbot/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ class MissingPermission(SGGWBotError):
"""Missing permission."""


class PluginError(SGGWBotError):
"""Plugin error."""


class PluginNotFoundError(PluginError):
"""Plugin not found."""

__slots__ = ("plugin_name",)

plugin_name: str

def __init__(self, plugin_name: str) -> None:
self.plugin_name = plugin_name
super().__init__(f"Plugin '{plugin_name}' not found.")


class PluginOperationError(PluginError):
"""Plugin operation error."""


@dataclass
class ExceptionData:
"""Exception data with attributes to be passed to the error handler.
Expand Down
Loading

0 comments on commit 30e0514

Please sign in to comment.