Compare commits

...

4 commits

Author SHA1 Message Date
1d40f6ae5d
feat: replace View original with Open in App
All checks were successful
Build / Upload to production (push) Successful in 1m17s
y'all can always use Show information button anyway

Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
2025-07-23 03:12:55 +03:00
f7a9bf9f13
change: remove implicitly set variable types
Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
2025-07-23 02:59:10 +03:00
0fa430cb51
change!: rename PreferSecureProtocol to HTTPS
Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
2025-07-23 02:46:28 +03:00
235fab19e6
fix: all my homies hate python 3.11
this commit fixes some issues for 3.11 by using triple-quoted f-strings and avoiding same quote type when nesting inside f-strings

Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
2025-07-23 02:23:45 +03:00
3 changed files with 18 additions and 29 deletions

View file

@ -120,7 +120,7 @@ async def info_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
"Date:", "Date:",
HtmlFormat.hyperlink( HtmlFormat.hyperlink(
created_at.strftime("%Y-%m-%d %X (%z)"), created_at.strftime("%Y-%m-%d %X (%z)"),
f"{config.app.protocol}://{config.app.hostname}/posts?tags=date:{created_at.strftime("%Y-%m-%d")}", f"{config.app.protocol}://{config.app.hostname}/posts?tags=date:{created_at.strftime('%Y-%m-%d')}",
), ),
] ]
) )
@ -295,7 +295,7 @@ async def user_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
vote_post_count, vote_post_count,
f"{config.app.protocol}://{config.app.hostname}/post_votes?search[user_name]={user_data['name']}", f"{config.app.protocol}://{config.app.hostname}/post_votes?search[user_name]={user_data['name']}",
), ),
f"({' '.join([ f"""({' '.join([
HtmlFormat.hyperlink( HtmlFormat.hyperlink(
f"up:{upvote_post_count}", f"up:{upvote_post_count}",
f"{config.app.protocol}://{config.app.hostname}/post_votes?search[user_name]={user_data['name']}&search[score]=1", f"{config.app.protocol}://{config.app.hostname}/post_votes?search[user_name]={user_data['name']}&search[score]=1",
@ -304,7 +304,7 @@ async def user_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
f"down:{downvote_post_count}", f"down:{downvote_post_count}",
f"{config.app.protocol}://{config.app.hostname}/post_votes?search[user_name]={user_data['name']}&search[score]=-1", f"{config.app.protocol}://{config.app.hostname}/post_votes?search[user_name]={user_data['name']}&search[score]=-1",
), ),
])})", ])})""",
] ]
) )
) )
@ -438,7 +438,7 @@ async def user_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
total_feedback_count, total_feedback_count,
f"{config.app.protocol}://{config.app.hostname}/user_feedbacks?search[user_name]={user_data['name']}", f"{config.app.protocol}://{config.app.hostname}/user_feedbacks?search[user_name]={user_data['name']}",
), ),
f"({' '.join([ f"""({' '.join([
HtmlFormat.hyperlink( HtmlFormat.hyperlink(
f"positive:{user_data['positive_feedback_count']}", f"positive:{user_data['positive_feedback_count']}",
f"{config.app.protocol}://{config.app.hostname}/user_feedbacks?search[user_name]={user_data['name']}&search[category]=positive", f"{config.app.protocol}://{config.app.hostname}/user_feedbacks?search[user_name]={user_data['name']}&search[category]=positive",
@ -451,7 +451,7 @@ async def user_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
f"negative:{user_data['negative_feedback_count']}", f"negative:{user_data['negative_feedback_count']}",
f"{config.app.protocol}://{config.app.hostname}/user_feedbacks?search[user_name]={user_data['name']}&search[category]=negative", f"{config.app.protocol}://{config.app.hostname}/user_feedbacks?search[user_name]={user_data['name']}&search[category]=negative",
), ),
])})" ])})"""
] ]
) )
) )

View file

@ -1,6 +1,5 @@
import configparser import configparser
from os import path from os import path
from typing import Optional
import requests import requests
@ -11,7 +10,7 @@ _c.optionxform = str
def init_config() -> None: def init_config() -> None:
if _validate_config() is False: if not _validate_config():
print("Config is invalid.") print("Config is invalid.")
exit(1) exit(1)
_c.read("config.ini", "utf-8") _c.read("config.ini", "utf-8")
@ -27,7 +26,7 @@ def _validate_config() -> bool:
"Name": "Danbooru", "Name": "Danbooru",
"Host": "danbooru.donmai.us", "Host": "danbooru.donmai.us",
"HostName": "", "HostName": "",
"PreferSecureProtocol": True, "HTTPS": True,
}, },
} }
@ -58,7 +57,7 @@ def _validate_config() -> bool:
try: try:
response = requests.get( response = requests.get(
f"http://{_c.get("App", "Host")}/status.json", timeout=10 f"http://{_c.get('App', 'Host')}/status.json", timeout=10
) )
if response.status_code != 200: if response.status_code != 200:
raise requests.exceptions.InvalidURL raise requests.exceptions.InvalidURL
@ -70,9 +69,6 @@ def _validate_config() -> bool:
class _General: class _General:
token: str
sourceurl: Optional[str]
def __init__(self): def __init__(self):
self.token = _c.get("General", "Token") self.token = _c.get("General", "Token")
self.sourceurl = _c.get("General", "SourceUrl") self.sourceurl = _c.get("General", "SourceUrl")
@ -83,10 +79,6 @@ class _General:
class _App: class _App:
name: str
host: str
hostname: str
def __init__(self): def __init__(self):
self.name = _c.get("App", "Name") self.name = _c.get("App", "Name")
self.host = _c.get("App", "Host") self.host = _c.get("App", "Host")
@ -94,7 +86,7 @@ class _App:
if not self.hostname: if not self.hostname:
self.hostname = self.host self.hostname = self.host
self.protocol = "http" self.protocol = "http"
if eval(_c.get("App", "PreferSecureProtocol")): if eval(_c.get("App", "HTTPS")):
self.protocol = "https" self.protocol = "https"

View file

@ -38,7 +38,7 @@ async def inline_query(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
async def answer_query( async def answer_query(
update: Update, context: ContextTypes.DEFAULT_TYPE, query: int, data update: Update, context: ContextTypes.DEFAULT_TYPE, query: int, data
) -> None: ) -> None:
characters = humanize_tags_from_json(data["tag_string_character"], "no characters") characters = humanize_tags_from_json(data["tag_string_character"], "no characters")
copyrights = humanize_tags_from_json( copyrights = humanize_tags_from_json(
@ -53,6 +53,8 @@ async def answer_query(
"Show information", "Show information",
url=helpers.create_deep_linked_url(context.bot.username, str(query)), url=helpers.create_deep_linked_url(context.bot.username, str(query)),
), ),
InlineKeyboardButton(f"Open in {config.app.name}",
url=f"{config.app.protocol}://{config.app.hostname}/posts/{query}"),
] ]
] ]
@ -90,8 +92,6 @@ async def answer_query(
await update.inline_query.answer(results) await update.inline_query.answer(results)
return return
keyboard[0].append(InlineKeyboardButton("View original", url=data["file_url"]))
results = [ results = [
InlineQueryResultArticle( InlineQueryResultArticle(
id=str(uuid4()), id=str(uuid4()),
@ -102,15 +102,12 @@ async def answer_query(
" ".join( " ".join(
[ [
HtmlFormat.code(f"#{query}"), HtmlFormat.code(f"#{query}"),
HtmlFormat.hyperlink( " ".join(
" ".join( [
[ HtmlFormat.bold(f"{characters} ({copyrights})"),
HtmlFormat.bold(f"{characters} ({copyrights})"), "drawn by",
"drawn by", HtmlFormat.bold(artists),
HtmlFormat.bold(artists), ]
]
),
f"{config.app.protocol}://{config.app.hostname}/posts/{query}",
), ),
rating, rating,
] ]