-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
481 additions
and
689 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,59 @@ | ||
FROM python:3.12 as builder | ||
|
||
ENV PYTHONUNBUFFERED=1 \ | ||
PYTHONDONTWRITEBYTECODE=1 \ | ||
PIP_DISABLE_PIP_VERSION_CHECK=1 \ | ||
PIP_DEFAULT_TIMEOUT=100 \ | ||
POETRY_NO_INTERACTION=1 \ | ||
POETRY_VIRTUALENVS_CREATE=0 \ | ||
POETRY_CACHE_DIR=/tmp/poetry_cache \ | ||
PATH="$PATH:/root/.poetry/bin" | ||
|
||
# Change workdir | ||
WORKDIR /build | ||
|
||
# Install poetry | ||
RUN pip install poetry | ||
|
||
# Add poetry files | ||
COPY pyproject.toml poetry.lock ./ | ||
|
||
# Use poetry to resolve dependecies | ||
RUN mkdir -p /build/wheels && poetry export -f requirements.txt --output /build/wheels/requirements.txt | ||
# Compile dependencies | ||
WORKDIR /build/wheels | ||
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /build/wheels -r /build/wheels/requirements.txt | ||
# Install dependecies | ||
RUN pip install --find-links /build/wheels -r /build/wheels/requirements.txt | ||
|
||
FROM python:3.12-slim | ||
|
||
ENV PYTHONFAULTHANDLER=1 \ | ||
PYTHONUNBUFFERED=1 \ | ||
PYTHONHASHSEED=random \ | ||
PYTHONDONTWRITEBYTECODE=1 | ||
|
||
ENV DS_TOKEN "YOUR_DISCORD_TOKEN" # discord token from the developer portal | ||
ENV DS_GUILD_ID "YOUR_GUILD_ID" # the guild id where the bot will be used | ||
#ENV CF_CLIENT_ID "YOUR_CLIENT_ID" # cloudflare client id | ||
#ENV CF_TOKEN "YOUR_CLOUDFLARE_TOKEN" # cloudflare token | ||
|
||
# Copy project dependecies | ||
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages | ||
|
||
# Change workdir | ||
WORKDIR /bot | ||
|
||
# Setting up proper permissions: | ||
RUN groupadd -r bot && useradd -d /bot -r -g bot bot \ | ||
&& mkdir -p /bot/config && chown bot:bot -R /bot | ||
|
||
# Run as non-root user | ||
USER bot | ||
|
||
# Copy project | ||
COPY --chown=bot:bot dsmusic/ /bot/dsmusic/ | ||
|
||
VOLUME ["/bot/config"] | ||
VOLUME ["/bot/data"] | ||
|
||
# Commands to execute inside container | ||
CMD ["python", "-O", "-B", "-m", "dsmusic"] | ||
FROM python:3.12 as builder | ||
|
||
ENV PYTHONUNBUFFERED=1 \ | ||
PYTHONDONTWRITEBYTECODE=1 \ | ||
PIP_DISABLE_PIP_VERSION_CHECK=1 \ | ||
PIP_DEFAULT_TIMEOUT=100 \ | ||
POETRY_NO_INTERACTION=1 \ | ||
POETRY_VIRTUALENVS_CREATE=0 \ | ||
POETRY_CACHE_DIR=/tmp/poetry_cache \ | ||
PATH="$PATH:/root/.poetry/bin" | ||
|
||
# Change workdir | ||
WORKDIR /build | ||
|
||
# Install poetry | ||
RUN pip install poetry | ||
|
||
# Add poetry files | ||
COPY pyproject.toml poetry.lock ./ | ||
|
||
# Use poetry to resolve dependecies | ||
RUN mkdir -p /build/wheels && poetry export -f requirements.txt --output /build/wheels/requirements.txt | ||
# Compile dependencies | ||
WORKDIR /build/wheels | ||
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /build/wheels -r /build/wheels/requirements.txt | ||
# Install dependecies | ||
RUN pip install --find-links /build/wheels -r /build/wheels/requirements.txt | ||
|
||
FROM python:3.12-slim | ||
|
||
ENV PYTHONFAULTHANDLER=1 \ | ||
PYTHONUNBUFFERED=1 \ | ||
PYTHONHASHSEED=random \ | ||
PYTHONDONTWRITEBYTECODE=1 | ||
|
||
ENV DS_TOKEN "YOUR_DISCORD_TOKEN" # discord token from the developer portal | ||
ENV DS_GUILD_ID "YOUR_GUILD_ID" # the guild id where the bot will be used | ||
|
||
# Copy project dependecies | ||
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages | ||
|
||
# Change workdir | ||
WORKDIR /bot | ||
|
||
# Setting up proper permissions: | ||
RUN groupadd -r bot && useradd -d /bot -r -g bot bot \ | ||
&& mkdir -p /bot/config && chown bot:bot -R /bot | ||
|
||
# Run as non-root user | ||
USER bot | ||
|
||
# Copy project | ||
COPY --chown=bot:bot dsmusic/ /bot/dsmusic/ | ||
|
||
VOLUME ["/bot/config"] | ||
VOLUME ["/bot/data"] | ||
|
||
# Commands to execute inside container | ||
CMD ["python", "-O", "-B", "-m", "dsmusic"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,91 @@ | ||
import os | ||
import logging | ||
|
||
import discord | ||
|
||
from .client import Client | ||
|
||
try: | ||
import uvloop | ||
except ImportError: | ||
pass | ||
else: | ||
uvloop.install() | ||
|
||
|
||
def setup_discord_auxiliary_objects(): | ||
intents = discord.Intents( | ||
guilds=True, | ||
members=True, | ||
messages=True, | ||
voice_states=True, | ||
presences=True, | ||
message_content=True | ||
) | ||
|
||
permissions = discord.Permissions( | ||
send_messages=True, | ||
read_messages=True, | ||
|
||
connect=True, | ||
speak=True, | ||
use_voice_activation=True, | ||
|
||
manage_threads=True, | ||
send_messages_in_threads=True, | ||
|
||
attach_files=True, | ||
embed_links=True, | ||
) | ||
|
||
return intents, permissions | ||
|
||
|
||
def setup_logging(): | ||
logging.basicConfig( | ||
level=logging.INFO, | ||
format="[%(asctime)s] [%(levelname)s] %(name)s: %(message)s", | ||
datefmt="%Y-%m-%d %H:%M:%S" | ||
) | ||
logging.getLogger('discord').setLevel(logging.WARNING) | ||
logging.getLogger('discord.client').setLevel(logging.INFO) | ||
logging.getLogger('mafic').setLevel(logging.WARNING) | ||
logging.getLogger('mafic.strategy').setLevel(logging.CRITICAL) | ||
|
||
|
||
def main(): | ||
setup_logging() | ||
intents, permissions = setup_discord_auxiliary_objects() | ||
|
||
client = Client( | ||
intents=intents, | ||
command_prefix="!", | ||
activity=discord.CustomActivity(name="Gressinbon"), | ||
status=discord.Status.online, | ||
mentions=discord.AllowedMentions.none(), | ||
help_command=None | ||
) | ||
|
||
oauth_url = discord.utils.oauth_url( | ||
client_id=839827510761488404, | ||
guild=discord.Object(os.getenv("DS_GUILD_ID")), | ||
permissions=permissions | ||
) | ||
print(f"Bot URL: {oauth_url}") | ||
|
||
token = os.getenv("DS_TOKEN") | ||
|
||
if token: | ||
client.run(token=token, log_handler=None) | ||
else: | ||
raise ValueError("Missing token") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() | ||
import asyncio | ||
import os | ||
import logging | ||
import sys | ||
|
||
import discord | ||
|
||
from .client import Client | ||
|
||
try: | ||
import uvloop | ||
except ImportError: | ||
pass | ||
else: | ||
uvloop.install() | ||
|
||
|
||
def setup_discord_auxiliary_objects(): | ||
intents = discord.Intents( | ||
guilds=True, | ||
members=True, | ||
messages=True, | ||
voice_states=True, | ||
presences=True, | ||
message_content=True | ||
) | ||
|
||
permissions = discord.Permissions( | ||
send_messages=True, | ||
read_messages=True, | ||
|
||
connect=True, | ||
speak=True, | ||
use_voice_activation=True, | ||
|
||
manage_threads=True, | ||
send_messages_in_threads=True, | ||
|
||
attach_files=True, | ||
embed_links=True, | ||
) | ||
|
||
return intents, permissions | ||
|
||
|
||
def setup_logging(): | ||
logging.basicConfig( | ||
level=logging.INFO, | ||
format="[%(asctime)s] [%(levelname)s] %(name)s: %(message)s", | ||
datefmt="%Y-%m-%d %H:%M:%S" | ||
) | ||
logging.getLogger('discord').setLevel(logging.WARNING) | ||
logging.getLogger('discord.client').setLevel(logging.INFO) | ||
logging.getLogger('mafic').setLevel(logging.WARNING) | ||
logging.getLogger('mafic.strategy').setLevel(logging.CRITICAL) | ||
|
||
|
||
def main(): | ||
setup_logging() | ||
|
||
if sys.platform == 'win32': | ||
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) | ||
|
||
intents, permissions = setup_discord_auxiliary_objects() | ||
|
||
client = Client( | ||
intents=intents, | ||
command_prefix="!", | ||
activity=discord.CustomActivity(name="Gressinbon"), | ||
status=discord.Status.online, | ||
mentions=discord.AllowedMentions.none(), | ||
help_command=None | ||
) | ||
|
||
oauth_url = discord.utils.oauth_url( | ||
client_id=839827510761488404, | ||
guild=discord.Object(os.getenv("DS_GUILD_ID")), | ||
permissions=permissions | ||
) | ||
print(f"Bot URL: {oauth_url}") | ||
|
||
token = os.getenv("DS_TOKEN") | ||
|
||
if token: | ||
client.run(token=token, log_handler=None) | ||
else: | ||
raise ValueError("Missing token") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Empty file.
Oops, something went wrong.