IQQEventRegisterService
对于以前,qq事件的发布是需要插件实现IRobotPlugin接口的,现在qq内核的事件以事件形式发布给插件,所以插件需要向sdk注册处理各种qq事件的委托。
依赖
你需要导入LiangdunSdk.dll, 在Manifest.xml中依赖LiangdunSdk的bundle即可。
使用
初始化插件的sdk
internal static class MySDK
{
private static IQQEventRegisterService _EventRegisterService;
private static Sdk _LiangdunSdk;
internal static IQQEventRegisterService EventRegisterService
{
get
{
if (_EventRegisterService == null) _EventRegisterService = LiangdunSdk.GetQQEventRegisterService();
return _EventRegisterService;
}
}
public static Sdk LiangdunSdk
{
get { return _LiangdunSdk; }
set { _LiangdunSdk = value; }
}
}
初始化MySDK的_LiangdunSdk后,即可使用服务!
在 public class Activator : IBundleActivator类的start方法中进行初始化:
Context = context;
var sdkFactoryService = context.GetFirstOrDefaultService<SdkFactoryService>();
MySDK.LiangdunSdk = sdkFactoryService.GetSdk(context);
定义委托执行的函数
#region 好友消息 测试
private static void HandleFriendMsg(uint uin, QQEvent evt)
{
try
{
FriendMsgEvent fe = (FriendMsgEvent)evt;
Console.WriteLine(fe.FriendUin + " " + fe.Msg);
}
catch (Exception ex)
{ }
}
#endregion
#region 群消息
private static void HandleClusterMsg(uint uin, QQEvent evt)
{
try
{
ClusterMsgEvent clusterMsg = (ClusterMsgEvent)evt;
Console.WriteLine(clusterMsg.Msg);
}
catch (Exception ex)
{
}
}
#endregion
注册
internal class QQEventHandler
{
internal static void RegisterQQEvent()
{
MySDK.EventRegisterService.Register(Activator.Context.Bundle, HandleFriendMsg, QQEventType.MSG_FRIEND);
MySDK.EventRegisterService.Register(Activator.Context.Bundle, HandleClusterMsg, QQEventType.MSG_CLUSTER);
}
}
注销
sdk在插件禁用后会自动注销插件注册过的委托,所以插件不需要自己注销委托。
网友评论