Skip to main content

NoneBot 暗语

Project description

NoneBot-Plugin-Argot

✨ NoneBot2 暗语消息 ✨

pypi python pdm-managed alc-resolved
NoneBot Registry Supported Adapters
📸 演示与预览   |   📦️ 下载插件   |   💬 加入交流群

📖 介绍

NoneBot2 暗语消息支持

[!IMPORTANT] 收藏项目,你将从 GitHub 上无延迟地接收所有发布通知~⭐️

starify
Star History

💿 安装

以下提到的方法任选 其一 即可

[推荐] 使用 nb-cli 安装 在 Bot 的根目录下打开命令行, 输入以下指令即可安装
nb plugin install nonebot-plugin-argot
使用包管理器安装
pip install nonebot-plugin-argot
# or, use poetry
poetry add nonebot-plugin-argot
# or, use pdm
pdm add nonebot-plugin-argot
# or, use uv
uv add nonebot-plugin-argot

🎉 使用

本插件基于 plugin-alconna,为 NoneBot 提供了一个新的消息段 Argot

@dataclass
class Argot(Segment):
    name: str
    segment: str | Segment | list[Segment]
    command: str | Literal[False] | None = field(default=None, kw_only=True)
    expired_at: int | timedelta = field(default_factory=timedelta, kw_only=True)
  • name: 暗语名称
  • segment: 暗语包含的消息段
  • command: 触发暗语的指令(跟随 COMMAND_START 配置)
    • None: 使用 name 作为指令名
    • False: 禁止通过指令获取暗语
  • expired_at: 过期时间
示例
  1. NoneBot Matcher + Matcher.send

    from nonebot_plugin_argot import add_argot, get_message_id
    
    @on_command("cmd").handle()
    async def _():
        await cmd.send(
            "This is a text message. Reply /background to get background image.",
            argot={
                "name": "background",
                "command": "background",
                "segment": Image(url="https://koishi.chat/logo.png"),
                "expired_at": 60
            }
        )
    
  2. NoneBot Matcher + UniMessage.send

    from nonebot import on_command
    from nonebot_plugin_alconna.uniseg import Text, Image, UniMessage
    from nonebot_plugin_argot.extension import ArgotExtension, ArgotSendWrapper, current_send_wrapper
    
    cmd = on_command("cmd")
    
    @cmd.handle()
    async def _():
    path: Path = Path(__file__).parent / "image.png"
    
    with current_send_wrapper.use(ArgotSendWrapper()):
        await UniMessage(
          [
              Text("This is a text message. Reply /image to get image."),
              Argot("image", [Text("image"), Image(path=path)]),
          ]
        ).send()
    
  3. Alconna Matcher + UniMessage.send

    from nonebot_plugin_alconna import Command
    from nonebot_plugin_alconna.uniseg import Text, Image, UniMessage
    from nonebot_plugin_argot.extension import ArgotExtension, ArgotSendWrapper, current_send_wrapper
    
    cmd = Command("cmd").build(use_cmd_start=True, extensions=[ArgotExtension()])
    
    @cmd.handle()
    async def _():
        path: Path = Path(__file__).parent / "image.png"
        await UniMessage(
            [
                Text("This is a text message. Reply /image to get image."),
                Argot("image", [Text("image"), Image(path=path)]),
            ]
        ).send()
    
  4. 手动添加

    from nonebot_plugin_argot import add_argot, get_message_id
    
    @on_command("cmd").handle()
    async def _():
        message = await cmd2.send("This is a text message. Reply /background to get background image.")
        await add_argot(
            message_id=get_message_id(message) or "",
            name="background",
            segment=Image(url="https://koishi.chat/logo.png"),
            expired_at=timedelta(minutes=2),
        )
    

获取暗语有以下几种方式:

  • 使用设置的 command 回复附带暗语的消息
  • 通过 get_argot 函数
  • 超管回复暗语消息 /argot [name]

📸 效果图

rendering

💖 鸣谢

贡献者们

contributors sponsors

感谢这些大佬对本项目作出的贡献:

contributors

📄 许可证

本项目使用 MIT 许可证开源

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nonebot_plugin_argot-0.1.7.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nonebot_plugin_argot-0.1.7-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file nonebot_plugin_argot-0.1.7.tar.gz.

File metadata

  • Download URL: nonebot_plugin_argot-0.1.7.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for nonebot_plugin_argot-0.1.7.tar.gz
Algorithm Hash digest
SHA256 f76c2139c9af1e2de6efdc487b728fbad84737d272bf1f600d085bbe6ed79094
MD5 d052aaf516feb42af2ec1c64a5cafbda
BLAKE2b-256 d97789e9b923d044dc4dee6f1fb0906a6d1b5239f7bcd243c25fea0de09bf410

See more details on using hashes here.

File details

Details for the file nonebot_plugin_argot-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for nonebot_plugin_argot-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1af939a60967e27aff6f7ce97150d26cba8f1ef0cf216b44372cc0d8e5937204
MD5 03be3c4c499a81789c945343b9a29b4e
BLAKE2b-256 7add210d00aedf9870644581029b83f2818ea7d891a6888238890fdfb47bf418

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page