mirror of
https://github.com/Xtao-Labs/misskey2telegram.git
synced 2024-11-22 05:53:09 +00:00
fix: search user
This commit is contained in:
parent
93532ca8cc
commit
db6da0456c
@ -30,7 +30,11 @@ class Announcement:
|
||||
|
||||
@property
|
||||
def updated_at(self) -> Optional[datetime]:
|
||||
return datetime.strptime(self._updated_at, "%Y-%m-%dT%H:%M:%S.%fZ") if self._updated_at else None
|
||||
return (
|
||||
datetime.strptime(self._updated_at, "%Y-%m-%dT%H:%M:%S.%fZ")
|
||||
if self._updated_at
|
||||
else None
|
||||
)
|
||||
|
||||
async def send_notice(self):
|
||||
if not self.image_url:
|
||||
@ -59,7 +63,9 @@ class Announcement:
|
||||
}
|
||||
await self.misskey_bot.core.http.request(
|
||||
Route("POST", "/api/i/read-announcement"),
|
||||
json=data, auth=True, lower=True,
|
||||
json=data,
|
||||
auth=True,
|
||||
lower=True,
|
||||
)
|
||||
|
||||
|
||||
@ -70,6 +76,8 @@ async def get_unread_announcements(misskey_bot: MisskeyBot):
|
||||
}
|
||||
req = await misskey_bot.core.http.request(
|
||||
Route("POST", "/api/announcements"),
|
||||
json=data, auth=True, lower=True,
|
||||
json=data,
|
||||
auth=True,
|
||||
lower=True,
|
||||
)
|
||||
return [Announcement(i, misskey_bot) for i in req]
|
||||
|
20
defs/chat.py
20
defs/chat.py
@ -37,9 +37,9 @@ def gen_button(message: ChatMessage):
|
||||
def get_content(message: ChatMessage) -> str:
|
||||
content = message.text or ""
|
||||
content = content[:768]
|
||||
user = f"<a href=\"{get_user_link(message.user)}\">{message.user.nickname}</a>"
|
||||
user = f'<a href="{get_user_link(message.user)}">{message.user.nickname}</a>'
|
||||
if message.group:
|
||||
group = f"<a href=\"{get_source_link(message)}\">{message.group.name}</a>"
|
||||
group = f'<a href="{get_source_link(message)}">{message.group.name}</a>'
|
||||
user += f" ( {group} )"
|
||||
return f"""<b>Misskey Message</b>
|
||||
|
||||
@ -67,7 +67,9 @@ def deprecated_to_text(func):
|
||||
|
||||
|
||||
@deprecated_to_text
|
||||
async def send_photo(cid: int, url: str, message: ChatMessage, reply_to_message_id: int):
|
||||
async def send_photo(
|
||||
cid: int, url: str, message: ChatMessage, reply_to_message_id: int
|
||||
):
|
||||
if not url:
|
||||
return await send_text(cid, message, reply_to_message_id)
|
||||
await bot.send_photo(
|
||||
@ -80,7 +82,9 @@ async def send_photo(cid: int, url: str, message: ChatMessage, reply_to_message_
|
||||
|
||||
|
||||
@deprecated_to_text
|
||||
async def send_video(cid: int, url: str, message: ChatMessage, reply_to_message_id: int):
|
||||
async def send_video(
|
||||
cid: int, url: str, message: ChatMessage, reply_to_message_id: int
|
||||
):
|
||||
if not url:
|
||||
return await send_text(cid, message, reply_to_message_id)
|
||||
await bot.send_video(
|
||||
@ -93,7 +97,9 @@ async def send_video(cid: int, url: str, message: ChatMessage, reply_to_message_
|
||||
|
||||
|
||||
@deprecated_to_text
|
||||
async def send_audio(cid: int, url: str, message: ChatMessage, reply_to_message_id: int):
|
||||
async def send_audio(
|
||||
cid: int, url: str, message: ChatMessage, reply_to_message_id: int
|
||||
):
|
||||
if not url:
|
||||
return await send_text(cid, message, reply_to_message_id)
|
||||
await bot.send_audio(
|
||||
@ -122,7 +128,9 @@ async def fetch_document(file: File) -> Optional[str]:
|
||||
|
||||
|
||||
@deprecated_to_text
|
||||
async def send_document(cid: int, file: File, message: ChatMessage, reply_to_message_id: int):
|
||||
async def send_document(
|
||||
cid: int, file: File, message: ChatMessage, reply_to_message_id: int
|
||||
):
|
||||
file = await fetch_document(file)
|
||||
if not file:
|
||||
return await send_text(cid, message, reply_to_message_id)
|
||||
|
@ -8,10 +8,10 @@ from misskey_init import get_misskey_bot
|
||||
|
||||
class ReadySend:
|
||||
def __init__(
|
||||
self,
|
||||
content: str,
|
||||
reply_id: Optional[str] = None,
|
||||
files: Optional[list[Union[str, File]]] = None,
|
||||
self,
|
||||
content: str,
|
||||
reply_id: Optional[str] = None,
|
||||
files: Optional[list[Union[str, File]]] = None,
|
||||
):
|
||||
self.content = content
|
||||
self.reply_id = reply_id
|
||||
@ -25,7 +25,7 @@ class ReadySend:
|
||||
[
|
||||
[
|
||||
InlineKeyboardButton(text="发送", callback_data="send"),
|
||||
InlineKeyboardButton(text="拒绝", callback_data="delete")
|
||||
InlineKeyboardButton(text="拒绝", callback_data="delete"),
|
||||
]
|
||||
]
|
||||
),
|
||||
@ -50,11 +50,11 @@ class ReadySend:
|
||||
|
||||
class ReadySendMessage:
|
||||
def __init__(
|
||||
self,
|
||||
text: str,
|
||||
group: bool = False,
|
||||
uid: Optional[str] = None,
|
||||
file_id: Optional[str] = None,
|
||||
self,
|
||||
text: str,
|
||||
group: bool = False,
|
||||
uid: Optional[str] = None,
|
||||
file_id: Optional[str] = None,
|
||||
):
|
||||
self.text = text
|
||||
self.user_id = None if group else uid
|
||||
@ -69,7 +69,7 @@ class ReadySendMessage:
|
||||
[
|
||||
[
|
||||
InlineKeyboardButton(text="发送", callback_data="chat_send"),
|
||||
InlineKeyboardButton(text="拒绝", callback_data="delete")
|
||||
InlineKeyboardButton(text="拒绝", callback_data="delete"),
|
||||
]
|
||||
]
|
||||
),
|
||||
|
@ -7,8 +7,14 @@ from mipac.types import IDriveFile
|
||||
from pyrogram.enums import ParseMode
|
||||
from pyrogram.errors import MediaEmpty
|
||||
|
||||
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, InputMediaPhoto, InputMediaVideo, \
|
||||
InputMediaDocument, InputMediaAudio
|
||||
from pyrogram.types import (
|
||||
InlineKeyboardMarkup,
|
||||
InlineKeyboardButton,
|
||||
InputMediaPhoto,
|
||||
InputMediaVideo,
|
||||
InputMediaDocument,
|
||||
InputMediaAudio,
|
||||
)
|
||||
|
||||
from glover import misskey_host
|
||||
from init import bot, request
|
||||
@ -65,8 +71,10 @@ def get_content(note: Note) -> str:
|
||||
show_note = note.renote
|
||||
action = "转推"
|
||||
content = note.renote.content or content
|
||||
origin = f"\n<a href=\"{get_user_link(note.renote.author)}\">{note.renote.author.nickname}</a> " \
|
||||
f"发表于 {get_post_time(note.renote.created_at)}"
|
||||
origin = (
|
||||
f'\n<a href="{get_user_link(note.renote.author)}">{note.renote.author.nickname}</a> '
|
||||
f"发表于 {get_post_time(note.renote.created_at)}"
|
||||
)
|
||||
content = content[:768]
|
||||
return f"""<b>Misskey Timeline Update</b>
|
||||
|
||||
@ -152,7 +160,9 @@ async def fetch_document(file: IDriveFile) -> Optional[str]:
|
||||
|
||||
|
||||
@deprecated_to_text
|
||||
async def send_document(cid: int, file: IDriveFile, note: Note, reply_to_message_id: int):
|
||||
async def send_document(
|
||||
cid: int, file: IDriveFile, note: Note, reply_to_message_id: int
|
||||
):
|
||||
file = await fetch_document(file)
|
||||
if not file:
|
||||
return await send_text(cid, note, reply_to_message_id)
|
||||
@ -204,7 +214,9 @@ async def get_media_group(files: list[IDriveFile]) -> list:
|
||||
return media_lists
|
||||
|
||||
|
||||
async def send_group(cid: int, files: list[IDriveFile], note: Note, reply_to_message_id: int):
|
||||
async def send_group(
|
||||
cid: int, files: list[IDriveFile], note: Note, reply_to_message_id: int
|
||||
):
|
||||
groups = await get_media_group(files)
|
||||
if len(groups) == 0:
|
||||
return await send_text(cid, note, reply_to_message_id)
|
||||
|
@ -1,5 +1,9 @@
|
||||
from json import load
|
||||
from mipac.models.notification import NotificationFollow, NotificationFollowRequest, NotificationAchievement
|
||||
from mipac.models.notification import (
|
||||
NotificationFollow,
|
||||
NotificationFollowRequest,
|
||||
NotificationAchievement,
|
||||
)
|
||||
from mipac.models.lite.user import LiteUser
|
||||
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
|
||||
|
||||
@ -34,7 +38,9 @@ async def send_user_followed(chat_id: int, notice: NotificationFollow, topic_id:
|
||||
)
|
||||
|
||||
|
||||
async def send_follow_request(chat_id: int, notice: NotificationFollowRequest, topic_id: int):
|
||||
async def send_follow_request(
|
||||
chat_id: int, notice: NotificationFollowRequest, topic_id: int
|
||||
):
|
||||
await bot.send_message(
|
||||
chat_id,
|
||||
follow_request_template.format(
|
||||
@ -54,13 +60,15 @@ async def send_follow_request(chat_id: int, notice: NotificationFollowRequest, t
|
||||
text="Reject",
|
||||
callback_data=f"request_reject:{notice.user.id}",
|
||||
),
|
||||
]
|
||||
],
|
||||
],
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
async def send_follow_request_accept(chat_id: int, notice: NotificationFollowRequest, topic_id: int):
|
||||
async def send_follow_request_accept(
|
||||
chat_id: int, notice: NotificationFollowRequest, topic_id: int
|
||||
):
|
||||
await bot.send_message(
|
||||
chat_id,
|
||||
follow_request_accept_template.format(
|
||||
@ -72,7 +80,9 @@ async def send_follow_request_accept(chat_id: int, notice: NotificationFollowReq
|
||||
)
|
||||
|
||||
|
||||
async def send_achievement_earned(chat_id: int, notice: NotificationAchievement, topic_id: int):
|
||||
async def send_achievement_earned(
|
||||
chat_id: int, notice: NotificationAchievement, topic_id: int
|
||||
):
|
||||
name, desc, note = achievement_map.get(notice.achievement, ("", "", ""))
|
||||
await bot.send_message(
|
||||
chat_id,
|
||||
|
@ -2,6 +2,7 @@ from typing import Optional
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from mipac import UserDetailed
|
||||
from mipac.errors import FailedToResolveRemoteUserError
|
||||
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
|
||||
from misskey_init import MisskeyBot
|
||||
@ -52,12 +53,25 @@ def gen_button(user: UserDetailed):
|
||||
return InlineKeyboardMarkup([first_line, second_line])
|
||||
|
||||
|
||||
async def search_user(misskey_bot: MisskeyBot, username: str, host: str = None) -> Optional[UserDetailed]:
|
||||
async def search_user(
|
||||
misskey_bot: MisskeyBot, username: str, host: str = None
|
||||
) -> Optional[UserDetailed]:
|
||||
"""
|
||||
搜索用户
|
||||
搜索用户
|
||||
"""
|
||||
if host:
|
||||
users = await misskey_bot.core.api.user.action.search_by_username_and_host(username, host, limit=1)
|
||||
users = await misskey_bot.core.api.user.action.search_by_username_and_host(
|
||||
username, host, limit=1
|
||||
)
|
||||
if not users:
|
||||
try:
|
||||
users = [
|
||||
await misskey_bot.core.api.user.action.get(
|
||||
username=username, host=host
|
||||
)
|
||||
]
|
||||
except FailedToResolveRemoteUserError:
|
||||
pass
|
||||
else:
|
||||
users = []
|
||||
async for user in misskey_bot.core.api.user.action.search(username, limit=1):
|
||||
|
@ -7,12 +7,18 @@ json_path = Path(__file__).parent / "achievement.json"
|
||||
|
||||
|
||||
def main():
|
||||
yml_data = get("https://cdn.staticaly.com/gh/misskey-dev/misskey/develop/locales/zh-CN.yml")
|
||||
yml_data = get(
|
||||
"https://cdn.staticaly.com/gh/misskey-dev/misskey/develop/locales/zh-CN.yml"
|
||||
)
|
||||
json_raw_data = yaml.safe_load(yml_data.text)
|
||||
json_data = {}
|
||||
|
||||
for key, value in json_raw_data['_achievements']['_types'].items():
|
||||
json_data[key[1:]] = (value.get("title", ""), value.get("description", ""), value.get("flavor", ""))
|
||||
for key, value in json_raw_data["_achievements"]["_types"].items():
|
||||
json_data[key[1:]] = (
|
||||
value.get("title", ""),
|
||||
value.get("description", ""),
|
||||
value.get("flavor", ""),
|
||||
)
|
||||
|
||||
with open(json_path, "w", encoding="utf-8") as f:
|
||||
dump(json_data, f, ensure_ascii=False, indent=4)
|
||||
|
10
glover.py
10
glover.py
@ -21,16 +21,16 @@ api_id = config.getint("pyrogram", "api_id", fallback=api_id)
|
||||
api_hash = config.get("pyrogram", "api_hash", fallback=api_hash)
|
||||
ipv6 = config.get("basic", "ipv6", fallback=ipv6)
|
||||
misskey_url = config.get("misskey", "url", fallback=misskey_url)
|
||||
if origin_url := re.search(r'wss?://(.*)/streaming', misskey_url):
|
||||
if origin_url := re.search(r"wss?://(.*)/streaming", misskey_url):
|
||||
misskey_host = (
|
||||
origin_url[0]
|
||||
.replace('wss', 'https')
|
||||
.replace('ws', 'http')
|
||||
.replace('/streaming', '')
|
||||
.replace("wss", "https")
|
||||
.replace("ws", "http")
|
||||
.replace("/streaming", "")
|
||||
)
|
||||
else:
|
||||
misskey_host = misskey_url
|
||||
misskey_domain = re.search(r'https?://(.*)', misskey_host)[1]
|
||||
misskey_domain = re.search(r"https?://(.*)", misskey_host)[1]
|
||||
web_domain = config.get("misskey", "web_domain", fallback=web_domain)
|
||||
admin = config.getint("misskey", "admin", fallback=admin)
|
||||
try:
|
||||
|
4
init.py
4
init.py
@ -20,7 +20,9 @@ logs.setLevel(INFO)
|
||||
if not scheduler.running:
|
||||
scheduler.start()
|
||||
# Init client
|
||||
bot = pyrogram.Client("bot", api_id=api_id, api_hash=api_hash, ipv6=ipv6, plugins=dict(root="modules"))
|
||||
bot = pyrogram.Client(
|
||||
"bot", api_id=api_id, api_hash=api_hash, ipv6=ipv6, plugins=dict(root="modules")
|
||||
)
|
||||
# fix topic group
|
||||
setattr(pyrogram.types.Message, "old_parse", getattr(pyrogram.types.Message, "_parse"))
|
||||
setattr(pyrogram.types.Message, "_parse", fix_topic)
|
||||
|
@ -6,12 +6,23 @@ from aiohttp import ClientConnectorError
|
||||
from mipa.exception import WebSocketNotConnected
|
||||
from mipa.ext import commands
|
||||
from mipa.router import Router
|
||||
from mipac import Note, NotificationFollow, NotificationFollowRequest, ChatMessage, NotificationAchievement
|
||||
from mipac import (
|
||||
Note,
|
||||
NotificationFollow,
|
||||
NotificationFollowRequest,
|
||||
ChatMessage,
|
||||
NotificationAchievement,
|
||||
)
|
||||
from mipac.client import Client as MisskeyClient
|
||||
|
||||
from defs.chat import send_chat_message
|
||||
from defs.misskey import send_update
|
||||
from defs.notice import send_user_followed, send_follow_request, send_follow_request_accept, send_achievement_earned
|
||||
from defs.notice import (
|
||||
send_user_followed,
|
||||
send_follow_request,
|
||||
send_follow_request_accept,
|
||||
send_achievement_earned,
|
||||
)
|
||||
from glover import misskey_url, misskey_host
|
||||
|
||||
from models.models.user import User, TokenStatusEnum
|
||||
@ -39,26 +50,36 @@ class MisskeyBot(commands.Bot):
|
||||
|
||||
async def on_user_followed(self, notice: NotificationFollow):
|
||||
if self.tg_user:
|
||||
await send_user_followed(self.tg_user.chat_id, notice, self.tg_user.notice_topic)
|
||||
await send_user_followed(
|
||||
self.tg_user.chat_id, notice, self.tg_user.notice_topic
|
||||
)
|
||||
|
||||
async def on_follow_request(self, notice: NotificationFollowRequest):
|
||||
if self.tg_user:
|
||||
await send_follow_request(self.tg_user.chat_id, notice, self.tg_user.notice_topic)
|
||||
await send_follow_request(
|
||||
self.tg_user.chat_id, notice, self.tg_user.notice_topic
|
||||
)
|
||||
|
||||
async def on_follow_request_accept(self, notice: NotificationFollowRequest):
|
||||
if self.tg_user:
|
||||
await send_follow_request_accept(self.tg_user.chat_id, notice, self.tg_user.notice_topic)
|
||||
await send_follow_request_accept(
|
||||
self.tg_user.chat_id, notice, self.tg_user.notice_topic
|
||||
)
|
||||
|
||||
async def on_chat(self, message: ChatMessage):
|
||||
if self.tg_user:
|
||||
await send_chat_message(self.tg_user.chat_id, message, self.tg_user.notice_topic)
|
||||
await send_chat_message(
|
||||
self.tg_user.chat_id, message, self.tg_user.notice_topic
|
||||
)
|
||||
|
||||
async def on_chat_unread_message(self, message: ChatMessage):
|
||||
await message.api.read()
|
||||
|
||||
async def on_achievement_earned(self, notice: NotificationAchievement):
|
||||
if self.tg_user:
|
||||
await send_achievement_earned(self.tg_user.chat_id, notice, self.tg_user.notice_topic)
|
||||
await send_achievement_earned(
|
||||
self.tg_user.chat_id, notice, self.tg_user.notice_topic
|
||||
)
|
||||
|
||||
|
||||
misskey_bot_map: dict[int, MisskeyBot] = {}
|
||||
|
@ -5,7 +5,6 @@ from misskey_init import get_misskey_bot
|
||||
|
||||
|
||||
def private_filter(filter_type: str = "timeline"):
|
||||
|
||||
async def func(_, __, update: Update):
|
||||
if isinstance(update, Message):
|
||||
user_id = update.from_user.id if update.from_user else None
|
||||
|
@ -2,20 +2,22 @@ import pyrogram
|
||||
|
||||
|
||||
async def fix_topic(
|
||||
client: "pyrogram.Client",
|
||||
message: pyrogram.raw.base.Message,
|
||||
users: dict,
|
||||
chats: dict,
|
||||
is_scheduled: bool = False,
|
||||
replies: int = 1
|
||||
client: "pyrogram.Client",
|
||||
message: pyrogram.raw.base.Message,
|
||||
users: dict,
|
||||
chats: dict,
|
||||
is_scheduled: bool = False,
|
||||
replies: int = 1,
|
||||
):
|
||||
parsed = await pyrogram.types.Message.old_parse(client, message, users, chats, is_scheduled, replies) # noqa
|
||||
parsed = await pyrogram.types.Message.old_parse(
|
||||
client, message, users, chats, is_scheduled, replies
|
||||
) # noqa
|
||||
if isinstance(message, pyrogram.raw.types.Message):
|
||||
parsed.forum_topic = getattr(message.reply_to, "forum_topic", None)
|
||||
if (
|
||||
message.reply_to
|
||||
and parsed.forum_topic
|
||||
and not message.reply_to.reply_to_top_id
|
||||
message.reply_to
|
||||
and parsed.forum_topic
|
||||
and not message.reply_to.reply_to_top_id
|
||||
):
|
||||
parsed.reply_to_top_message_id = parsed.reply_to_message_id
|
||||
parsed.reply_to_message_id = None
|
||||
|
@ -27,18 +27,14 @@ class UserAction:
|
||||
async def get_user_if_ok(user_id: int) -> Optional[User]:
|
||||
async with sqlite.session() as session:
|
||||
session = cast(AsyncSession, session)
|
||||
statement = select(User).where(
|
||||
User.user_id == user_id
|
||||
).where(
|
||||
User.status == TokenStatusEnum.STATUS_SUCCESS
|
||||
).where(
|
||||
User.chat_id != 0
|
||||
).where(
|
||||
User.timeline_topic != 0
|
||||
).where(
|
||||
User.notice_topic != 0
|
||||
).where(
|
||||
User.token != ""
|
||||
statement = (
|
||||
select(User)
|
||||
.where(User.user_id == user_id)
|
||||
.where(User.status == TokenStatusEnum.STATUS_SUCCESS)
|
||||
.where(User.chat_id != 0)
|
||||
.where(User.timeline_topic != 0)
|
||||
.where(User.notice_topic != 0)
|
||||
.where(User.token != "")
|
||||
)
|
||||
results = await session.exec(statement)
|
||||
return user[0] if (user := results.first()) else None
|
||||
@ -47,16 +43,13 @@ class UserAction:
|
||||
async def get_all_token_ok_users() -> list[User]:
|
||||
async with sqlite.session() as session:
|
||||
session = cast(AsyncSession, session)
|
||||
statement = select(User).where(
|
||||
User.status == TokenStatusEnum.STATUS_SUCCESS
|
||||
).where(
|
||||
User.chat_id != 0
|
||||
).where(
|
||||
User.timeline_topic != 0
|
||||
).where(
|
||||
User.notice_topic != 0
|
||||
).where(
|
||||
User.token != ""
|
||||
statement = (
|
||||
select(User)
|
||||
.where(User.status == TokenStatusEnum.STATUS_SUCCESS)
|
||||
.where(User.chat_id != 0)
|
||||
.where(User.timeline_topic != 0)
|
||||
.where(User.notice_topic != 0)
|
||||
.where(User.token != "")
|
||||
)
|
||||
results = await session.exec(statement)
|
||||
users = results.all()
|
||||
@ -90,7 +83,9 @@ class UserAction:
|
||||
async def change_user_token(user_id: int, token: str) -> bool:
|
||||
user = await UserAction.get_user_by_id(user_id)
|
||||
if not user:
|
||||
user = User(user_id=user_id, token=token, status=TokenStatusEnum.STATUS_SUCCESS)
|
||||
user = User(
|
||||
user_id=user_id, token=token, status=TokenStatusEnum.STATUS_SUCCESS
|
||||
)
|
||||
user.token = token
|
||||
user.status = TokenStatusEnum.STATUS_SUCCESS
|
||||
await UserAction.update_user(user)
|
||||
|
@ -28,12 +28,16 @@ async def finish_check(message: Message):
|
||||
await message.reply("设置完成,开始链接。", quote=True)
|
||||
|
||||
|
||||
@Client.on_message(filters.incoming & filters.group & filters.command(["bind_timeline"]))
|
||||
@Client.on_message(
|
||||
filters.incoming & filters.group & filters.command(["bind_timeline"])
|
||||
)
|
||||
async def bind_timeline_command(_: Client, message: Message):
|
||||
if not await pre_check(message):
|
||||
return
|
||||
await UserAction.change_user_group_id(message.from_user.id, message.chat.id)
|
||||
if await UserAction.change_user_timeline(message.from_user.id, message.reply_to_top_message_id):
|
||||
if await UserAction.change_user_timeline(
|
||||
message.from_user.id, message.reply_to_top_message_id
|
||||
):
|
||||
await message.reply("Timeline 绑定成功。", quote=True)
|
||||
else:
|
||||
await message.reply("Timeline 绑定失败,不能和 Notice 话题相同。", quote=True)
|
||||
@ -45,7 +49,9 @@ async def bind_notice_command(_: Client, message: Message):
|
||||
if not await pre_check(message):
|
||||
return
|
||||
await UserAction.change_user_group_id(message.from_user.id, message.chat.id)
|
||||
if await UserAction.change_user_notice(message.from_user.id, message.reply_to_top_message_id):
|
||||
if await UserAction.change_user_notice(
|
||||
message.from_user.id, message.reply_to_top_message_id
|
||||
):
|
||||
await message.reply("Notice 话题绑定成功。", quote=True)
|
||||
else:
|
||||
await message.reply("Notice 话题绑定失败,不能和 Timeline 话题相同。", quote=True)
|
||||
|
@ -12,10 +12,7 @@ from models.filters import notice_filter
|
||||
|
||||
def get_uid(message: Message) -> Tuple[bool, str]:
|
||||
group, user, uid = False, None, None
|
||||
if (
|
||||
not message.reply_to_message
|
||||
or not message.reply_to_message.reply_markup
|
||||
):
|
||||
if not message.reply_to_message or not message.reply_to_message.reply_markup:
|
||||
raise ContinuePropagation
|
||||
with contextlib.suppress(IndexError, AttributeError):
|
||||
url = message.reply_to_message.reply_markup.inline_keyboard[0][0].url
|
||||
@ -60,7 +57,7 @@ async def chat_photo_command(_: Client, message: Message):
|
||||
@Client.on_callback_query(filters.regex("^chat_send$") & notice_filter)
|
||||
async def chat_send_callback(_: Client, callback_query: CallbackQuery):
|
||||
"""
|
||||
发送
|
||||
发送
|
||||
"""
|
||||
msg = callback_query.message
|
||||
if need_send := ready_send.get((msg.chat.id, msg.id), None):
|
||||
|
@ -6,11 +6,16 @@ from misskey_init import get_misskey_bot
|
||||
from models.filters import timeline_filter
|
||||
|
||||
|
||||
@Client.on_message(filters.incoming & filters.text & filters.reply & timeline_filter &
|
||||
filters.command("delete"))
|
||||
@Client.on_message(
|
||||
filters.incoming
|
||||
& filters.text
|
||||
& filters.reply
|
||||
& timeline_filter
|
||||
& filters.command("delete")
|
||||
)
|
||||
async def delete_command(_: Client, message: Message):
|
||||
"""
|
||||
删除
|
||||
删除
|
||||
"""
|
||||
if not message.reply_to_message:
|
||||
return
|
||||
|
@ -18,11 +18,10 @@ help_msg = f"""这里是 Bot 帮助
|
||||
更多功能正在开发中,敬请期待!"""
|
||||
|
||||
|
||||
@Client.on_message(filters.incoming & filters.private &
|
||||
filters.command(["help"]))
|
||||
@Client.on_message(filters.incoming & filters.private & filters.command(["help"]))
|
||||
async def help_command(_: Client, message: Message):
|
||||
"""
|
||||
回应 help
|
||||
回应 help
|
||||
"""
|
||||
await message.reply(
|
||||
help_msg,
|
||||
|
@ -12,7 +12,7 @@ from models.filters import timeline_filter
|
||||
@Client.on_message(filters.incoming & timeline_filter & filters.text)
|
||||
async def post_command(_: Client, message: Message):
|
||||
"""
|
||||
发送新贴或者回复
|
||||
发送新贴或者回复
|
||||
"""
|
||||
note_id = None
|
||||
if message.reply_to_message and message.reply_to_message.reply_markup:
|
||||
@ -29,7 +29,7 @@ async def post_command(_: Client, message: Message):
|
||||
@Client.on_message(filters.incoming & timeline_filter & filters.photo)
|
||||
async def post_photo_command(_: Client, message: Message):
|
||||
"""
|
||||
发送新贴或者回复
|
||||
发送新贴或者回复
|
||||
"""
|
||||
note_id = None
|
||||
if message.reply_to_message and message.reply_to_message.reply_markup:
|
||||
@ -51,7 +51,7 @@ async def post_photo_command(_: Client, message: Message):
|
||||
@Client.on_callback_query(filters.regex("^send$") & timeline_filter)
|
||||
async def send_callback(_: Client, callback_query: CallbackQuery):
|
||||
"""
|
||||
发送
|
||||
发送
|
||||
"""
|
||||
msg = callback_query.message
|
||||
if need_send := ready_send.get((msg.chat.id, msg.id), None):
|
||||
@ -64,7 +64,7 @@ async def send_callback(_: Client, callback_query: CallbackQuery):
|
||||
@Client.on_callback_query(filters.regex("^delete$") & timeline_filter)
|
||||
async def delete_callback(_: Client, callback_query: CallbackQuery):
|
||||
"""
|
||||
删除
|
||||
删除
|
||||
"""
|
||||
if not (need_send := callback_query.message):
|
||||
return await callback_query.answer("按钮已过期", show_alert=True)
|
||||
|
@ -1,5 +1,9 @@
|
||||
import contextlib
|
||||
from mipac.errors import InternalErrorError, AlreadyFollowingError, FolloweeIsYourselfError
|
||||
from mipac.errors import (
|
||||
InternalErrorError,
|
||||
AlreadyFollowingError,
|
||||
FolloweeIsYourselfError,
|
||||
)
|
||||
from pyrogram import Client, filters
|
||||
from pyrogram.types import Message, CallbackQuery
|
||||
|
||||
@ -12,7 +16,7 @@ from models.filters import notice_filter
|
||||
@Client.on_message(filters.incoming & notice_filter & filters.regex(r"^@(.*)$"))
|
||||
async def search_user_command(_: Client, message: Message):
|
||||
"""
|
||||
搜索用户
|
||||
搜索用户
|
||||
"""
|
||||
username = message.matches[0].group(1)
|
||||
path = username.strip().split("@")
|
||||
@ -26,11 +30,17 @@ async def search_user_command(_: Client, message: Message):
|
||||
text, button = gen_text(user), gen_button(user)
|
||||
if user.avatar_url:
|
||||
try:
|
||||
await message.reply_photo(user.avatar_url, caption=text, reply_markup=button, quote=True)
|
||||
await message.reply_photo(
|
||||
user.avatar_url, caption=text, reply_markup=button, quote=True
|
||||
)
|
||||
except Exception:
|
||||
await message.reply(text, reply_markup=button, quote=True, disable_web_page_preview=True)
|
||||
await message.reply(
|
||||
text, reply_markup=button, quote=True, disable_web_page_preview=True
|
||||
)
|
||||
else:
|
||||
await message.reply(text, reply_markup=button, quote=True, disable_web_page_preview=True)
|
||||
await message.reply(
|
||||
text, reply_markup=button, quote=True, disable_web_page_preview=True
|
||||
)
|
||||
except Exception as e:
|
||||
return await message.reply(f"搜索用户失败:{e}", quote=True)
|
||||
|
||||
@ -39,7 +49,7 @@ async def search_user_command(_: Client, message: Message):
|
||||
@Client.on_callback_query(filters.regex(r"^follow:(.*)$") & notice_filter)
|
||||
async def follow_user_callback(_: Client, callback_query: CallbackQuery):
|
||||
"""
|
||||
关注/取消关注用户
|
||||
关注/取消关注用户
|
||||
"""
|
||||
user_id = callback_query.matches[0].group(1)
|
||||
button = callback_query.message.reply_markup
|
||||
|
@ -30,11 +30,10 @@ def gen_url():
|
||||
return f"https://{web_domain}/gen?host={misskey_domain}&back_host={web_domain}&username={bot.me.username}"
|
||||
|
||||
|
||||
@Client.on_message(filters.incoming & filters.private &
|
||||
filters.command(["start"]))
|
||||
@Client.on_message(filters.incoming & filters.private & filters.command(["start"]))
|
||||
async def start_command(_: Client, message: Message):
|
||||
"""
|
||||
回应 start
|
||||
回应 start
|
||||
"""
|
||||
if len(message.command) == 2:
|
||||
token = message.command[1]
|
||||
@ -44,9 +43,7 @@ async def start_command(_: Client, message: Message):
|
||||
if await test_token(token):
|
||||
await UserAction.change_user_token(message.from_user.id, token)
|
||||
await message.reply(
|
||||
"Token 验证成功,绑定账号完成。\n"
|
||||
"当你撤销此登录时,你可以重新点击按钮授权。",
|
||||
quote=True
|
||||
"Token 验证成功,绑定账号完成。\n" "当你撤销此登录时,你可以重新点击按钮授权。", quote=True
|
||||
)
|
||||
await finish_check(message)
|
||||
else:
|
||||
@ -61,5 +58,5 @@ async def start_command(_: Client, message: Message):
|
||||
InlineKeyboardButton(text="绑定 Misskey 账号", url=gen_url()),
|
||||
]
|
||||
]
|
||||
)
|
||||
),
|
||||
)
|
||||
|
@ -8,11 +8,10 @@ from models.models.user import TokenStatusEnum
|
||||
from models.services.user import UserAction
|
||||
|
||||
|
||||
@Client.on_message(filters.incoming & filters.private &
|
||||
filters.command(["status"]))
|
||||
@Client.on_message(filters.incoming & filters.private & filters.command(["status"]))
|
||||
async def status_command(_: Client, message: Message):
|
||||
"""
|
||||
回应 status
|
||||
回应 status
|
||||
"""
|
||||
user = await UserAction.get_user_by_id(message.from_user.id)
|
||||
if not user:
|
||||
|
Loading…
Reference in New Issue
Block a user