old_flsystem/应用/RoomMembers/Class1.cs

122 lines
5.2 KiB
C#
Raw Permalink Normal View History

2022-09-20 03:10:29 +00:00
using Api.Framework.Events;
using Api.Framework.SDK;
using RoomMembers.Properties;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace RoomMembers
{
public class Class1 : Plugin
{
public Class1()
{
this.Name = "群成员Api";
this.Note = "获取群成员";
this.Logo = Resources._22;
}
#region
//public static Config Config;
#endregion
public override void Start()
{
try
{
SDK.WebRequestEvent += SDK_WebRequestEvent;
}
catch (Exception ex)
{
this.OnLog(ex.Message);
}
}
private void SDK_WebRequestEvent(object sender, WebRequestEvents e)
{
try
{
#region
if (e.Param.ContainsKey("method"))//方法名称
{
var method = e.Param["method"].ToLower();
switch (method)
{
case "roommembers"://用户
{
try
{
if (!e.Param.ContainsKey("roomid")) throw new Exception("缺少参数roomid");
if (!e.Param.ContainsKey("robotname")) throw new Exception("缺少参数roomname");
var robotname = e.Param["robotname"].ToString();
var roomid = e.Param["roomid"].ToString();
if (string.IsNullOrWhiteSpace(robotname)) throw new Exception("robotname参数不能为空");
if (string.IsNullOrWhiteSpace(roomid)) throw new Exception("roomid参数不能为空");
var client = Chat.Framework.ChatClient.WXClient.Values.FirstOrDefault(f => f.WeixinHao == robotname && f.WeixinType == Chat.Framework.WXSdk.Implement.WeixinType.Grpc微信 && f.Status == Chat.Framework.WXSdk.WxStatus.线);
if (client == null) throw new Exception("机器人不存在或者不在线");
var members = client.GetMembers(roomid, true);
if (members == null) members = new Chat.Framework.WXSdk.GroupMember[] { };
e.Send(members);
}
catch (Exception ex)
{
e.Send(ex.Message, -1);
}
}
break;
case "removemembers":
{
try
{
if (!e.Param.ContainsKey("roomid")) throw new Exception("缺少参数roomid");
if (!e.Param.ContainsKey("robotname")) throw new Exception("缺少参数roomname");
if (!e.Param.ContainsKey("usernames")) throw new Exception("缺少参数roomname");
var robotname = e.Param["robotname"].ToString();
var roomid = e.Param["roomid"].ToString();
var usernames = e.Param["usernames"].ToString();
if (string.IsNullOrWhiteSpace(robotname)) throw new Exception("robotname参数不能为空");
if (string.IsNullOrWhiteSpace(roomid)) throw new Exception("roomid参数不能为空");
if (string.IsNullOrWhiteSpace(usernames)) throw new Exception("usernames参数不能为空");
var client = Chat.Framework.ChatClient.WXClient.Values.FirstOrDefault(f => f.WeixinHao == robotname && f.WeixinType == Chat.Framework.WXSdk.Implement.WeixinType.Grpc微信 && f.Status == Chat.Framework.WXSdk.WxStatus.线);
if (client == null) throw new Exception("机器人不存在或者不在线");
var users = usernames.Replace("", ",").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(f => f.Trim()).ToList();
foreach (var item in users)
{
client.DeleteGroupMember(item, roomid);
Thread.Sleep(200);
}
e.Send("任务执行完成");
}
catch (Exception ex)
{
e.Send(ex.Message, -1);
}
}
break;
}
}
#endregion
}
catch (Exception ex)
{
}
}
}
}