Compare commits
4 commits
1b8c096db6
...
1d40f6ae5d
Author | SHA1 | Date | |
---|---|---|---|
1d40f6ae5d | |||
f7a9bf9f13 | |||
0fa430cb51 | |||
235fab19e6 |
3 changed files with 18 additions and 29 deletions
10
commands.py
10
commands.py
|
@ -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",
|
||||
),
|
||||
])})"
|
||||
])})"""
|
||||
]
|
||||
)
|
||||
)
|
||||
|
|
16
config.py
16
config.py
|
@ -1,6 +1,5 @@
|
|||
import configparser
|
||||
from os import path
|
||||
from typing import Optional
|
||||
|
||||
import requests
|
||||
|
||||
|
@ -11,7 +10,7 @@ _c.optionxform = str
|
|||
|
||||
|
||||
def init_config() -> None:
|
||||
if _validate_config() is False:
|
||||
if not _validate_config():
|
||||
print("Config is invalid.")
|
||||
exit(1)
|
||||
_c.read("config.ini", "utf-8")
|
||||
|
@ -27,7 +26,7 @@ def _validate_config() -> bool:
|
|||
"Name": "Danbooru",
|
||||
"Host": "danbooru.donmai.us",
|
||||
"HostName": "",
|
||||
"PreferSecureProtocol": True,
|
||||
"HTTPS": True,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -58,7 +57,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
|
||||
|
@ -70,9 +69,6 @@ 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")
|
||||
|
@ -83,10 +79,6 @@ 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")
|
||||
|
@ -94,7 +86,7 @@ class _App:
|
|||
if not self.hostname:
|
||||
self.hostname = self.host
|
||||
self.protocol = "http"
|
||||
if eval(_c.get("App", "PreferSecureProtocol")):
|
||||
if eval(_c.get("App", "HTTPS")):
|
||||
self.protocol = "https"
|
||||
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ async def inline_query(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
|
|||
|
||||
|
||||
async def answer_query(
|
||||
update: Update, context: ContextTypes.DEFAULT_TYPE, query: int, data
|
||||
update: Update, context: ContextTypes.DEFAULT_TYPE, query: int, data
|
||||
) -> None:
|
||||
characters = humanize_tags_from_json(data["tag_string_character"], "no characters")
|
||||
copyrights = humanize_tags_from_json(
|
||||
|
@ -53,6 +53,8 @@ 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}"),
|
||||
]
|
||||
]
|
||||
|
||||
|
@ -90,8 +92,6 @@ 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,15 +102,12 @@ async def answer_query(
|
|||
" ".join(
|
||||
[
|
||||
HtmlFormat.code(f"#{query}"),
|
||||
HtmlFormat.hyperlink(
|
||||
" ".join(
|
||||
[
|
||||
HtmlFormat.bold(f"{characters} ({copyrights})"),
|
||||
"drawn by",
|
||||
HtmlFormat.bold(artists),
|
||||
]
|
||||
),
|
||||
f"{config.app.protocol}://{config.app.hostname}/posts/{query}",
|
||||
" ".join(
|
||||
[
|
||||
HtmlFormat.bold(f"{characters} ({copyrights})"),
|
||||
"drawn by",
|
||||
HtmlFormat.bold(artists),
|
||||
]
|
||||
),
|
||||
rating,
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue