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)
|
||||||
|
@ -8,10 +8,10 @@ from misskey_init import get_misskey_bot
|
|||||||
|
|
||||||
class ReadySend:
|
class ReadySend:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
content: str,
|
content: str,
|
||||||
reply_id: Optional[str] = None,
|
reply_id: Optional[str] = None,
|
||||||
files: Optional[list[Union[str, File]]] = None,
|
files: Optional[list[Union[str, File]]] = None,
|
||||||
):
|
):
|
||||||
self.content = content
|
self.content = content
|
||||||
self.reply_id = reply_id
|
self.reply_id = reply_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"),
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
@ -50,11 +50,11 @@ class ReadySend:
|
|||||||
|
|
||||||
class ReadySendMessage:
|
class ReadySendMessage:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
text: str,
|
text: str,
|
||||||
group: bool = False,
|
group: bool = False,
|
||||||
uid: Optional[str] = None,
|
uid: Optional[str] = None,
|
||||||
file_id: Optional[str] = None,
|
file_id: Optional[str] = None,
|
||||||
):
|
):
|
||||||
self.text = text
|
self.text = text
|
||||||
self.user_id = None if group else uid
|
self.user_id = None if group else uid
|
||||||
@ -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"发表于 {get_post_time(note.renote.created_at)}"
|
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]
|
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
|
||||||
|
@ -2,20 +2,22 @@ import pyrogram
|
|||||||
|
|
||||||
|
|
||||||
async def fix_topic(
|
async def fix_topic(
|
||||||
client: "pyrogram.Client",
|
client: "pyrogram.Client",
|
||||||
message: pyrogram.raw.base.Message,
|
message: pyrogram.raw.base.Message,
|
||||||
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 (
|
||||||
message.reply_to
|
message.reply_to
|
||||||
and parsed.forum_topic
|
and parsed.forum_topic
|
||||||
and not message.reply_to.reply_to_top_id
|
and not message.reply_to.reply_to_top_id
|
||||||
):
|
):
|
||||||
parsed.reply_to_top_message_id = parsed.reply_to_message_id
|
parsed.reply_to_top_message_id = parsed.reply_to_message_id
|
||||||
parsed.reply_to_message_id = None
|
parsed.reply_to_message_id = None
|
||||||
|
@ -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
|
||||||
@ -60,7 +57,7 @@ async def chat_photo_command(_: Client, message: Message):
|
|||||||
@Client.on_callback_query(filters.regex("^chat_send$") & notice_filter)
|
@Client.on_callback_query(filters.regex("^chat_send$") & notice_filter)
|
||||||
async def chat_send_callback(_: Client, callback_query: CallbackQuery):
|
async def chat_send_callback(_: Client, callback_query: CallbackQuery):
|
||||||
"""
|
"""
|
||||||
发送
|
发送
|
||||||
"""
|
"""
|
||||||
msg = callback_query.message
|
msg = callback_query.message
|
||||||
if need_send := ready_send.get((msg.chat.id, msg.id), None):
|
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
|
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):
|
||||||
"""
|
"""
|
||||||
删除
|
删除
|
||||||
"""
|
"""
|
||||||
if not message.reply_to_message:
|
if not message.reply_to_message:
|
||||||
return
|
return
|
||||||
|
@ -18,11 +18,10 @@ 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
|
||||||
"""
|
"""
|
||||||
await message.reply(
|
await message.reply(
|
||||||
help_msg,
|
help_msg,
|
||||||
|
@ -12,7 +12,7 @@ from models.filters import timeline_filter
|
|||||||
@Client.on_message(filters.incoming & timeline_filter & filters.text)
|
@Client.on_message(filters.incoming & timeline_filter & filters.text)
|
||||||
async def post_command(_: Client, message: Message):
|
async def post_command(_: Client, message: Message):
|
||||||
"""
|
"""
|
||||||
发送新贴或者回复
|
发送新贴或者回复
|
||||||
"""
|
"""
|
||||||
note_id = None
|
note_id = None
|
||||||
if message.reply_to_message and message.reply_to_message.reply_markup:
|
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)
|
@Client.on_message(filters.incoming & timeline_filter & filters.photo)
|
||||||
async def post_photo_command(_: Client, message: Message):
|
async def post_photo_command(_: Client, message: Message):
|
||||||
"""
|
"""
|
||||||
发送新贴或者回复
|
发送新贴或者回复
|
||||||
"""
|
"""
|
||||||
note_id = None
|
note_id = None
|
||||||
if message.reply_to_message and message.reply_to_message.reply_markup:
|
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)
|
@Client.on_callback_query(filters.regex("^send$") & timeline_filter)
|
||||||
async def send_callback(_: Client, callback_query: CallbackQuery):
|
async def send_callback(_: Client, callback_query: CallbackQuery):
|
||||||
"""
|
"""
|
||||||
发送
|
发送
|
||||||
"""
|
"""
|
||||||
msg = callback_query.message
|
msg = callback_query.message
|
||||||
if need_send := ready_send.get((msg.chat.id, msg.id), None):
|
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)
|
@Client.on_callback_query(filters.regex("^delete$") & timeline_filter)
|
||||||
async def delete_callback(_: Client, callback_query: CallbackQuery):
|
async def delete_callback(_: Client, callback_query: CallbackQuery):
|
||||||
"""
|
"""
|
||||||
删除
|
删除
|
||||||
"""
|
"""
|
||||||
if not (need_send := callback_query.message):
|
if not (need_send := callback_query.message):
|
||||||
return await callback_query.answer("按钮已过期", show_alert=True)
|
return await callback_query.answer("按钮已过期", show_alert=True)
|
||||||
|
@ -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
|
||||||
|
|
||||||
@ -12,7 +16,7 @@ from models.filters import notice_filter
|
|||||||
@Client.on_message(filters.incoming & notice_filter & filters.regex(r"^@(.*)$"))
|
@Client.on_message(filters.incoming & notice_filter & filters.regex(r"^@(.*)$"))
|
||||||
async def search_user_command(_: Client, message: Message):
|
async def search_user_command(_: Client, message: Message):
|
||||||
"""
|
"""
|
||||||
搜索用户
|
搜索用户
|
||||||
"""
|
"""
|
||||||
username = message.matches[0].group(1)
|
username = message.matches[0].group(1)
|
||||||
path = username.strip().split("@")
|
path = username.strip().split("@")
|
||||||
@ -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)
|
||||||
|
|
||||||
@ -39,7 +49,7 @@ async def search_user_command(_: Client, message: Message):
|
|||||||
@Client.on_callback_query(filters.regex(r"^follow:(.*)$") & notice_filter)
|
@Client.on_callback_query(filters.regex(r"^follow:(.*)$") & notice_filter)
|
||||||
async def follow_user_callback(_: Client, callback_query: CallbackQuery):
|
async def follow_user_callback(_: Client, callback_query: CallbackQuery):
|
||||||
"""
|
"""
|
||||||
关注/取消关注用户
|
关注/取消关注用户
|
||||||
"""
|
"""
|
||||||
user_id = callback_query.matches[0].group(1)
|
user_id = callback_query.matches[0].group(1)
|
||||||
button = callback_query.message.reply_markup
|
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}"
|
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
|
||||||
"""
|
"""
|
||||||
if len(message.command) == 2:
|
if len(message.command) == 2:
|
||||||
token = message.command[1]
|
token = message.command[1]
|
||||||
@ -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,11 +8,10 @@ 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
|
||||||
"""
|
"""
|
||||||
user = await UserAction.get_user_by_id(message.from_user.id)
|
user = await UserAction.get_user_by_id(message.from_user.id)
|
||||||
if not user:
|
if not user:
|
||||||
|
Loading…
Reference in New Issue
Block a user