-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
509 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using PluginCore; | ||
|
||
namespace MoLiPlugin.Controllers | ||
{ | ||
/// <summary> | ||
/// 其实也可以不写这个, 直接访问 Plugins/QQStatPlugin/index.html | ||
/// | ||
/// 下面的方法, 是去掉 index.html | ||
/// | ||
/// 若 wwwroot 下有其它需要访问的文件, 如何 css, js, 而你又不想每次新增 action 指定返回, 则 Route 必须 Plugins/{PluginId}, | ||
/// 这样访问 Plugins/HelloWorldPlugin/css/main.css 就会访问到你插件下的 wwwroot/css/main.css | ||
/// </summary> | ||
[Route($"Plugins/{(nameof(MoLiPlugin))}")] | ||
public class HomeController : Controller | ||
{ | ||
public async Task<ActionResult> Get() | ||
{ | ||
string indexFilePath = System.IO.Path.Combine(PluginPathProvider.PluginWwwRootDir(nameof(MoLiPlugin)), "index.html"); | ||
|
||
return PhysicalFile(indexFilePath, "text/html"); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using PluginCore.IPlugins; | ||
using Konata.Core; | ||
using Konata.Core.Events.Model; | ||
using Konata.Core.Interfaces.Api; | ||
using QQBotHub.Sdk.IPlugins; | ||
using MoLiPlugin.Utils; | ||
|
||
namespace MoLiPlugin | ||
{ | ||
public class MoLiPlugin : BasePlugin, IQQBotPlugin | ||
{ | ||
public override (bool IsSuccess, string Message) AfterEnable() | ||
{ | ||
Console.WriteLine($"{nameof(MoLiPlugin)}: {nameof(AfterEnable)}"); | ||
return base.AfterEnable(); | ||
} | ||
|
||
public override (bool IsSuccess, string Message) BeforeDisable() | ||
{ | ||
Console.WriteLine($"{nameof(MoLiPlugin)}: {nameof(BeforeDisable)}"); | ||
return base.BeforeDisable(); | ||
} | ||
|
||
#region QQBot | ||
public void OnGroupMessage((Bot s, GroupMessageEvent e) obj, string message, string groupName, uint groupUin, uint memberUin) | ||
{ | ||
SettingsModel settingsModel = PluginCore.PluginSettingsModelFactory.Create<SettingsModel>(nameof(MoLiPlugin)); | ||
|
||
Console.WriteLine($"茉莉: 来自: {groupUin}-{memberUin}"); | ||
if (settingsModel.AllowGroup != null && settingsModel.AllowGroup.Count >= 1 && settingsModel.AllowGroup.Contains(groupUin.ToString())) | ||
{ | ||
Console.WriteLine("茉莉准备回复: "); | ||
MoLiApiResponseModel resModel = new MoLiApiResponseModel(); | ||
try | ||
{ | ||
resModel = Utils.MoLiApiUtil.Reply(new MoLiApiRequestModel | ||
{ | ||
content = message, | ||
type = "2", | ||
from = memberUin.ToString(), | ||
fromName = obj.e.Message.Sender.Name, | ||
to = groupUin.ToString(), | ||
toName = groupName | ||
}); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine("茉莉回复出错: "); | ||
Console.WriteLine(ex.ToString()); | ||
} | ||
|
||
if (resModel != null && resModel.code == "00000") | ||
{ | ||
if (resModel.data != null && resModel.data.Count >= 1) | ||
{ | ||
foreach (var item in resModel.data) | ||
{ | ||
obj.s.SendGroupMessage(groupUin: groupUin, message: item.content); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
public void OnFriendMessage((Bot s, FriendMessageEvent e) obj, string message, uint friendUin) | ||
{ | ||
SettingsModel settingsModel = PluginCore.PluginSettingsModelFactory.Create<SettingsModel>(nameof(MoLiPlugin)); | ||
|
||
Console.WriteLine($"茉莉: 来自: {friendUin}"); | ||
if (settingsModel.AllowFriends != null && settingsModel.AllowFriends.Count >= 1 && settingsModel.AllowFriends.Contains(friendUin.ToString())) | ||
{ | ||
Console.WriteLine("茉莉准备回复: "); | ||
MoLiApiResponseModel resModel = new MoLiApiResponseModel(); | ||
try | ||
{ | ||
resModel = Utils.MoLiApiUtil.Reply(new MoLiApiRequestModel | ||
{ | ||
content = message, | ||
type = "1", | ||
from = friendUin.ToString(), | ||
fromName = obj.e.Message.Sender.Name, | ||
to = "", | ||
toName = "" | ||
}); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine("茉莉回复出错: "); | ||
Console.WriteLine(ex.ToString()); | ||
} | ||
|
||
if (resModel != null && resModel.code == "00000") | ||
{ | ||
if (resModel.data != null && resModel.data.Count >= 1) | ||
{ | ||
foreach (var item in resModel.data) | ||
{ | ||
obj.s.SendFriendMessage(friendUin: friendUin, message: item.content); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
public void OnBotOnline((Bot s, BotOnlineEvent e) obj, string botName, uint botUin) | ||
{ | ||
//SettingsModel settingsModel = PluginCore.PluginSettingsModelFactory.Create<SettingsModel>(nameof(QQStatPlugin)); | ||
|
||
//if (settingsModel != null && !string.IsNullOrEmpty(settingsModel.AdminQQ)) | ||
//{ | ||
// obj.s.SendFriendMessage(Convert.ToUInt32(settingsModel.AdminQQ), $"{obj.s.Name}({obj.s.Uin}) 上线啦"); | ||
//} | ||
} | ||
|
||
public void OnBotOffline((Bot s, BotOfflineEvent e) obj, string botName, uint botUin) | ||
{ | ||
//SettingsModel settingsModel = PluginCore.PluginSettingsModelFactory.Create<SettingsModel>(nameof(QQStatPlugin)); | ||
|
||
//if (settingsModel != null && !string.IsNullOrEmpty(settingsModel.AdminQQ)) | ||
//{ | ||
// obj.s.SendFriendMessage(Convert.ToUInt32(settingsModel.AdminQQ), $"{obj.s.Name}({obj.s.Uin}) 离线啦"); | ||
//} | ||
} | ||
#endregion | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<EnableDynamicLoading>true</EnableDynamicLoading> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0"> | ||
<ExcludeAssets>runtime</ExcludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> | ||
<!--<PackageReference Include="SqlSugarCore" Version="5.0.7.3"> | ||
<ExcludeAssets>runtime</ExcludeAssets> | ||
</PackageReference>--> | ||
<!--<PackageReference Include="SqlSugarCore" Version="5.0.7.3" />--> | ||
<!--<PackageReference Include="SqlSugarCoreNoDrive" Version="5.0.7.3" />--> | ||
</ItemGroup> | ||
|
||
<!-- 方便开发debug,与发布到nuget --> | ||
<ItemGroup Condition="'$(Configuration)' == 'Release'"> | ||
<PackageReference Include="QQBotHub.Sdk" Version="0.0.1"> | ||
<ExcludeAssets>runtime</ExcludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
<ItemGroup Condition="'$(Configuration)' == 'Debug'"> | ||
<ProjectReference Include="..\..\src\QQBotHub.Sdk\QQBotHub.Sdk.csproj"> | ||
<Private>false</Private> | ||
<ExcludeAssets>runtime</ExcludeAssets> | ||
</ProjectReference> | ||
</ItemGroup> | ||
|
||
<!-- 发布插件相关文件 --> | ||
<ItemGroup> | ||
<Content Include="info.json"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</Content> | ||
<Content Include="README.md"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</Content> | ||
<Content Include="settings.json"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
|
||
<!-- 发布 wwwroot --> | ||
<ItemGroup> | ||
<Content Include="wwwroot\**\*"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
|
||
|
||
|
||
|
||
## 使用 | ||
|
||
|
||
前往 [https://mly.app](https://mly.app) 注册, 创建机器人, 获取 `ApiKey` 以及 `ApiSecret` 填入设置, 然后启用 | ||
|
||
|
||
|
||
|
||
|
||
## 前端视图 | ||
|
||
- [/Plugins/MoLiPlugin](/Plugins/MoLiPlugin) | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Text; | ||
using PluginCore.Models; | ||
|
||
namespace MoLiPlugin | ||
{ | ||
public class SettingsModel : PluginSettingsModel | ||
{ | ||
public string ApiKey { get; set; } | ||
|
||
public string ApiSecret { get; set; } | ||
|
||
public List<string> AllowGroup { get; set; } | ||
|
||
public List<string> AllowFriends { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using System; | ||
|
||
namespace MoLiPlugin.Utils | ||
{ | ||
/// <summary> | ||
/// JavaScript时间戳:是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总毫秒数。(13 位数字) | ||
/// | ||
/// Unix时间戳:是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。(10 位数字) | ||
/// </summary> | ||
public static class DateTimeUtil | ||
{ | ||
public static DateTime DateTime1970 = new DateTime(1970, 1, 1).ToLocalTime(); | ||
|
||
#region Unix 10位时间戳-总秒数 | ||
/// <summary> | ||
/// C# DateTime转换为Unix时间戳 | ||
/// </summary> | ||
public static long ToTimeStamp10(this DateTime dateTime) | ||
{ | ||
// 相差秒数 | ||
long timeStamp = (long)(dateTime.ToLocalTime() - DateTime1970).TotalSeconds; | ||
|
||
return timeStamp; | ||
} | ||
|
||
/// <summary> | ||
/// C# DateTime转换为Unix时间戳 | ||
/// </summary> | ||
public static long ToTimeStamp10(this DateTime? dateTime) | ||
{ | ||
if (dateTime == null) | ||
{ | ||
return 0; | ||
} | ||
// 相差秒数 | ||
long timeStamp = ToTimeStamp10((DateTime)dateTime); | ||
|
||
return timeStamp; | ||
} | ||
|
||
/// <summary> | ||
/// Unix时间戳转换为C# DateTime | ||
/// </summary> | ||
public static DateTime ToDateTime10(this long timeStamp10) | ||
{ | ||
DateTime dateTime = DateTime1970.AddSeconds(timeStamp10).ToLocalTime(); | ||
|
||
return dateTime; | ||
} | ||
#endregion | ||
|
||
#region JavaScript 13位时间戳-总毫秒数 | ||
/// <summary> | ||
/// C# DateTime转换为JavaScript时间戳 | ||
/// </summary> | ||
public static long ToTimeStamp13(this DateTime dateTime) | ||
{ | ||
// 相差毫秒数 | ||
long timeStamp = (long)(dateTime.ToLocalTime() - DateTime1970).TotalMilliseconds; | ||
|
||
return timeStamp; | ||
} | ||
|
||
/// <summary> | ||
/// C# DateTime转换为JavaScript时间戳 | ||
/// </summary> | ||
public static long ToTimeStamp13(this DateTime? dateTime) | ||
{ | ||
if (dateTime == null) | ||
{ | ||
return 0; | ||
} | ||
// 相差秒数 | ||
long timeStamp = ToTimeStamp13((DateTime)dateTime); | ||
|
||
return timeStamp; | ||
} | ||
|
||
/// <summary> | ||
/// JavaScript时间戳转换为C# DateTime | ||
/// </summary> | ||
public static DateTime ToDateTime13(this long timeStamp13) | ||
{ | ||
DateTime dateTime = DateTime1970.AddMilliseconds(timeStamp13).ToLocalTime(); | ||
|
||
return dateTime; | ||
} | ||
#endregion | ||
|
||
#region 获取当前Unix时间戳 | ||
public static long NowTimeStamp10() | ||
{ | ||
return ToTimeStamp10(DateTime.Now); | ||
} | ||
#endregion | ||
|
||
#region 获取当前JavaScript时间戳 | ||
public static long NowTimeStamp13() | ||
{ | ||
return ToTimeStamp13(DateTime.Now); | ||
} | ||
#endregion | ||
} | ||
} |
Oops, something went wrong.