{"id":15479300,"url":"https://github.com/niuhuan/mirai-framework","last_synced_at":"2025-07-04T21:07:53.836Z","repository":{"id":43055391,"uuid":"406595392","full_name":"niuhuan/mirai-framework","owner":"niuhuan","description":"一个基于MariGo的QQ机器人框架, 完全插件化的设计, 帮您轻而易举的建立属于自己的机器人, 对其增改插件, 同时保持更为清晰的代码结构。","archived":false,"fork":false,"pushed_at":"2023-06-30T02:26:41.000Z","size":359,"stargazers_count":20,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-22T15:07:12.137Z","etag":null,"topics":["bot","qq","qqbot"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/niuhuan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-15T03:04:48.000Z","updated_at":"2024-04-28T02:14:03.000Z","dependencies_parsed_at":"2024-10-02T04:20:47.931Z","dependency_job_id":"bd489abd-98b2-4632-b79a-ac64f85ae414","html_url":"https://github.com/niuhuan/mirai-framework","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/niuhuan/mirai-framework","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niuhuan%2Fmirai-framework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niuhuan%2Fmirai-framework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niuhuan%2Fmirai-framework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niuhuan%2Fmirai-framework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/niuhuan","download_url":"https://codeload.github.com/niuhuan/mirai-framework/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niuhuan%2Fmirai-framework/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263619808,"owners_count":23489563,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot","qq","qqbot"],"created_at":"2024-10-02T04:20:40.707Z","updated_at":"2025-07-04T21:07:53.819Z","avatar_url":"https://github.com/niuhuan.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"mirai-framework\n=====\n一个基于MariGo的QQ机器人框架, 完全插件化的设计, 帮您轻而易举的建立属于自己的机器人, 对其增改插件, 同时保持更为清晰的代码结构。\n\n# 注意事项\n\n已经跟随MiraiGo升级为Go1.18\n\n# 设计思路\n\n所有的功能都是由插件完成, 事件发生时, 调度器对插件循环调用, 插件响应是否处理该事件, 直至有插件响应事件, 插件发生异常, 或插件轮训结束, 最后日志结果被记录, 事件响应周期结束。\n![img.png](images/invoke.png)\n\n## 插件\n\n- Id 插件的ID\n- Name 插件的名称\n- OnPrivateMessage 收到私聊消息时\n- OnGroupMessage 收到组群消息时\n- OnTempMessage 收到临时消息时\n- OnMessage 收到消息时, 优先级低于明确类型的Message\n- OnNewFriendRequest 收到好友请求时\n- OnNewFriendAdded 添加了好友时\n- OnGroupInvited 收到组群邀请时\n- OnJoinGroup 加入组群时\n- OnLeaveGroup 离开组群时\n\n## 动作监听器\n\n- Id 监听器的ID\n- Name 监听器的名称\n- OnSendPrivateMessage 发送了私聊消息将会执行回调\n- OnSendGroupMessage 发送了组群消息将会执行回调\n- OnSendTempMessage 发送了私聊消息将会执行回调\n\n## 额外的api支持\n\n- func (c *Client) MessageSenderUin 获得消息的发送者, 支持所有类型的消息\n- func (c *Client) MessageElements 获得消息的组成, 支持所有类型的消息\n- func (c *Client) MessageContent 获得消息的内容, 支持所有类型的消息\n- func (c *Client) MessageFirstAt 获得消息中第一个AT的人\n- func (c *Client) CardNameInGroup 获取群名片\n- func (c *Client) MakeReplySendingMessage 创建一个回复消息, 如果是群员则自动带上@\n- func (c *Client) ReplyRawMessage 快捷回复 将消息按照原来的路径发回, 群员将自动带上@\n- func (c *Client) UploadReplyImage 上传图片, 接受人为消息源, 回复图片消息使用\n- func (c *Client) UploadReplyVideo 上传视频, 接受人为消息源, 回复视频消息使用\n- func (c *Client) AtElement 创建一个at\n- func (c *Client) ReplyText 快速回复一个文本消息\n\n## 插件拦截器\n\n**client.SetPluginBlocker()** 可以实现插件拦截, 实现个别群个人启用禁用插件\n\n# 如何使用\n\n## 实现一个插件超级简单\n\n```text\npackage hello\n\nimport \"github.com/niuhuan/mirai-framework\"\n\nfunc PluginInstance() *mirai.Plugin {\n\treturn \u0026mirai.Plugin{\n\t\tId: func() string {\n\t\t\treturn \"HELLO_WORLD\"\n\t\t},\n\t\tName: func() string {\n\t\t\treturn \"你好世界\"\n\t\t},\n\t\tOnMessage: func(client *mirai.Client, messageInterface interface{}) bool {\n\t\t\tcontent := client.MessageContent(messageInterface)\n\t\t\tif content == \"你好\" {\n\t\t\t\tclient.ReplyText(messageInterface, \"世界\")\n\t\t\t\treturn true\n\t\t\t}\n\t\t\treturn false\n\t\t},\n\t}\n}\n```\n\n为什么用 struct 而不是 interface\n\n- interface只需要选择其中几个func实现, 这种场景还是比较少见的\n- 用interface会强制实现所有方法, 你需要实现太多方法了, 如果用embedded-struct将会失去IDE智能的提示\n\n## 启动机器人\n\n```text\n  func main() {\n      // 初始化手机机型等信息\n      config.InitDeviceInfo()\n      // 创建机器人\n      client := mirai.NewClientMd5(Account.Uin, Account.PasswordBytes)\n      // 注册插件\n      client.SetActionListenersAndPlugins(\n          nil,\n          []*mirai.Plugin{\n              hello.PluginInstance(),\n          },\n      )\n      // 登录\n      cmdLogin(client)\n      // 等待退出信号\n\t  ch := make(chan os.Signal)\n\t  signal.Notify(ch, os.Interrupt, os.Kill)\n\t  \u003c-ch\n  }\n```\n\n- [InitDeviceInfo](https://github.com/niuhuan/mirai-bot/blob/master/config/device.go) 从设备读取机型等信息\n- [cmdLogin](https://github.com/niuhuan/mirai-bot/blob/master/login/login.go) 处理登录验证码, 设备锁等功能\n\n# 机器人模版\n\n- [mirai-bot](https://github.com/niuhuan/mirai-bot)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniuhuan%2Fmirai-framework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fniuhuan%2Fmirai-framework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniuhuan%2Fmirai-framework/lists"}