mirror of
https://github.com/wlinator/luminara.git
synced 2024-10-02 20:23:12 +00:00
Switch to poetry
This commit is contained in:
parent
9d3524186a
commit
edc734b1fa
6 changed files with 1173 additions and 67 deletions
12
Dockerfile
12
Dockerfile
|
@ -1,19 +1,21 @@
|
|||
FROM python:3.11
|
||||
FROM python:3.12
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get install -y locales mariadb-client && \
|
||||
apt-get install -y locales && \
|
||||
sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
|
||||
dpkg-reconfigure locales
|
||||
|
||||
COPY requirements.txt ./
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
COPY pyproject.toml poetry.lock ./
|
||||
RUN pip install poetry && \
|
||||
poetry config virtualenvs.create false && \
|
||||
poetry install --no-interaction --no-ansi
|
||||
|
||||
COPY . .
|
||||
|
||||
ENV LANG en_US.UTF-8
|
||||
ENV LC_ALL en_US.UTF-8
|
||||
|
||||
CMD [ "python", "./Luminara.py" ]
|
||||
CMD [ "poetry", "run", "python", "./Luminara.py" ]
|
|
@ -1,18 +1,20 @@
|
|||
from loguru import logger
|
||||
import os
|
||||
|
||||
import mariadb
|
||||
import mysql.connector
|
||||
from mysql.connector import pooling
|
||||
|
||||
|
||||
def create_connection_pool(name: str, size: int) -> mariadb.ConnectionPool:
|
||||
pool = mariadb.ConnectionPool(
|
||||
def create_connection_pool(name: str, size: int) -> pooling.MySQLConnectionPool:
|
||||
pool = pooling.MySQLConnectionPool(
|
||||
pool_name=name,
|
||||
pool_size=size,
|
||||
host="db",
|
||||
port=3306,
|
||||
database=os.environ.get("MARIADB_DATABASE"),
|
||||
user=os.environ.get("MARIADB_USER"),
|
||||
password=os.environ.get("MARIADB_PASSWORD"),
|
||||
pool_name=name,
|
||||
pool_size=size
|
||||
charset="utf8mb4",
|
||||
collation="utf8mb4_unicode_ci",
|
||||
)
|
||||
|
||||
return pool
|
||||
|
@ -20,8 +22,8 @@ def create_connection_pool(name: str, size: int) -> mariadb.ConnectionPool:
|
|||
|
||||
try:
|
||||
_cnxpool = create_connection_pool("core-pool", 25)
|
||||
except mariadb.Error as e:
|
||||
logger.critical(f"Couldn't create the MariaDB connection pool: {e}")
|
||||
except mysql.connector.Error as e:
|
||||
logger.critical(f"Couldn't create the MySQL connection pool: {e}")
|
||||
raise e
|
||||
|
||||
|
||||
|
|
1088
poetry.lock
generated
Normal file
1088
poetry.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
25
pyproject.toml
Normal file
25
pyproject.toml
Normal file
|
@ -0,0 +1,25 @@
|
|||
[tool.poetry]
|
||||
authors = ["wlinator <dokimakimaki@gmail.com>"]
|
||||
description = "A Discord application, can serve as a template for your own bot."
|
||||
license = "GNU General Public License v3.0"
|
||||
name = "lumi"
|
||||
package-mode = false
|
||||
readme = "README.md"
|
||||
version = "0.1.0"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
dropbox = "^12.0.2"
|
||||
httpx = "^0.27.0"
|
||||
loguru = "^0.7.2"
|
||||
mysql-connector-python = "^9.0.0"
|
||||
pre-commit = "^3.7.1"
|
||||
psutil = "^6.0.0"
|
||||
py-cord = "2.5.0"
|
||||
pyright = "^1.1.371"
|
||||
python = "^3.12"
|
||||
pytz = "^2024.1"
|
||||
ruff = "^0.5.2"
|
||||
|
||||
[build-system]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
requires = ["poetry-core"]
|
|
@ -1,9 +0,0 @@
|
|||
py-cord==2.5.0
|
||||
setuptools==69.2.0
|
||||
pytz==2024.1
|
||||
dropbox==11.36.2
|
||||
mariadb==1.1.10
|
||||
psutil==5.9.8
|
||||
httpx==0.27.0
|
||||
loguru==0.7.2
|
||||
aider-chat
|
|
@ -13,14 +13,16 @@ class CustomReactionsService:
|
|||
message_content = message_content.lower()
|
||||
query = """
|
||||
SELECT * FROM custom_reactions
|
||||
WHERE (guild_id = ? OR is_global = TRUE) AND (
|
||||
(is_full_match = TRUE AND trigger_text = ?) OR
|
||||
(is_full_match = FALSE AND ? LIKE CONCAT('%', trigger_text, '%'))
|
||||
WHERE (guild_id = %s OR is_global = TRUE) AND (
|
||||
(is_full_match = TRUE AND trigger_text = %s) OR
|
||||
(is_full_match = FALSE AND %s LIKE CONCAT('%%', trigger_text, '%%'))
|
||||
)
|
||||
ORDER BY guild_id = ? DESC, is_global ASC
|
||||
ORDER BY guild_id = %s DESC, is_global ASC
|
||||
LIMIT 1
|
||||
"""
|
||||
result = database.select_query(query, (guild_id, message_content, message_content, guild_id))
|
||||
result = database.select_query(
|
||||
query, (guild_id, message_content, message_content, guild_id)
|
||||
)
|
||||
if result:
|
||||
reaction = result[0] # Get the first result from the list
|
||||
return {
|
||||
|
@ -36,16 +38,14 @@ class CustomReactionsService:
|
|||
"usage_count": reaction[9],
|
||||
"created_at": reaction[10],
|
||||
"updated_at": reaction[11],
|
||||
"type": "emoji" if reaction[4] else "text"
|
||||
"type": "emoji" if reaction[4] else "text",
|
||||
}
|
||||
return None
|
||||
|
||||
async def find_id(
|
||||
self, reaction_id: int
|
||||
) -> Optional[Dict[str, Any]]:
|
||||
async def find_id(self, reaction_id: int) -> Optional[Dict[str, Any]]:
|
||||
query = """
|
||||
SELECT * FROM custom_reactions
|
||||
WHERE id = ?
|
||||
WHERE id = %s
|
||||
LIMIT 1
|
||||
"""
|
||||
result = database.select_query(query, (reaction_id,))
|
||||
|
@ -64,35 +64,35 @@ class CustomReactionsService:
|
|||
"usage_count": reaction[9],
|
||||
"created_at": reaction[10],
|
||||
"updated_at": reaction[11],
|
||||
"type": "emoji" if reaction[4] else "text"
|
||||
"type": "emoji" if reaction[4] else "text",
|
||||
}
|
||||
return None
|
||||
|
||||
async def find_all_by_guild(
|
||||
self, guild_id: int
|
||||
) -> List[Dict[str, Any]]:
|
||||
async def find_all_by_guild(self, guild_id: int) -> List[Dict[str, Any]]:
|
||||
query = """
|
||||
SELECT * FROM custom_reactions
|
||||
WHERE guild_id = ?
|
||||
WHERE guild_id = %s
|
||||
"""
|
||||
results = database.select_query(query, (guild_id,))
|
||||
reactions = []
|
||||
for reaction in results:
|
||||
reactions.append({
|
||||
"id": reaction[0],
|
||||
"trigger_text": reaction[1],
|
||||
"response": reaction[2],
|
||||
"emoji_id": reaction[3],
|
||||
"is_emoji": reaction[4],
|
||||
"is_full_match": reaction[5],
|
||||
"is_global": reaction[6],
|
||||
"guild_id": reaction[7],
|
||||
"creator_id": reaction[8],
|
||||
"usage_count": reaction[9],
|
||||
"created_at": reaction[10],
|
||||
"updated_at": reaction[11],
|
||||
"type": "emoji" if reaction[4] else "text"
|
||||
})
|
||||
reactions.append(
|
||||
{
|
||||
"id": reaction[0],
|
||||
"trigger_text": reaction[1],
|
||||
"response": reaction[2],
|
||||
"emoji_id": reaction[3],
|
||||
"is_emoji": reaction[4],
|
||||
"is_full_match": reaction[5],
|
||||
"is_global": reaction[6],
|
||||
"guild_id": reaction[7],
|
||||
"creator_id": reaction[8],
|
||||
"usage_count": reaction[9],
|
||||
"created_at": reaction[10],
|
||||
"updated_at": reaction[11],
|
||||
"type": "emoji" if reaction[4] else "text",
|
||||
}
|
||||
)
|
||||
return reactions
|
||||
|
||||
async def create_custom_reaction(
|
||||
|
@ -111,7 +111,7 @@ class CustomReactionsService:
|
|||
|
||||
query = """
|
||||
INSERT INTO custom_reactions (trigger_text, response, emoji_id, is_emoji, is_full_match, is_global, guild_id, creator_id)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
|
||||
ON DUPLICATE KEY UPDATE trigger_text=trigger_text
|
||||
"""
|
||||
database.execute_query(
|
||||
|
@ -140,13 +140,13 @@ class CustomReactionsService:
|
|||
) -> bool:
|
||||
query = """
|
||||
UPDATE custom_reactions
|
||||
SET response = COALESCE(?, response),
|
||||
emoji_id = COALESCE(?, emoji_id),
|
||||
is_emoji = COALESCE(?, is_emoji),
|
||||
is_full_match = COALESCE(?, is_full_match),
|
||||
is_global = COALESCE(?, is_global),
|
||||
updated_at = ?
|
||||
WHERE id = ?
|
||||
SET response = COALESCE(%s, response),
|
||||
emoji_id = COALESCE(%s, emoji_id),
|
||||
is_emoji = COALESCE(%s, is_emoji),
|
||||
is_full_match = COALESCE(%s, is_full_match),
|
||||
is_global = COALESCE(%s, is_global),
|
||||
updated_at = %s
|
||||
WHERE id = %s
|
||||
"""
|
||||
database.execute_query(
|
||||
query,
|
||||
|
@ -165,7 +165,7 @@ class CustomReactionsService:
|
|||
async def delete_custom_reaction(self, reaction_id: int) -> bool:
|
||||
query = """
|
||||
DELETE FROM custom_reactions
|
||||
WHERE id = ?
|
||||
WHERE id = %s
|
||||
"""
|
||||
database.execute_query(query, (reaction_id,))
|
||||
return True
|
||||
|
@ -173,7 +173,7 @@ class CustomReactionsService:
|
|||
async def count_custom_reactions(self, guild_id: int) -> int:
|
||||
query = """
|
||||
SELECT COUNT(*) FROM custom_reactions
|
||||
WHERE guild_id = ?
|
||||
WHERE guild_id = %s
|
||||
"""
|
||||
count = database.select_query_one(query, (guild_id,))
|
||||
return count if count else 0
|
||||
|
@ -182,12 +182,10 @@ class CustomReactionsService:
|
|||
query = """
|
||||
UPDATE custom_reactions
|
||||
SET usage_count = usage_count + 1
|
||||
WHERE id = ?
|
||||
WHERE id = %s
|
||||
"""
|
||||
database.execute_query(
|
||||
query,
|
||||
(
|
||||
reaction_id,
|
||||
),
|
||||
(reaction_id,),
|
||||
)
|
||||
return True
|
||||
|
|
Loading…
Reference in a new issue