Compare commits

..

No commits in common. "1d40f6ae5d4c1bbd8577645ce814d391be6c7832" and "1b8c096db6ae5318f5346f77b3f8ec6f86202456" have entirely different histories.

3 changed files with 29 additions and 18 deletions

View file

@ -120,7 +120,7 @@ async def info_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
"Date:",
HtmlFormat.hyperlink(
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,
f"{config.app.protocol}://{config.app.hostname}/post_votes?search[user_name]={user_data['name']}",
),
f"""({' '.join([
f"({' '.join([
HtmlFormat.hyperlink(
f"up:{upvote_post_count}",
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"{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,
f"{config.app.protocol}://{config.app.hostname}/user_feedbacks?search[user_name]={user_data['name']}",
),
f"""({' '.join([
f"({' '.join([
HtmlFormat.hyperlink(
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",
@ -451,7 +451,7 @@ async def user_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
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",
),
])})"""
])})"
]
)
)

View file

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

View file

@ -53,8 +53,6 @@ async def answer_query(
"Show information",
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}"),
]
]
@ -92,6 +90,8 @@ async def answer_query(
await update.inline_query.answer(results)
return
keyboard[0].append(InlineKeyboardButton("View original", url=data["file_url"]))
results = [
InlineQueryResultArticle(
id=str(uuid4()),
@ -102,6 +102,7 @@ async def answer_query(
" ".join(
[
HtmlFormat.code(f"#{query}"),
HtmlFormat.hyperlink(
" ".join(
[
HtmlFormat.bold(f"{characters} ({copyrights})"),
@ -109,6 +110,8 @@ async def answer_query(
HtmlFormat.bold(artists),
]
),
f"{config.app.protocol}://{config.app.hostname}/posts/{query}",
),
rating,
]
),