Skip to main content

A Python SDK for heychat (黑盒语音)

Project description

heychat.py

Python SDK for HeyChat

pypi version GitHub last commit khl server github stars khl server

安装

pip install heychat

最简示例

from heychat import Bot, Message

bot = Bot('your_token')

@bot.command('hello')
async def hello(msg: Message):
    await msg.reply('world!')

bot.run()

更多功能

✅ 命令参数处理
from heychat import Bot, Message
from random import randint

bot = Bot('your_token')

@bot.command('roll')
async def hello(msg: Message,max_num):
    # 需先前往小黑盒开发平台为注册指令添加变量
    # 如果没有添加变量单纯输入 /roll 100 也可解析
    max_num = int(max_num)
    await msg.reply(f"你掷出了{randint(1,max_num)}")

bot.run()
✅ 获取基础信息
from heychat import Bot, Message

bot = Bot('your_token')

@bot.on_message()
async def on_message(msg: Message):
    # 用户
    print(msg.author.username) # 用户名
    print(msg.author.nickname) # 房间昵称
    print(msg.author.id)       # 用户ID

    # 消息
    print(msg.content)         # 消息内容
    print(msg.msg_timestamp)   # 消息时间戳
    
    # 房间
    print(msg.ctx.guild.id)    # 房间ID
    print(msg.ctx.guild.name)  # 房间名
    
    # 频道
    print(msg.ctx.channel.id)  # 频道ID
    print(msg.ctx.channel.name)# 频道名
    

bot.run()
✅ MD构建
import MDMessage
@bot.on_message()
async def on_message(msg: Message):

    img_path = "./img.png"
    await upload_img(img_path)

    md_msg = MDMessage()
    md_msg.apeend("这是一段文字")
    md_msg.append(Element.TEXT("这也是一段文字"))
    md_msg.append(Element.MENTION("18661718")) # @
    md_msg.append(Element.IMG("https://chat.max-c.com/attachments/2024-09-15/1835322670233686016_UitVbhhcLf.jpg"))

    # or
    
    md_msg = MDMessage("这是一段文字\n",
                        Element.TEXT("这也是一段文字"),
                        Element.IMG("https://chat.max-c.com/attachments/2024-09-15/1835322670233686016_UitVbhhcLf.jpg"),
                        Element.MENTION("18661718"))
    

    await msg.reply(md_msg)
✅ 支持更多指令变量类型
已经看了,觉得不需要适配现在的够用了,如果有具体需求欢迎提出
✅ 从type5转移至type50
(划掉)等什么时候官方把type5删了再写(划掉)已经写了
✅ 事件处理
from heychat import Bot, EventTypes, GuildMemberEvent
@bot.on_event(EventTypes.JOINED_GUILD)
async def on_joined_guild(e: GuildMemberEvent):
    print(f"{e.user.username}加入了{e.guild.name}")
❌ 日志

贡献

欢迎大家提供建议以及pr!

写在最后的省流

抄的khl.py

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

heychat-0.0.4.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

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

heychat-0.0.4-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file heychat-0.0.4.tar.gz.

File metadata

  • Download URL: heychat-0.0.4.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for heychat-0.0.4.tar.gz
Algorithm Hash digest
SHA256 d105250945b1357ea51e64be4fef2f70a5be70d351b6e2b67a58fc52aea2bb01
MD5 117c936266bb44f0c5db6a80ab08c614
BLAKE2b-256 3491f817eaaa1635da46f8112b15f3aacdf949951207b3ee3997babd0263cf8c

See more details on using hashes here.

File details

Details for the file heychat-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: heychat-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 20.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for heychat-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8eda87f3c0c2d5f81d49570908d0b114adbf3d9715145951beb8e6d7cd4828c1
MD5 a3f70269bd5a973e34cc66bcbfdff107
BLAKE2b-256 8f48ceae09ce18056da692dbb79fb8efed3ccf091ab60e92384d9e1a88881577

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