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:", "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,5 +1,6 @@
import configparser import configparser
from os import path from os import path
from typing import Optional
import requests import requests
@ -10,7 +11,7 @@ _c.optionxform = str
def init_config() -> None: def init_config() -> None:
if not _validate_config(): if _validate_config() is False:
print("Config is invalid.") print("Config is invalid.")
exit(1) exit(1)
_c.read("config.ini", "utf-8") _c.read("config.ini", "utf-8")
@ -26,7 +27,7 @@ def _validate_config() -> bool:
"Name": "Danbooru", "Name": "Danbooru",
"Host": "danbooru.donmai.us", "Host": "danbooru.donmai.us",
"HostName": "", "HostName": "",
"HTTPS": True, "PreferSecureProtocol": True,
}, },
} }
@ -57,7 +58,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
@ -69,6 +70,9 @@ 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")
@ -79,6 +83,10 @@ 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")
@ -86,7 +94,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", "HTTPS")): if eval(_c.get("App", "PreferSecureProtocol")):
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,8 +53,6 @@ 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}"),
] ]
] ]
@ -92,6 +90,8 @@ 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,12 +102,15 @@ async def answer_query(
" ".join( " ".join(
[ [
HtmlFormat.code(f"#{query}"), HtmlFormat.code(f"#{query}"),
" ".join( HtmlFormat.hyperlink(
[ " ".join(
HtmlFormat.bold(f"{characters} ({copyrights})"), [
"drawn by", HtmlFormat.bold(f"{characters} ({copyrights})"),
HtmlFormat.bold(artists), "drawn by",
] HtmlFormat.bold(artists),
]
),
f"{config.app.protocol}://{config.app.hostname}/posts/{query}",
), ),
rating, rating,
] ]