private void StationListener_OnMsg(JObject obj) { if (obj["status"].ToString() != "success") { return; } var resp = obj["response"]; switch ((string)obj["action"]) { case "sendServerTime": Car.DeltaTime = (long)resp["time"] - DateTime.UtcNow.ToTimestamp(); break; case "sendRoomNumberList": foreach (JObject car in (JArray)resp) { var c = new Car(car); lock (cars) cars.Add(c); OnNewCar?.Invoke(c); } break; } }
private void StationListener_OnMsg(JObject obj) { this.Log(LoggerLevel.Info, obj); if (obj["status"].ToString() != "success" || obj["action"].ToString() != "sendRoomNumberList") { return; } foreach (JObject car in (JArray)obj["response"]) { this.Log(LoggerLevel.Info, car); var c = new Car(car); lock (cars) cars.Add(c); OnNewCar?.Invoke(c); } }
public async Task <bool> OnMessage(HandlerArgs args) { var message = args.message; if (message == "m" || message == "M") { if (LastCar.TryGetValue(args.Sender.FromQQ, out int lc)) { lock (sekaicars) sekaicars = sekaicars.Where(c => c.index != lc).ToList(); } return(true); } int split, car; if (IsIgnore(args.Sender)) { return(false); } if (message.Length < 5) { return(false); } for (int i = 0; i < 5; ++i) { if (!IsNumeric(message[i])) { return(false); } } split = message.Length > 5 && IsNumeric(message[5]) ? 6 : 5; if (message.Length > split && IsNumeric(message[split])) { return(false); } car = int.Parse(message.Substring(0, split)); LastCar[args.Sender.FromQQ] = car; string raw_message = car.ToString("d5") + " " + message.Substring(split); // ignore non-text messages raw_message = codereg.Replace(raw_message, _ => ""); switch (Configuration.GetConfig <CarTypeConfig>()[args.Sender.FromGroup]) { case CarType.Bandori: var ignore = CheckIgnored(car, message.Substring(split)); if (ignore != null) { if (ignore != "") { await args.Callback(ignore); } break; } JObject res = await Utils.GetHttp($"http://api.bandoristation.com/?function=submit_room_number&number={car}&source={source}&token={token}&raw_message={raw_message}&user_id={args.Sender.FromQQ}"); if (res == null) { await args.Callback($"无法连接到bandoristation.com"); } else if (res["status"].ToString() != "success") { await args.Callback($"上传车牌时发生错误: {res["response"]}"); } return(true); case CarType.Sekai: if (CheckIgnored(car, message.Substring(split)) == "") { break; } if (car == 114514 || car == 11451 || car == 19198) { break; } var caro = new Car { index = car, rawmessage = raw_message, time = DateTime.UtcNow }; lock (sekaicars) sekaicars.Add(caro); OnNewCar?.Invoke(caro); return(true); } return(false); }
public YCM() { listener = new StationListener(); listener.OnNewCar += car => OnNewCar?.Invoke(car); listener.Start(); }