Skip to content

Commit

Permalink
🔖 Pre Release 0.1.0b11
Browse files Browse the repository at this point in the history
  • Loading branch information
j1g5awi committed May 12, 2023
1 parent daa474f commit b254595
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 279 deletions.
25 changes: 23 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.1.0-beta.11] - 2023-05-12

### 🚀 新功能

- 适配 Telegram Bot API 6.7
- Bot.send 新增 `media_group_caption_index` 参数[@lgc2333](https://github.com/lgc2333) ([#31](https://github.com/nonebot/adapter-telegram/pull/31))
- 使用 bytes 发送文件时可自定义文件名 [@lgc2333](https://github.com/lgc2333) ([#31](https://github.com/nonebot/adapter-telegram/pull/31))

### 🐛 Bug 修复

- 更正 `thumb``thumbnail` [@lgc2333](https://github.com/lgc2333) ([#26](https://github.com/nonebot/adapter-telegram/pull/26))
- 不存在 WebHook 模式的 Bot 时不使用服务端型驱动器
- 修复将 `ForumTopicMessageEvent` 错误解析成 `GroupMessageEvent` 的问题
- 修复 `PinnedMessageEvent` 在频道中解析失败的问题 [@lgc2333](https://github.com/lgc2333) ([#30](https://github.com/nonebot/adapter-telegram/pull/30))

### 📝 文档

- 修复下载文件的示例
- 新增@用户的示例 [@applenana](https://github.com/applenana) ([#34](https://github.com/nonebot/adapter-telegram/pull/34))

## [0.1.0-beta.10] - 2023-04-10

### 🚀 新功能
Expand All @@ -22,7 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### 🐛 Bug 修复

修复 Message 处理时的 KeyError
- 修复 Message 处理时的 KeyError

## [0.1.0-beta.8] - 2023-02-10

Expand Down Expand Up @@ -149,7 +169,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- 适配 NoneBot2 2.0.0b1
- 支持多个机器人同时在线

[Unreleased]: https://github.com/nonebot/adapter-telegram/compare/v0.1.0b10...HEAD
[Unreleased]: https://github.com/nonebot/adapter-telegram/compare/v0.1.0b11...HEAD
[0.1.0-beta.11]: https://github.com/nonebot/adapter-telegram/compare/v0.1.0b10...v0.1.0b11
[0.1.0-beta.10]: https://github.com/nonebot/adapter-telegram/compare/v0.1.0b9...v0.1.0b10
[0.1.0-beta.9]: https://github.com/nonebot/adapter-telegram/compare/v0.1.0b8...v0.1.09b
[0.1.0-beta.8]: https://github.com/nonebot/adapter-telegram/compare/v0.1.0b7...v0.1.0b8
Expand Down
70 changes: 21 additions & 49 deletions example/mention.py
Original file line number Diff line number Diff line change
@@ -1,72 +1,44 @@
"""@某个用户的示例"""
"""
@某个用户的示例
# [重构提醒]:该实例涉及的Entity在将会会进行重构,本示例可能会过时
# 所以使用"""~"""来代表可能会过时的注释,请注意分辨
本示例所涉及的 Entity 在将在下个版本重构
"""

from nonebot import on_command
from nonebot.adapters.telegram import Bot
from nonebot.adapters.telegram.message import Entity
from nonebot.adapters.telegram.event import MessageEvent
from nonebot.adapters.telegram.message import Entity, Message

mention = on_command("mention1")


@mention.handle()
async def _(event: MessageEvent):
@on_command("mention1").handle()
async def _(bot: Bot, event: MessageEvent):
user = event.telegram_model.message.from_
# 获取一个User对象,这里采用event获取发送mention命令的用户User对象
# 获取一个 User 对象,这里从 event 获取用户的 User 对象

if user is None:
return
# ChannelPostEvent没有from字段
# ChannelPostEvent 没有 from 字段

username = user.username
# 获取用户名

await mention.send(Entity.mention("@" + username))
"""要注意的是使用Entity.mention必须保证@存在,以及username的正确"""
# [重构提醒]:将来会自动添加@
await bot.send(event, Entity.mention("@" + username))
"""要注意的是使用 Entity.mention 需要该用户有 username"""

await mention.send(
Message(["first part", " ", Entity.mention("@" + username), " ", "second_part"])
await bot.send(
event, "first part " + Entity.mention("@" + username) + " second_part"
)
# 你当然也可以在消息片段发送@某人

"""
还要注意的是Entity.mention不能与其它消息直接相连,要用空格间隔开
如await mention.send(Message(['first_part',Entity.mention("@"+username),'second']))是绝对不允许的!
@前面若存在其他消息,则telegrame不会识别该mention
@后面若有其他消息,则telegrame会将后面的消息也识别为username的一部分
还要注意 Entity.mention 不能与其它消息直接相连,要用空格间隔开
@之前若与其他消息相连,则 Telegram 不会识别其为 mention
@之后若有其他消息相连,则 Telegram 会将后面的消息也识别为 username 的一部分
"""
# [重构提醒]将来会自动加空格


mention2 = on_command("mention2")


@mention2.handle()
async def _(event: MessageEvent):
user = event.telegram_model.message.from_
if user is None:
@on_command("mention2").handle()
async def _(bot: Bot, event: MessageEvent):
if (user := event.telegram_model.message.from_) is None:
return
username = user.username

await mention.send(Entity.text_mention("@" + username, user))
# 你可以使用Entity.text_mention来达到与Entity.mention相近的效果
await mention.send(Entity.text_mention("anytext", user))
# 与mention不同的是,text_mention的文本可以为自己定义,且不影响mention链接

await mention.send(
Message(
[
"first part",
" ",
Entity.text_mention("anytext", user),
" ",
"second_part",
]
)
)
# 使用方法与mention类似
"""也是注意消息不能粘连"""
# [重构提醒]将来会自动加空格
await bot.send(event, Entity.text_mention("anytext", user))
# 与 mention 不同的是,text_mention 的文本可以自定义
Loading

0 comments on commit b254595

Please sign in to comment.