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