private static void ConfigListener(ApiPostListener cqWebSocketEvent) { _ = Task.Run(async() => { while (true) { await Task.Delay(1000); Console.WriteLine("Available: {0}, Listening {1}", (cqWebSocketEvent as dynamic).IsAvailable, (cqWebSocketEvent as dynamic).IsListening); } }); cqWebSocketEvent.MessageEvent += async(api, e) => { Console.WriteLine(e.Content.Raw); Console.WriteLine(api is null); await api.SendMessageAsync(e.Endpoint, "Response 1" + SendingMessage.LocalImage(@"C:\Users\yinmi\Pictures\bad(Y)(auto_scale)(Level3)(width 2000).jpg")); if (e is GroupMessage groupMessage) { await api.GetGroupMemberInfoAsync(groupMessage.GroupId, e.UserId); } await api.SendMessageAsync(e.Endpoint, "Response 2" + SendingMessage.LocalImage(@"C:\Users\yinmi\Pictures\karen.jpg")); }; cqWebSocketEvent.FriendRequestEvent += (api, e) => true; cqWebSocketEvent.GroupInviteEvent += (api, e) => true; cqWebSocketEvent.AnonymousMessageEvent += (api, e) => { Console.WriteLine("id|name|flag:{0}|{1}|{2}", e.Anonymous.Id, e.Anonymous.Name, e.Anonymous.Flag); api.BanMessageSource(e.GroupId, e.Source, 1); }; }
public static IEnumerable <object[]> Interpolated_TestData() { var cqCodeMessage = SendingMessage.At(123456789); var textMessage = "hello"; var imageMessage = SendingMessage.LocalImage("/a.jpg"); var multipleSegmentMessage = SendingMessage.At(123456789) + "hello" + SendingMessage.LocalImage("/a.jpg"); { yield return(new object[] { SendingMessage.FromInterpolated($"{1}"), "1" }); yield return(new object[] { SendingMessage.FromInterpolated($"{cqCodeMessage},你好"), cqCodeMessage + ",你好" }); yield return(new object[] { SendingMessage.FromInterpolated($"{multipleSegmentMessage},你好"), multipleSegmentMessage + ",你好" }); yield return(new object[] { SendingMessage.FromInterpolated($"{cqCodeMessage}{textMessage}"), cqCodeMessage + textMessage }); yield return(new object[] { SendingMessage.FromInterpolated($"{textMessage}{cqCodeMessage},[]& {23}"), textMessage + cqCodeMessage + ",[]& " + 23.ToString() }); } }
public void LocalImageTests(string path, string expected) { var image = SendingMessage.LocalImage(path); Assert.Equal(new KeyValuePair <string, string>("file", expected), image.Sections.Single().Data.Single()); }