Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jotonedev committed Sep 9, 2024
1 parent 74d1fbb commit 71d3529
Show file tree
Hide file tree
Showing 7 changed files with 481 additions and 689 deletions.
120 changes: 59 additions & 61 deletions Dockerfile
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"]
176 changes: 91 additions & 85 deletions dsmusic/__main__.py
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 removed dsmusic/assistant/__init__.py
Empty file.
Loading

0 comments on commit 71d3529

Please sign in to comment.