feat: add Quote.is_active field
This commit is contained in:
parent
7131930d8e
commit
811fead29d
8 changed files with 287 additions and 235 deletions
|
|
@ -12,8 +12,14 @@ class CreateQuoteAction(BaseModel):
|
|||
create_quote_svc: CreateQuoteSvc
|
||||
is_mod_svc: IsModSvc
|
||||
|
||||
async def run(
|
||||
self, user: User, channel: str, quote: str, author: str, username: str
|
||||
async def run( # noqa: PLR0913
|
||||
self,
|
||||
user: User,
|
||||
channel: str,
|
||||
quote: str,
|
||||
author: str,
|
||||
username: str,
|
||||
is_active: bool = True,
|
||||
) -> Quote | None:
|
||||
if not await self.is_mod_svc.run(user=user, username=username, channel=channel):
|
||||
return None
|
||||
|
|
@ -23,6 +29,7 @@ class CreateQuoteAction(BaseModel):
|
|||
author=author,
|
||||
channel_name=channel,
|
||||
created_at=datetime.datetime.now(datetime.UTC),
|
||||
is_active=is_active,
|
||||
last_updated_at=datetime.datetime.now(datetime.UTC),
|
||||
)
|
||||
return await self.create_quote_svc.run(new_quote)
|
||||
|
|
|
|||
|
|
@ -62,7 +62,9 @@ class UserRepo(IRepo[User]):
|
|||
self.get_client(auto_commit=auto_commit) as db,
|
||||
await db.execute(
|
||||
"""
|
||||
SELECT * FROM users WHERE id = ?
|
||||
SELECT *
|
||||
FROM users
|
||||
WHERE id = ?
|
||||
""",
|
||||
(obj_id.hex,),
|
||||
) as cursor,
|
||||
|
|
@ -79,8 +81,7 @@ class UserRepo(IRepo[User]):
|
|||
self.get_client(auto_commit=auto_commit) as db,
|
||||
await db.execute(
|
||||
"""INSERT INTO users (id, username, external_auth, created_at, last_updated_at)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
RETURNING *
|
||||
VALUES (?, ?, ?, ?, ?) RETURNING *
|
||||
""",
|
||||
(
|
||||
obj.id.hex,
|
||||
|
|
@ -102,13 +103,12 @@ class UserRepo(IRepo[User]):
|
|||
self.get_client(auto_commit=auto_commit) as db,
|
||||
db.execute(
|
||||
"""
|
||||
UPDATE users
|
||||
SET username = ?,
|
||||
external_auth = ?,
|
||||
last_updated_at = ?
|
||||
WHERE id = ?
|
||||
RETURNING *
|
||||
""",
|
||||
UPDATE users
|
||||
SET username = ?,
|
||||
external_auth = ?,
|
||||
last_updated_at = ?
|
||||
WHERE id = ? RETURNING *
|
||||
""",
|
||||
(
|
||||
obj.username,
|
||||
obj.serialize_external_auth(),
|
||||
|
|
@ -124,7 +124,9 @@ class UserRepo(IRepo[User]):
|
|||
async with self.get_client(auto_commit=auto_commit) as db:
|
||||
await db.execute(
|
||||
"""
|
||||
DELETE FROM users WHERE id = ?
|
||||
DELETE
|
||||
FROM users
|
||||
WHERE id = ?
|
||||
""",
|
||||
(obj.id.hex,),
|
||||
)
|
||||
|
|
@ -134,8 +136,10 @@ class UserRepo(IRepo[User]):
|
|||
self.get_client(auto_commit=auto_commit) as db,
|
||||
db.execute(
|
||||
"""
|
||||
SELECT * FROM users WHERE username = ?
|
||||
""",
|
||||
SELECT *
|
||||
FROM users
|
||||
WHERE username = ?
|
||||
""",
|
||||
(user,),
|
||||
) as cursor,
|
||||
):
|
||||
|
|
@ -169,6 +173,7 @@ class QuoteRepo(IRepo[Quote]):
|
|||
channel_name=data["channel"],
|
||||
created_at=data["created_at"],
|
||||
last_updated_at=data["last_updated_at"],
|
||||
is_active=data["is_active"],
|
||||
)
|
||||
|
||||
async def create(self, obj: Quote, auto_commit=True) -> Quote:
|
||||
|
|
@ -178,9 +183,8 @@ class QuoteRepo(IRepo[Quote]):
|
|||
self.get_client(auto_commit=auto_commit) as db,
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO quotes (id, quote, author, channel, created_at, last_updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
RETURNING *
|
||||
INSERT INTO quotes (id, quote, author, channel, created_at, is_active, last_updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING *
|
||||
""",
|
||||
(
|
||||
obj.id.hex,
|
||||
|
|
@ -188,6 +192,7 @@ class QuoteRepo(IRepo[Quote]):
|
|||
obj.author,
|
||||
obj.channel_name,
|
||||
obj.created_at,
|
||||
obj.is_active,
|
||||
obj.last_updated_at,
|
||||
),
|
||||
) as cursor,
|
||||
|
|
@ -202,18 +207,19 @@ class QuoteRepo(IRepo[Quote]):
|
|||
self.get_client(auto_commit=auto_commit) as db,
|
||||
await db.execute(
|
||||
"""
|
||||
UPDATE quotes
|
||||
SET quote = ?,
|
||||
author = ?,
|
||||
channel = ?,
|
||||
last_updated_at = ?
|
||||
WHERE id = ?
|
||||
RETURNING *
|
||||
UPDATE quotes
|
||||
SET quote = ?,
|
||||
author = ?,
|
||||
channel = ?,
|
||||
is_active = ?,
|
||||
last_updated_at = ?
|
||||
WHERE id = ? RETURNING *
|
||||
""",
|
||||
(
|
||||
obj.quote,
|
||||
obj.author,
|
||||
obj.channel_name,
|
||||
obj.is_active,
|
||||
utils.get_utc_now(),
|
||||
obj.id.hex,
|
||||
),
|
||||
|
|
@ -226,7 +232,9 @@ class QuoteRepo(IRepo[Quote]):
|
|||
async with self.get_client(auto_commit=auto_commit) as db:
|
||||
await db.execute(
|
||||
"""
|
||||
DELETE FROM quotes WHERE id = ?
|
||||
DELETE
|
||||
FROM quotes
|
||||
WHERE id = ?
|
||||
""",
|
||||
(obj.id.hex,),
|
||||
)
|
||||
|
|
@ -236,7 +244,9 @@ class QuoteRepo(IRepo[Quote]):
|
|||
self.get_client(auto_commit=auto_commit) as db,
|
||||
db.execute(
|
||||
"""
|
||||
SELECT * FROM quotes WHERE id = ?
|
||||
SELECT *
|
||||
FROM quotes
|
||||
WHERE id = ?
|
||||
""",
|
||||
(obj_id.hex,),
|
||||
) as cursor,
|
||||
|
|
@ -251,7 +261,9 @@ class QuoteRepo(IRepo[Quote]):
|
|||
self.get_client(auto_commit=auto_commit) as db,
|
||||
db.execute(
|
||||
"""
|
||||
SELECT * FROM quotes WHERE quote = ?
|
||||
SELECT *
|
||||
FROM quotes
|
||||
WHERE quote = ?
|
||||
""",
|
||||
(quote,),
|
||||
) as cursor,
|
||||
|
|
@ -277,10 +289,11 @@ class QuoteRepo(IRepo[Quote]):
|
|||
self.get_client(auto_commit=auto_commit) as db,
|
||||
db.execute(
|
||||
"""
|
||||
SELECT * FROM quotes
|
||||
WHERE channel = ?
|
||||
ORDER BY RANDOM()
|
||||
LIMIT 1
|
||||
SELECT *
|
||||
FROM quotes
|
||||
WHERE channel = ?
|
||||
AND is_active = 1
|
||||
ORDER BY RANDOM() LIMIT 1
|
||||
""",
|
||||
(channel_name,),
|
||||
) as cursor,
|
||||
|
|
@ -310,17 +323,15 @@ class ChatbotRepo(IRepo[Chatbot]):
|
|||
async with (
|
||||
self.get_client(auto_commit=auto_commit) as db,
|
||||
await db.execute(
|
||||
"""INSERT INTO chatbot (
|
||||
id,
|
||||
user_id,
|
||||
automatic_generation_timer,
|
||||
automatic_quote_timer,
|
||||
mods,
|
||||
created_at,
|
||||
last_updated_at
|
||||
) VALUES(?,?,?,?,?,?,?)
|
||||
RETURNING *
|
||||
""",
|
||||
"""INSERT INTO chatbot (id,
|
||||
user_id,
|
||||
automatic_generation_timer,
|
||||
automatic_quote_timer,
|
||||
mods,
|
||||
created_at,
|
||||
last_updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING *
|
||||
""",
|
||||
(
|
||||
obj.id.hex,
|
||||
obj.user_id.hex,
|
||||
|
|
@ -341,13 +352,12 @@ class ChatbotRepo(IRepo[Chatbot]):
|
|||
async with (
|
||||
self.get_client(auto_commit=auto_commit) as db,
|
||||
await db.execute(
|
||||
"""UPDATE chatbot SET
|
||||
automatic_generation_timer = ?,
|
||||
automatic_quote_timer = ?,
|
||||
mods = ?,
|
||||
last_updated_at = ?
|
||||
WHERE user_id = ?
|
||||
RETURNING *
|
||||
"""UPDATE chatbot
|
||||
SET automatic_generation_timer = ?,
|
||||
automatic_quote_timer = ?,
|
||||
mods = ?,
|
||||
last_updated_at = ?
|
||||
WHERE user_id = ? RETURNING *
|
||||
""",
|
||||
(
|
||||
obj.automatic_generation_timer,
|
||||
|
|
|
|||
|
|
@ -105,6 +105,7 @@ class Quote(BaseModel):
|
|||
quote: str
|
||||
author: str
|
||||
channel_name: str
|
||||
is_active: bool = True
|
||||
created_at: datetime.datetime = Field(default_factory=utils.get_utc_now)
|
||||
last_updated_at: datetime.datetime = Field(default_factory=utils.get_utc_now)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import tempfile
|
||||
from collections.abc import Generator
|
||||
from collections.abc import Iterator
|
||||
from pathlib import Path
|
||||
|
||||
import yt_dlp
|
||||
|
|
@ -9,7 +9,7 @@ from pydantic import BaseModel
|
|||
|
||||
class DownloadClosedCaptionsSvc(BaseModel):
|
||||
@staticmethod
|
||||
def run(youtube_url: str, sub_lang: str = "es") -> Generator[Path, None, None]:
|
||||
def run(youtube_url: str, sub_lang: str = "es") -> Iterator[Path]:
|
||||
"""Download closed captions from a yt video and save it to a temp file
|
||||
|
||||
Args:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue