Skip to content

Commit

Permalink
fix(plugins/moliplugin/): 获取完整文本消息
Browse files Browse the repository at this point in the history
  • Loading branch information
yiyungent committed Jun 4, 2022
1 parent d8c1d84 commit c5683f3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
47 changes: 45 additions & 2 deletions plugins/MoLiPlugin/MoLiPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using MoLiPlugin.Utils;
using Konata.Core.Message;
using Konata.Core.Message.Model;
using System.Text;

namespace MoLiPlugin
{
Expand Down Expand Up @@ -50,9 +51,10 @@ public void OnGroupMessage((Bot s, GroupMessageEvent e) obj, string message, str
MoLiApiResponseModel resModel = new MoLiApiResponseModel();
try
{
string text = ConvertToString(obj.e.Chain);
resModel = Utils.MoLiApiUtil.Reply(new MoLiApiRequestModel
{
content = message,
content = text,
type = "2",
from = memberUin.ToString(),
fromName = obj.e.Message.Sender.Name,
Expand Down Expand Up @@ -100,9 +102,10 @@ public void OnFriendMessage((Bot s, FriendMessageEvent e) obj, string message, u
MoLiApiResponseModel resModel = new MoLiApiResponseModel();
try
{
string text = ConvertToString(obj.e.Chain);
resModel = Utils.MoLiApiUtil.Reply(new MoLiApiRequestModel
{
content = message,
content = text,
type = "1",
from = friendUin.ToString(),
fromName = obj.e.Message.Sender.Name,
Expand All @@ -129,6 +132,46 @@ public void OnFriendMessage((Bot s, FriendMessageEvent e) obj, string message, u
}
}

private string ConvertToString(MessageChain chains)
{
StringBuilder sb = new StringBuilder();
foreach (var item in chains)
{
switch (item.Type)
{
case BaseChain.ChainType.At:
break;
case BaseChain.ChainType.Reply:
break;
case BaseChain.ChainType.Text:
sb.AppendLine(item.ToString());
break;
case BaseChain.ChainType.Image:
break;
case BaseChain.ChainType.Flash:
break;
case BaseChain.ChainType.Record:
break;
case BaseChain.ChainType.Video:
break;
case BaseChain.ChainType.QFace:
break;
case BaseChain.ChainType.BFace:
break;
case BaseChain.ChainType.Xml:
break;
case BaseChain.ChainType.MultiMsg:
break;
case BaseChain.ChainType.Json:
break;
default:
break;
}
}

return sb.ToString();
}

private bool IsAtBot(MessageChain baseChains, uint botUin)
{
bool isAtBot = false;
Expand Down
2 changes: 1 addition & 1 deletion plugins/MoLiPlugin/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"DisplayName": "茉莉机器人",
"Description": "对接 茉莉 API",
"Author": "yiyun",
"Version": "0.3.0",
"Version": "0.3.1",
"SupportedVersions": [ "0.0.1" ]
}

0 comments on commit c5683f3

Please sign in to comment.