mirror of
https://github.com/cdryzun/tg_bot_collections.git
synced 2025-08-04 04:36:42 +08:00
* feat: add summary and search commands Signed-off-by: Frost Ming <me@frostming.com> * fix formats Signed-off-by: Frost Ming <me@frostming.com> * fix: clean up Signed-off-by: Frost Ming <me@frostming.com>
36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
import subprocess
|
|
|
|
from telebot import TeleBot
|
|
from telebot.types import Message
|
|
|
|
|
|
def github_poster_handler(message: Message, bot: TeleBot):
|
|
"""github poster: /github <github_user_name> [<start>-<end>]"""
|
|
m = message.text.strip()
|
|
message_list = m.split(",")
|
|
name = message_list[0].strip()
|
|
cmd_list = ["github_poster", "github", "--github_user_name", name, "--me", name]
|
|
if len(message_list) > 1:
|
|
years = message_list[1]
|
|
cmd_list.append("--year")
|
|
cmd_list.append(years.strip())
|
|
r = subprocess.check_output(cmd_list).decode("utf-8")
|
|
if "done" in r:
|
|
# TODO windows path
|
|
r = subprocess.check_output(
|
|
["cairosvg", "OUT_FOLDER/github.svg", "-o", f"github_{name}.png"]
|
|
).decode("utf-8")
|
|
with open(f"github_{name}.png", "rb") as photo:
|
|
bot.send_photo(
|
|
message.chat.id, photo, reply_to_message_id=message.message_id
|
|
)
|
|
|
|
|
|
def register(bot: TeleBot) -> None:
|
|
bot.register_message_handler(
|
|
github_poster_handler, commands=["github"], pass_bot=True
|
|
)
|
|
bot.register_message_handler(
|
|
github_poster_handler, regexp="^github:", pass_bot=True
|
|
)
|