Skip to content

Commit

Permalink
✏️ fix many typos
Browse files Browse the repository at this point in the history
  • Loading branch information
j1g5awi committed Feb 15, 2024
1 parent 019314b commit 7ec67f0
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 50 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/pyright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Pyright Lint

on:
push:
branches:
- beta
pull_request:
paths:
- "nonebot/**"
- "tests/**"
- ".github/actions/setup-python/**"
- ".github/workflows/pyright.yml"
- "pyproject.toml"
- "pdm.lock"

jobs:
pyright:
name: Pyright Lint
runs-on: ubuntu-latest
concurrency:
group: pyright-${{ github.ref }}
cancel-in-progress: true
strategy:
fail-fast: false

steps:
- uses: actions/checkout@v4

- name: Setup Python environment
uses: ./.github/actions/setup-python
with:
no-root: true

- name: Install dependencies
run: pdm install -G tests -G nonebot

- name: Run Pyright
uses: jakebailey/pyright-action@v2
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- 支持多个机器人同时在线

[Unreleased]: https://github.com/nonebot/adapter-telegram/compare/v0.1.0b16...HEAD
[0.1.0-beta.15]: https://github.com/nonebot/adapter-telegram/compare/v0.1.0b15...v0.1.0b16
[0.1.0-beta.16]: https://github.com/nonebot/adapter-telegram/compare/v0.1.0b15...v0.1.0b16
[0.1.0-beta.15]: https://github.com/nonebot/adapter-telegram/compare/v0.1.0b14...v0.1.0b15
[0.1.0-beta.14]: https://github.com/nonebot/adapter-telegram/compare/v0.1.0b13...v0.1.0b14
[0.1.0-beta.13]: https://github.com/nonebot/adapter-telegram/compare/v0.1.0b12...v0.1.0b13
Expand Down
52 changes: 22 additions & 30 deletions example/inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,6 @@
)


@on_command("inline").handle()
async def _(bot: Bot, event: MessageEvent):
await bot.send(
event,
"Hello InlineKeyboard !",
reply_markup=InlineKeyboardMarkup(
inline_keyboard=[
[
InlineKeyboardButton(
text="Nonebot Adapter Telegram",
url="https://github.com/nonebot/adapter-telegram",
)
],
[
InlineKeyboardButton(
text="Telegram Bot API",
url="https://core.telegram.org/bots/api",
)
],
[
InlineKeyboardButton(
text="Say hello to me",
callback_data="hello",
)
],
]
),
)


@on("inline").handle()

Check failure on line 20 in example/inline.py

View workflow job for this annotation

GitHub Actions / Pyright Lint

Expression form not supported for decorator prior to Python 3.9
async def _(bot: Bot, event: InlineQueryEvent):
await bot.answer_inline_query(
Expand All @@ -58,6 +28,28 @@ async def _(bot: Bot, event: InlineQueryEvent):
input_message_content=InputTextMessageContent(
message_text="Hello InlineQuery !"
),
reply_markup=InlineKeyboardMarkup(
inline_keyboard=[
[
InlineKeyboardButton(
text="Nonebot Adapter Telegram",
url="https://github.com/nonebot/adapter-telegram",
)
],
[
InlineKeyboardButton(
text="Telegram Bot API",
url="https://core.telegram.org/bots/api",
)
],
[
InlineKeyboardButton(
text="Say hello to me",
callback_data="hello",
)
],
]
),
),
],
)
Expand Down
2 changes: 1 addition & 1 deletion nonebot/adapters/telegram/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ async def process_input_file(file: Union[InputFile, str]) -> Optional[str]:
media.media = f"attach://{filename}"
# 对修改消息媒体消息的处理
elif api == "editMessageMedia":
media: Iterable[InputMedia] = data["media"]
media: InputMedia = data["media"]
filename = await process_input_file(media.media)
if filename:
media.media = f"attach://{filename}"
Expand Down
36 changes: 23 additions & 13 deletions nonebot/adapters/telegram/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def __build_entities_form_msg(
(
[
MessageEntity(
type=entity.type,
type=entity.type, # type: ignore
offset=sum(map(len, message[:i])),
length=len(entity.data["text"]),
url=entity.data.get("url"),
Expand Down Expand Up @@ -171,7 +171,7 @@ async def send_to(

# 单个 segment
if isinstance(message, MessageSegment):
if message.is_text():
if isinstance(message, Entity):
return await self.send_message(
chat_id=chat_id,
message_thread_id=message_thread_id,
Expand Down Expand Up @@ -206,21 +206,31 @@ async def send_to(
reply_parameters = ReplyParameters(**message["reply", 0].data)
message = message.exclude("reply")

entities = Message(x for x in message if isinstance(x, Entity))
files = Message(
entities = [x for x in message if isinstance(x, Entity)]
files = [
x
for x in message
if isinstance(x, File) and not isinstance(message, UnCombinFile)
)
others = Message(
if isinstance(x, File) and not isinstance(x, UnCombinFile)
]
others = [
x
for x in message
if not (isinstance(x, (Entity, File))) or isinstance(message, UnCombinFile)
)

# 如果只能单独发送的消息段和其他消息段在一起,那么抛出错误
if others and (len(others) > 1 or files or entities):
raise ApiNotAvailable
if not (isinstance(x, (Entity, File))) or isinstance(x, UnCombinFile)
]

if others:
# 如果只能单独发送的消息段和其他消息段在一起,那么抛出错误
if len(others) > 1 or files or entities:
raise ApiNotAvailable
other = others[0]
return await self.call_api(
f"send_{other.type}",
chat_id=chat_id,
message_thread_id=message_thread_id,
**other.data,
reply_parameters=reply_parameters,
**kwargs,
)

# 发送纯文本消息
if not files:
Expand Down
2 changes: 2 additions & 0 deletions nonebot/adapters/telegram/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,8 @@ def get_event_description(self) -> str:


class CallbackQueryEvent(InlineEvent, CallbackQuery):
chat: Chat = Field(default=None)

@overrides(Event)
def get_event_name(self) -> str:
return "inline.callback_query"
Expand Down
6 changes: 1 addition & 5 deletions nonebot/adapters/telegram/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def poll(question: str, options: List[str]) -> "MessageSegment":
def dice(
emoji: Literal["🎲", "🎯", "🏀", "⚽", "🎳", "🎰"] = "🎲"
) -> "MessageSegment":
return MessageSegment("dice", {"question": emoji})
return MessageSegment("dice", {"emoji": emoji})

@staticmethod
def chat_action(
Expand Down Expand Up @@ -109,10 +109,6 @@ def game(game_short_name: str):


class Reply(MessageSegment):
@overrides(BaseMessageSegment)
def is_text(self) -> bool:
return False

@staticmethod
def reply(message_id: int, chat_id: Optional[Union[int, str]] = None, **kargs):
return Reply("reply", {"message_id": message_id, "chat_id": chat_id, **kargs})
Expand Down

0 comments on commit 7ec67f0

Please sign in to comment.