private static void Main(string[] args) { CQApiClient client = new CQHTTPClient("http://127.0.0.1:5700", "test", 9000); //var connString0 = "Server=127.0.0.1;User ID=root;Password=asd123...;Database=tatatemp"; //var connString1 = "Server=127.0.0.1;User ID=root;Password=asd123...;Database=tata"; //var conn0 = new MySqlConnection(connString0); //var conn1 = new MySqlConnection(connString1); Console.WriteLine($"QQ:{client.self_id},{client.self_nick}"); Global.botid = client.self_id; // Global.processers.Add(new TFunction.Repeat()); Global.processers.Add(new Dice()); Global.processers.Add(new Ping()); Global.processers.Add(new Nuannuan()); Global.processers.Add(new Cat()); Global.processers.Add(new Autistic()); Global.processers.Add(new Minecraft()); Global.processers.Add(new Help()); Global.processers.Add(new Lottery()); Global.processers.Add(new Se()); Global.processers.Add(new Debug()); // Global.processers.Add(new Chat()); client.OnEventAsync += OnEventAsync; Console.ReadLine(); }
static void Main(string[] args) { cqhttp.Cyan.Logger.LogLevel = cqhttp.Cyan.Enums.Verbosity.INFO; CQApiClient cli = new CQHTTPClient( accessUrl: "http://127.0.0.1:5700", listen_port: 210 ); Group.Jobs.StartJobs(cli, 00000000); Private.Operation.LoadData(); cli.OnEvent += (client, e) => { if (e is MessageEvent) { string text_message = getText((e as MessageEvent).message); Command cmd; try { cmd = Parser.ParseCommand(text_message, (e as MessageEvent).sender.nickname); } catch { return(new EmptyResponse()); } if (e is GroupMessageEvent) { GroupMessageEvent ge = (e as GroupMessageEvent); cmd.endPoint = (client, (ge.messageType, ge.group_id)); if (privateCommands.IndexOf(cmd.operation) != -1) { client.SendTextAsync( cmd.endPoint.Item2, "请私聊调用这项功能" ); client.SendTextAsync( cqhttp.Cyan.Enums.MessageType.private_, ge.sender.user_id, helpMsg ); } else { Group.Jobs.Handle(cmd); } } else if (e is PrivateMessageEvent) { PrivateMessageEvent pe = (e as PrivateMessageEvent); cmd.endPoint = (cli, (pe.messageType, pe.sender_id)); if (cmd.operation == "help") { cli.SendTextAsync(cmd.endPoint.Item2, helpMsg); return(new EmptyResponse()); } try { Private.Operation.Handle(cmd).Wait(); } catch (AggregateException ee) { throw ee.InnerException; } } } return(new EmptyResponse()); }; Console.ReadLine(); }
public static void Init() { client = new CQHTTPClient( access_url: "http://127.0.0.1:5700", listen_port: 8080 ); if (!File.Exists("personal.config.json")) { PersonalInfo personal = new PersonalInfo(); personal.Name = "testname"; personal.QQ = "123456789"; File.WriteAllText("personal.config.json", JsonConvert.SerializeObject(personal)); } else { Personal = JsonConvert.DeserializeObject <PersonalInfo>(File.ReadAllText("personal.config.json")); } if (!File.Exists("whitelist.config.json")) { WhiteList = new List <long>(); File.WriteAllText("whitelist.config.json", JsonConvert.SerializeObject(WhiteList)); } else { WhiteList = JsonConvert.DeserializeObject <List <long> >(File.ReadAllText("whitelist.config.json")); } if (!File.Exists("response.config.json")) { ResponseMentioned = new List <string>(); ResponseMentioned.Add("My internet is poor."); ResponseMentioned.Add("I am restarting my router."); ResponseMentioned.Add("My device has no battery now."); File.WriteAllText("response.config.json", JsonConvert.SerializeObject(ResponseMentioned)); } else { ResponseMentioned = JsonConvert.DeserializeObject <List <string> >(File.ReadAllText("response.config.json")); } if (!File.Exists("meetings.config.json")) { ScheduledMeetings = new List <TencentScheduledMeeting>(); File.WriteAllText("meetings.config.json", JsonConvert.SerializeObject(ScheduledMeetings)); } else { ScheduledMeetings = JsonConvert.DeserializeObject <List <TencentScheduledMeeting> >(File.ReadAllText("meetings.config.json")); } WhiteListEnabled = WhiteList.Count > 0; }
static void Main(string[] args) { LoadCfg(); var client = new CQHTTPClient( accessUrl: Config.api_addr, listen_port: Config.listen_port, accessToken: Config.access_token, secret: Config.listen_secret ); FunctionPool.Initialize(); client.OnEvent += (cli, e) => { if (e is MessageEvent) { (MessageType, long)endPoint = (MessageType.private_, 745679136); if (e is GroupMessageEvent) { endPoint = ( MessageType.group_, (e as GroupMessageEvent).group_id ); } else if (e is PrivateMessageEvent) { endPoint = ( MessageType.private_, (e as PrivateMessageEvent).sender_id ); } else if (e is DiscussMessageEvent) { endPoint = ( MessageType.discuss_, (e as DiscussMessageEvent).discuss_id ); } Dispatcher.Dispatcher.Dispatch( cli, e as MessageEvent, endPoint ); } return(new EmptyResponse()); }; Console.ReadLine(); }
static void Main(string[] args) { CQApiClient client = new CQHTTPClient( access_url: "http://127.0.0.1:8080", access_token: "", listen_port: 5700, secret: "" ); Console.WriteLine( $"QQ:{client.self_id},昵称:{client.self_nick}" ); //client构造后会发送一条get_login_info请求,则可以通过 //判断是否成功获取登陆的账号的QQ与昵称判断API是否可访问 client.OnEvent += (client, e) => { return(new EmptyResponse()); }; }
/// public static void Main_() { var cli = new CQHTTPClient( accessUrl: "http://egurl.com" ); cli.OnEventAsync += async(client, e) => { // 只复读群消息 if (e is GroupMessageEvent) { var me = (e as GroupMessageEvent); await client.SendMessageAsync( Enums.MessageType.group_, me.group_id, me.message ); } return(new EmptyResponse()); }; System.Console.ReadLine();// 务必在所有bot中加上这一句 }