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 30, 2023
1 parent 8eb4ed9 commit b8b82ce
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 16 deletions.
56 changes: 42 additions & 14 deletions plugins/QQChannelPlugin/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,56 @@ public async Task<ActionResult> Login()
SettingsModel settingsModel = PluginCore.PluginSettingsModelFactory.Create<SettingsModel>(nameof(QQChannelPlugin));
// 确保以前的都取消
#region 确保以前的都取消
foreach (var item in QQChannelBotStore.Bots)
if (QQChannelBotStore.Bots != null && QQChannelBotStore.Bots.Count >= 1) {
foreach (var item in QQChannelBotStore.Bots)
{
try
{
await item.ChannelBot.OfflineAsync();
}
catch (Exception ex)
{ }
try
{
await item.ChannelBot.CloseAsync();
}
catch (Exception ex)
{ }
try
{
item.ChannelBot = null;
}
catch (Exception ex)
{ }
try
{
item.OpenApiAccessInfo = new OpenApiAccessInfo();
}
catch (Exception ex)
{ }
try
{
item.QQChannelApi = null;
}
catch (Exception ex)
{ }
}
QQChannelBotStore.Bots.Clear();
}
#endregion

foreach (var botConfig in settingsModel.Bots)
{
try
{
await item.ChannelBot.OfflineAsync();
await item.ChannelBot.CloseAsync();
item.ChannelBot = null;
item.OpenApiAccessInfo = new OpenApiAccessInfo();
item.QQChannelApi = null;
ChannelBotItem(botConfig, settingsModel);
}
catch (Exception ex)
{

System.Console.WriteLine($"{botConfig.BotAppId} 登录失败");
System.Console.WriteLine(ex.ToString());
}
}
QQChannelBotStore.Bots.Clear();

#endregion
foreach (var botConfig in settingsModel.Bots)
{
ChannelBotItem(botConfig, settingsModel);
}

// TODO: 暂时这么做, 以后优化界面
return Content("尝试登录 设置 里的QQ频道机器人中, 请耐性等待! 看到此页面可能已上线/登录中");
Expand Down
2 changes: 1 addition & 1 deletion plugins/QQChannelPlugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@
> 本项目基于 [Chianne1025/QQChannelFramework: MyBot - QQ频道机器人开发框架(C#)](https://github.com/Chianne1025/QQChannelFramework)
<!-- Matomo Image Tracker-->
<img referrerpolicy="no-referrer-when-downgrade" src="https://matomo.moeci.com/matomo.php?idsite=2&amp;rec=1&amp;action_name=Plugins.QQChannelPlugin-v0.1.4.README" style="border:0" alt="" />
<img referrerpolicy="no-referrer-when-downgrade" src="https://matomo.moeci.com/matomo.php?idsite=2&amp;rec=1&amp;action_name=Plugins.QQChannelPlugin-v0.1.5.README" style="border:0" alt="" />
<!-- End Matomo -->
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.4",
"Version": "0.1.5",
"SupportedVersions": [ "0.0.1" ]
}

0 comments on commit b8b82ce

Please sign in to comment.