public static void Main(string[] args) { // 好友消息回调 Client.FriendMessageReceived += (sender, message) => { Console.WriteLine($"{message.Sender.Alias ?? message.Sender.Nickname}:{message.Content}"); }; // 群消息回调 Client.GroupMessageReceived += (sender, message) => { Console.WriteLine( $"[{message.Group.Name}]{message.Sender.Alias ?? message.Sender.Nickname}:{message.Content}"); if (message.Content.IsMatch(@"^\s*Knock knock\s*$")) { message.Reply("Who's there?"); } else if (message.StrictlyMentionedMe) { message.Reply("什么事?"); } }; // 讨论组消息回调 Client.DiscussionMessageReceived += (sender, message) => { Console.WriteLine($"[{message.Discussion.Name}]{message.Sender.Nickname}:{message.Content}"); }; // 消息回显 Client.MessageEcho += (sender, e) => { Console.WriteLine($"{e.Target.Name}>{e.Content}"); }; if (File.Exists(CookiePath)) { // 尝试使用cookie登录 if (Client.Start(File.ReadAllText(CookiePath)) != DumbQQClient.LoginResult.Succeeded) { QrLogin(); } } else { QrLogin(); } Console.WriteLine($"欢迎,{Client.Nickname}!"); // 导出cookie try { File.WriteAllText(CookiePath, Client.DumpCookies()); } catch { // Ignored } // 防止程序终止 while (Client.Status == DumbQQClient.ClientStatus.Active) { } }
public static void Main(string[] args) { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); // 好友消息回调 Client.FriendMessageReceived += (sender, message) => { Console.WriteLine($"{message.Sender.Alias ?? message.Sender.Nickname}:{message.Content}"); }; // 群消息回调 Client.GroupMessageReceived += (sender, message) => { Console.WriteLine( $"[{message.Group.Name}]{message.Sender.Alias ?? message.Sender.Nickname}:{message.Content}"); //if (message.StrictlyMentionedMe) // message.Reply("什么事?"); }; // 讨论组消息回调 Client.DiscussionMessageReceived += (sender, message) => { Console.WriteLine($"[{message.Discussion.Name}]{message.Sender.Nickname}:{message.Content}"); }; // 消息回显 Client.MessageEcho += (sender, e) => { Console.WriteLine($"{e.Target.Name}>{e.Content}"); }; if (File.Exists(CookiePath)) { // 尝试使用cookie登录 if (Client.Start(File.ReadAllText(CookiePath)) != DumbQQClient.LoginResult.Succeeded) { // 登录失败,退回二维码登录 QrLogin(); } } else { QrLogin(); } Console.WriteLine($"Login Success,{Client.Nickname}!"); // 导出cookie File.WriteAllText(CookiePath, Client.DumpCookies()); // 防止程序终止 Console.ReadLine(); }