Skip to content

Commit

Permalink
fix(plugins/qqchannelplugin/): 缺少的事件注册
Browse files Browse the repository at this point in the history
  • Loading branch information
yiyungent committed Jan 29, 2023
1 parent 395651c commit 41ac650
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 4 deletions.
33 changes: 30 additions & 3 deletions plugins/QQChannelPlugin/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,24 @@ public async Task<ActionResult> Login()
}

// TODO: 暂时这么做, 以后优化界面
return Content("尝试登录 设置 里的 QQ频道机器人中, 请耐性等待! 注意查看控制台!");
return Content("尝试登录 设置 里的QQ频道机器人中, 请耐性等待! 看到此页面可能已上线/登录中");
}

private async void ChannelBotItem(SettingsModel.BotDevItemModel botConfig, SettingsModel settings)
[NonAction]
public async void ChannelBotItem(SettingsModel.BotDevItemModel botConfig, SettingsModel settings)
{
// https://www.yuque.com/chianne1025/mybot/otkzzg

// 声明鉴权信息
#region OpenApiAccessInfo
OpenApiAccessInfo openApiAccessInfo = new OpenApiAccessInfo();
openApiAccessInfo.BotAppId = botConfig.BotAppId;
openApiAccessInfo.BotToken = botConfig.BotToken;
openApiAccessInfo.BotSecret = botConfig.BotSecret;
#endregion

// 使用QQChannelApi获取相应的Api接口
#region QQChannelApi
// 鉴权信息在实例化时传入
QQChannelApi qChannelApi = new(openApiAccessInfo);

Expand All @@ -121,13 +125,34 @@ private async void ChannelBotItem(SettingsModel.BotDevItemModel botConfig, Setti
// 不指定的情况下默认是正式模式
//qChannelApi.UseReleaseMode();
}
#endregion

// 实例化一个 ChannelBot,该类是一个容易理解且简单的类
#region ChannelBot
// 帮助你快速实现一个利于理解学习与开发的机器人原型
// 将鉴权信息 (openApiAccessInfo) 传入构造函数
ChannelBot channelBot = new(qChannelApi);
// 注册接受@机器人消息时间,否则无法收到消息
channelBot.RegisterAtMessageEvent();
//channelBot.RegisterAtMessageEvent();
channelBot.RegisterGuildsEvent() // 订阅 主频道相关事件
.RegisterGuildMembersEvent() // 订阅 频道成员相关事件
.RegisterAtMessageEvent() // 订阅 @机器人的消息事件
.RegisterUserMessageEvent() // 订阅 无需@机器人的消息事件
.RegisterAudioActionEvent() // 订阅 音频机器人相关事件
.RegisterForumEvent(); // 订阅 论坛相关事件

if (botConfig.UsePrivateBot)
{
channelBot.UsePrivateBot();
}
if (botConfig.EnableUserMessageTriggerCommand)
{
channelBot.EnableUserMessageTriggerCommand();
}
else
{
channelBot.CloseUserMessageTriggerCommand();
}

#region 事件

Expand Down Expand Up @@ -231,6 +256,8 @@ await qChannelApi
}
};

#endregion

#endregion

// 保存起来
Expand Down
21 changes: 21 additions & 0 deletions plugins/QQChannelPlugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,35 @@

> 本项目为 QQ频道 基础插件, 可通过依赖本插件开发相关插件

## 设置

> 可配置多个机器人, 当然不需要那么多, 可删除, 只留一个
```json
"UseSandBoxMode": true,
"UsePrivateBot": true,
"EnableUserMessageTriggerCommand": true,
"UseDemoModel": true
```

> `UseSandBoxMode`: true
> 指定Api通道模式为沙盒模式 (测试时使用), 不指定的情况下默认是正式模式
> `UsePrivateBot`: true
> 指定为私域机器人
> 在想要使用一些私域机器人功能时,需要通过以下方法指定机器人为私域,否则无法正常使用。
> 例如: 无需 @机器人 可收到频道内用户消息
> `EnableUserMessageTriggerCommand`: true
> 启用无须@ 触发指令功能 (私域机器人可用)
> 启用后,频道内触发机器人指令 无需 @机器人
> `UseDemoModel`: true
> 当开启 `UseDemoModel` 时, 可在机器人加入的频道内 `@机器人` , 它会自动回复, 此项功能用于测试


## 登录

- [点击访问即可尝试登录, 注意查看控制台信息](/Plugins/QQChannelPlugin/Login)
Expand Down
15 changes: 15 additions & 0 deletions plugins/QQChannelPlugin/SettingsModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ public sealed class BotDevItemModel
/// </summary>
public bool UseSandBoxMode { get; set; }

/// <summary>
/// 指定为私域机器人
/// https://www.yuque.com/chianne1025/mybot/rexa9h
/// 在想要使用一些私域机器人功能时,需要通过以下方法指定机器人为私域,否则无法正常使用。
/// 例如: 无需 @机器人 可收到频道内用户消息
/// </summary>
public bool UsePrivateBot { get; set; }

/// <summary>
/// 启用无须@ 触发指令功能 (私域机器人可用)
/// https://www.yuque.com/chianne1025/mybot/rexa9h
/// 启用后,频道内触发机器人指令 无需 @机器人
/// </summary>
public bool EnableUserMessageTriggerCommand { get; set; }

/// <summary>
/// 使用 演示 模式, 方便测试/体验
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion plugins/QQChannelPlugin/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"DisplayName": "QQ频道插件",
"Description": "QQ频道基础插件",
"Author": "yiyun",
"Version": "0.1.1",
"Version": "0.1.2",
"SupportedVersions": [ "0.0.1" ]
}
4 changes: 4 additions & 0 deletions plugins/QQChannelPlugin/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
"BotToken": "",
"BotSecret": "",
"UseSandBoxMode": true,
"UsePrivateBot": true,
"EnableUserMessageTriggerCommand": true,
"UseDemoModel": true
},
{
"BotAppId": "",
"BotToken": "",
"BotSecret": "",
"UseSandBoxMode": true,
"UsePrivateBot": true,
"EnableUserMessageTriggerCommand": true,
"UseDemoModel": true
}
]
Expand Down

0 comments on commit 41ac650

Please sign in to comment.