mirror of
https://github.com/kurbezz/discord-bot.git
synced 2025-12-06 07:05:36 +01:00
Compare commits
21 Commits
402042080e
...
678dd29918
| Author | SHA1 | Date | |
|---|---|---|---|
| 678dd29918 | |||
| 3cfea7277f | |||
| 269245a112 | |||
| 22e9461a7e | |||
| 165308d83b | |||
| d041f8d903 | |||
| 8207266d9b | |||
| 9a76f86d41 | |||
| dc3abeb429 | |||
| fa82c96e79 | |||
| 6f0a236f2f | |||
| d645e6db92 | |||
| 334718a7fb | |||
| efa92dc575 | |||
| a95d80c8dc | |||
| f9603712e8 | |||
| fbe8367723 | |||
| 6e50807381 | |||
| f907892769 | |||
| 5648bfa024 | |||
| 7b3a89f41b |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,4 +1,4 @@
|
||||
venv
|
||||
.venv
|
||||
|
||||
.DS_Store
|
||||
|
||||
|
||||
@@ -1,33 +1,19 @@
|
||||
FROM python:3.12-slim AS build
|
||||
|
||||
ARG POETRY_EXPORT_EXTRA_ARGS=''
|
||||
|
||||
WORKDIR /opt/venv
|
||||
RUN python -m venv /opt/venv && /opt/venv/bin/pip install --upgrade pip && /opt/venv/bin/pip install --no-cache-dir httpx poetry poetry-plugin-export
|
||||
|
||||
COPY ./pyproject.toml ./poetry.lock ./
|
||||
RUN --mount=type=ssh /opt/venv/bin/poetry export --without-hashes ${POETRY_EXPORT_EXTRA_ARGS} > requirements.txt \
|
||||
&& /opt/venv/bin/pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
|
||||
FROM python:3.12-slim AS runtime
|
||||
|
||||
RUN apt update && \
|
||||
apt install -y --no-install-recommends curl jq && \
|
||||
apt clean
|
||||
|
||||
COPY ./src/ /app
|
||||
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
|
||||
|
||||
COPY ./scripts/*.sh /
|
||||
RUN chmod +x /*.sh
|
||||
|
||||
ENV PATH="/opt/venv/bin:$PATH"
|
||||
ENV VENV_PATH=/opt/venv
|
||||
|
||||
COPY --from=build /opt/venv /opt/venv
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY ./pyproject.toml ./
|
||||
COPY ./uv.lock ./
|
||||
|
||||
RUN uv venv && uv sync --frozen
|
||||
|
||||
COPY ./src ./src
|
||||
|
||||
ENV PATH="/app/.venv/bin:$PATH"
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
CMD ["python", "main.py"]
|
||||
CMD ["uv", "run", "src/main.py"]
|
||||
|
||||
2152
poetry.lock
generated
2152
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,30 +1,33 @@
|
||||
[tool.poetry]
|
||||
[project]
|
||||
name = "discord-bot"
|
||||
version = "0.1.0"
|
||||
description = ""
|
||||
authors = ["Bulat Kurbanov <kurbanovbul@gmail.com>"]
|
||||
readme = "README.md"
|
||||
packages = [{include = "discord_bot"}]
|
||||
authors = [{ name = "Bulat Kurbanov", email = "kurbanovbul@gmail.com" }]
|
||||
requires-python = "~=3.12"
|
||||
dependencies = [
|
||||
"discord-py>=2.4.0,<3",
|
||||
"twitchapi>=4.4.0,<5",
|
||||
"pydantic>=2.10.5,<3",
|
||||
"pydantic-settings>=2.7.1,<3",
|
||||
"httpx>=0.28.1,<0.29",
|
||||
"icalendar>=6.1.0,<7",
|
||||
"pytz~=2024.2",
|
||||
"mongojet>=0.2.7,<0.3",
|
||||
"taskiq>=0.11.11,<0.12",
|
||||
"taskiq-redis>=1.0.2,<2",
|
||||
"redis[hiredis]>=5.2.1,<6",
|
||||
"fastapi>=0.115.8,<0.116",
|
||||
"authx>=1.4.1,<2",
|
||||
"httpx-oauth>=0.16.1,<0.17",
|
||||
"uvicorn[standard]>=0.34.0,<0.35",
|
||||
]
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.11"
|
||||
discord-py = "^2.4.0"
|
||||
twitchapi = "^4.4.0"
|
||||
pydantic = "^2.10.5"
|
||||
pydantic-settings = "^2.7.1"
|
||||
httpx = "^0.28.1"
|
||||
icalendar = "^6.1.0"
|
||||
pytz = "^2024.2"
|
||||
mongojet = "^0.2.7"
|
||||
taskiq = "^0.11.11"
|
||||
taskiq-redis = "^1.0.2"
|
||||
redis = {extras = ["hiredis"], version = "^5.2.1"}
|
||||
fastapi = "^0.115.8"
|
||||
authx = "^1.4.1"
|
||||
httpx-oauth = "^0.16.1"
|
||||
uvicorn = {extras = ["standard"], version = "^0.34.0"}
|
||||
[tool.hatch.build.targets.sdist]
|
||||
include = ["discord_bot"]
|
||||
|
||||
[tool.hatch.build.targets.wheel]
|
||||
include = ["discord_bot"]
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#! /usr/bin/env sh
|
||||
|
||||
/opt/venv/bin/python main.py $1
|
||||
uv run ./src/main.py $1
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#! /usr/bin/env sh
|
||||
|
||||
/opt/venv/bin/taskiq scheduler core.broker:scheduler modules.tasks
|
||||
uv run --directory src taskiq scheduler core.broker:scheduler modules.tasks
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#! /usr/bin/env sh
|
||||
|
||||
/opt/venv/bin/uvicorn modules.web_app.app:app --host 0.0.0.0 --port 80
|
||||
uv run --directory src uvicorn modules.web_app.app:app --host 0.0.0.0 --port 80
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#! /usr/bin/env sh
|
||||
|
||||
/opt/venv/bin/taskiq worker core.broker:broker modules.tasks
|
||||
uv run --directory src taskiq worker core.broker:broker modules.tasks
|
||||
|
||||
@@ -96,6 +96,19 @@ async def get_completion(messages: list[dict]) -> str:
|
||||
logger.info(f"Getting completion for message: {messages}")
|
||||
|
||||
data_messages = [
|
||||
{
|
||||
"role": "system",
|
||||
"content": (
|
||||
"Don't use markdown! "
|
||||
"Don't use blocked words on Twitch! "
|
||||
"Make answers short and clear! "
|
||||
"You are not language model! "
|
||||
"You are not a bot! "
|
||||
"You are human! "
|
||||
"Your name is kurbezz or Bulat! "
|
||||
"Don't start answer with @kurbezz!"
|
||||
)
|
||||
},
|
||||
*(
|
||||
{
|
||||
"role": "assistant" if message["user"] == "kurbezz" else "user",
|
||||
@@ -103,10 +116,6 @@ async def get_completion(messages: list[dict]) -> str:
|
||||
}
|
||||
for message in messages
|
||||
),
|
||||
{
|
||||
"role": "system",
|
||||
"content": "Don't use markdown! Don't use blocked words on Twitch! Make answers short and clear!"
|
||||
}
|
||||
]
|
||||
|
||||
async with AsyncClient() as client:
|
||||
@@ -154,8 +163,13 @@ class MessagesProc:
|
||||
def get_message_history_with_thread(cls, message_id: str, thread_id: str | None = None) -> list[dict]:
|
||||
logger.info(f"HISTORY: {cls.MESSAGE_HISTORY}")
|
||||
|
||||
return [m for m in cls.MESSAGE_HISTORY if m["thread_id"] == thread_id] + \
|
||||
[m for m in cls.MESSAGE_HISTORY if m["id"] == message_id]
|
||||
if thread_id is not None:
|
||||
return (
|
||||
[m for m in cls.MESSAGE_HISTORY if m["id"] == thread_id]
|
||||
+ [m for m in cls.MESSAGE_HISTORY if m["thread_id"] == thread_id]
|
||||
)
|
||||
|
||||
return [m for m in cls.MESSAGE_HISTORY if m["id"] == message_id]
|
||||
|
||||
@classmethod
|
||||
async def on_message(cls, event: MessageEvent):
|
||||
@@ -182,7 +196,29 @@ class MessagesProc:
|
||||
)
|
||||
|
||||
if "lasqexx" in event.chatter_user_login:
|
||||
pass # Todo: Здароу
|
||||
if "здароу" in event.message.text.lower():
|
||||
await twitch.send_chat_message(
|
||||
event.broadcaster_user_id,
|
||||
config.TWITCH_ADMIN_USER_ID,
|
||||
"Здароу, давай иди уже",
|
||||
reply_parent_message_id=event.message_id
|
||||
)
|
||||
|
||||
if "сосал?" in event.message.text.lower():
|
||||
await twitch.send_chat_message(
|
||||
event.broadcaster_user_id,
|
||||
config.TWITCH_ADMIN_USER_ID,
|
||||
"А ты? Иди уже",
|
||||
reply_parent_message_id=event.message_id
|
||||
)
|
||||
|
||||
if "лан я пошёл" in event.message.text.lower():
|
||||
await twitch.send_chat_message(
|
||||
event.broadcaster_user_id,
|
||||
config.TWITCH_ADMIN_USER_ID,
|
||||
"да да, иди уже",
|
||||
reply_parent_message_id=event.message_id
|
||||
)
|
||||
|
||||
if event.message.text.lower().startswith("!ai"):
|
||||
try:
|
||||
@@ -202,6 +238,13 @@ class MessagesProc:
|
||||
part,
|
||||
reply_parent_message_id=event.message_id
|
||||
)
|
||||
|
||||
cls.update_message_history(
|
||||
id="ai",
|
||||
text=part,
|
||||
user="kurbezz",
|
||||
thread_id=event.message_id
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error("Failed to get completion: {}", e, exc_info=True)
|
||||
|
||||
@@ -236,6 +279,13 @@ class MessagesProc:
|
||||
part,
|
||||
reply_parent_message_id=event.message_id
|
||||
)
|
||||
|
||||
cls.update_message_history(
|
||||
id="ai",
|
||||
text=part,
|
||||
user="kurbezz",
|
||||
thread_id=event.message_id
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to get completion: {e}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user