protected override void Invoking(MessageReceivedEventArgs e, ComplexMessage elements) { e.Reply(Resources.Processing); if (HttpUtilities.HttpGet(Resources.CovidStatusApiURL, out string content)) { try { var json = JObject.Parse(content); var dJson = JObject.Parse(json["data"].ToString()); var chinaTotal = dJson["chinaTotal"]; var chinaAdd = dJson["chinaAdd"]; e.Source.Send($"数据截至:{dJson["lastUpdateTime"]}\n" + $"累计确诊:{chinaTotal["confirm"]}(较昨日:{chinaAdd["confirm"].ToObject<int>():+#;-#;0})\n" + $"累计治愈:{chinaTotal["heal"]}(较昨日:{chinaAdd["heal"].ToObject<int>():+#;-#;0})\n" + $"累计死亡:{chinaTotal["dead"]}(较昨日:{chinaAdd["dead"].ToObject<int>():+#;-#;0})\n" + $"现有确诊:{chinaTotal["nowConfirm"]}(较昨日:{chinaAdd["nowConfirm"].ToObject<int>():+#;-#;0})\n" + $"现有疑似:{chinaTotal["suspect"]}(较昨日:{chinaAdd["suspect"].ToObject<int>():+#;-#;0})\n" + $"现有重症:{chinaTotal["nowSevere"]}(较昨日:{chinaAdd["nowSevere"].ToObject<int>():+#;-#;0})\n" + "(数据来源:腾讯新闻)"); } catch { e.Reply($"信息处理失败了 (;´д`)ゞ"); } } else { e.Reply($"请求失败了 (;´д`)ゞ"); } }
protected override void Invoking(MessageReceivedEventArgs e, PlainText plainText) { string songName = plainText; if (!string.IsNullOrWhiteSpace(songName)) { var musicName = songName.Trim(); var client = new HttpClient(); var res = client.GetAsync(string.Format(Resources.MusicApiURL, WebUtility.UrlEncode(musicName))).Result; if (res.IsSuccessStatusCode) { var json = JObject.Parse(res.Content.ReadAsStringAsync().Result); try { var musicJson = json["result"]["songs"][0]; e.Reply($"这是您点的歌曲哦 φ(>ω<*) :{string.Join(" / ", musicJson["artists"].Select(x => x["name"]))} - {musicJson["name"]}"); e.Source.Send(new Music { Id = musicJson["id"].ToObject <int>(), Platform = MusicPlatform.Netease }); } catch { e.Reply($"没有叫 {musicName} 的歌曲哦 (๑>ڡ<)☆"); } } else { e.Reply($"请求失败了 (;´д`)ゞ"); } } else { NotifyIncorrectUsage(e); } }
protected override void Invoking(MessageReceivedEventArgs e, ComplexMessage elements = null) { var client = new HttpClient(); var res = client.GetAsync(Resources.CovidStatusApiURL).Result; if (res.IsSuccessStatusCode) { try { var json = JObject.Parse(res.Content.ReadAsStringAsync().Result); var dJson = JObject.Parse(json["data"].ToString()); var chinaTotal = dJson["chinaTotal"]; var chinaAdd = dJson["chinaAdd"]; e.Source.Send($"数据截至:{dJson["lastUpdateTime"]}\n" + $"累计确诊:{chinaTotal["confirm"]}(较昨日:{chinaAdd["confirm"].ToObject<int>():+#;-#;0})\n" + $"累计治愈:{chinaTotal["heal"]}(较昨日:{chinaAdd["heal"].ToObject<int>():+#;-#;0})\n" + $"累计死亡:{chinaTotal["dead"]}(较昨日:{chinaAdd["dead"].ToObject<int>():+#;-#;0})\n" + $"现有确诊:{chinaTotal["nowConfirm"]}(较昨日:{chinaAdd["nowConfirm"].ToObject<int>():+#;-#;0})\n" + $"现有疑似:{chinaTotal["suspect"]}(较昨日:{chinaAdd["suspect"].ToObject<int>():+#;-#;0})\n" + $"现有重症:{chinaTotal["nowSevere"]}(较昨日:{chinaAdd["nowSevere"].ToObject<int>():+#;-#;0})\n" + "(数据来源:腾讯新闻)"); } catch { e.Reply($"信息处理失败了 (;´д`)ゞ"); } } else { e.Reply($"请求失败了 (;´д`)ゞ"); } }
internal override void Invoke(MessageReceivedEventArgs e) { var message = e.Message.Parse(); var mentions = message.OfType <Mention>(); var distinctMentions = mentions.Distinct(); if (distinctMentions.Count() == 1) { var mention = distinctMentions.Single(); var target = mention.GetTarget(); var plainTexts = message.OfType <PlainText>(); var others = message.Except(mentions).Except(plainTexts); if (!others.Any() && string.IsNullOrWhiteSpace(string.Join("", plainTexts)) && message.Where(mention.Equals).Count() > 1) { string custom = string.Empty; var config = (JObject)SlappingConfig.Config; string numStr = target.Number.ToString(); if (config.ContainsKey(numStr)) { custom = " " + config[numStr].ToString(); } if (target.Equals(e.Subject)) { e.Reply("拍了拍 自己" + custom); } else { e.Reply("拍了拍 " + mention + custom); } } } }
protected override void Invoking(MessageReceivedEventArgs e, PlainText plainText, PlainText countText, ComplexMessage elements) { if (int.TryParse(countText, out int count) && count < 100) { e.Reply(Resources.Processing); try { var results = PingUtilities.SendMoreAndGetRoundtripTime(plainText, count); var successResults = results.Where(x => x > -1); int timedoutCount = results.Count() - successResults.Count(); if (timedoutCount == count) { e.Reply($"Ping {plainText} 超时"); } else { e.Reply($"Ping {plainText} 结果:\n延迟:{Math.Round(successResults.Average())} ms\n丢包率:{timedoutCount / count * 100} %"); } } catch (PingException ex) { e.Reply($"Ping {plainText} 出错,错误原因:{ex.Message}"); } } }
protected override void Invoking(MessageReceivedEventArgs e, ComplexMessage elements) { var version = VersionUtilities.GetTagVersion(); e.Reply(Resources.Processing); if (VersionUtilities.GetLatestVersion(out Version latestVersion, out _)) { if (version < latestVersion) { e.Source.Send($"有新版本更新哦!(ૢ˃ꌂ˂⁎)\n当前版本:{version}\n最新 Release 版本:{latestVersion}\n\n如果需要更新,请发送 {Configuration.Prefix}update run"); } else if (version == latestVersion) { e.Source.Send($"当前版本已是最新版本!(ૢ˃ꌂ˂⁎)\n当前版本:{version}"); } else { e.Source.Send($"当前版本较最新 Release 版本新,可能你正在使用内测版本 (ノ´▽`)ノ♪\n当前版本:{version}\n最新 Release 版本:{latestVersion}"); } } else { e.Reply("获取最新版本信息失败了 (;´д`)ゞ"); } }
protected override void Invoking(MessageReceivedEventArgs e, PlainText appName, PlainText operationText, ComplexMessage elements) { try { var config = Configuration.AppStatusConfig; var app = AppUtilities.GetApps(e.Source, e.Subject).Where(x => x.Name.ToLower() == appName.Content.ToLower()).Single(); bool?operation = operationText.Content.ToLower().ToBool("on", "off"); if (app.CanDisable) { if (operation.HasValue) { config.Config[e.Source.ToString(true)][app.Name] = operation.Value; e.Reply($"已{(operation.Value ? "启用" : "停用")}应用 {app.DisplayName}({app.Name}) ✧(≖ ◡ ≖✿ "); config.Save(); } } else { e.Reply($"该应用 {app.DisplayName}({app.Name})不允许被启用/停用 o(゚Д゚)っ!"); } } catch (InvalidOperationException) { e.Reply($"应用 {appName} 不存在 (•́へ•́╬)"); } }
protected override void Invoking(MessageReceivedEventArgs e, ComplexMessage elements) { var config = (JArray)BlacklistConfig.Config; long number = long.MinValue; bool?operation = false; if (elements.Count == 1 && elements.TryDeconstruct(out PlainText plainText)) { string[] splitText = plainText.Content.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (splitText.Length == 2 && long.TryParse(splitText[1], out number)) { operation = splitText[0].ToLower().ToBool("add", "remove"); } } else if (elements.Count == 2 && elements.TryDeconstruct(out plainText, out Mention mention)) { operation = plainText.Content.Trim().ToLower().ToBool("add", "remove"); number = mention.TargetNumber; } if (number == Owner || number == Bot.CurrentUser.Number) { e.Reply("无法将主人或机器人加入到黑名单 ─=≡Σ(((つ•̀ω•́)つ"); } else { if ((!operation.HasValue) || number == long.MinValue) { NotifyIncorrectUsage(e); } else if (operation.Value) { if (config.Contains(number, true)) { e.Reply($"{number} 已存在黑名单内 (ц`ω´ц*)"); } else { config.Add(number); BlacklistConfig.Save(); e.Reply($"已将 {number} 加入黑名单 ❥(ゝω・✿ฺ)"); } } else { if (config.Contains(number, true)) { BlacklistConfig.SetValueAndSave(config.Remove(number, true)); e.Reply($"已将 {number} 移出黑名单 ❥(ゝω・✿ฺ)"); } else { e.Reply($"{number} 不存在黑名单内 (ц`ω´ц*)"); } } } }
protected override void Invoking(MessageReceivedEventArgs e, ComplexMessage elements) { ((JObject)SlappingConfig.Config).Remove(e.Subject.Number.ToString()); SlappingConfig.Save(); e.Reply("你的拍一拍自定义语句重置好了 |ू・ω・` )"); }
protected override void Invoking(MessageReceivedEventArgs e, MultipartElement element, ComplexMessage elements) { ((JObject)SlappingConfig.Config).Add(new JProperty(e.Subject.Number.ToString(), element.ToSendableString()), true); SlappingConfig.Save(); e.Reply("你的拍一拍自定义语句设置好了 |ू・ω・` )"); }
protected override void Invoking(MessageReceivedEventArgs e, PlainText operationText, PlainText numberText, ComplexMessage elements) { var config = (JArray)BlacklistConfig.Config; bool?operation = operationText.Content.ToLower().ToBool("add", "remove"); if (long.TryParse(numberText.Content, out long number)) { if (number == Owner || number == Bot.CurrentUser.Number) { e.Reply("无法将主人或机器人加入到黑名单 ─=≡Σ(((つ•̀ω•́)つ"); } else { if (operation.HasValue) { if (operation.Value) { if (config.Contains(number, true)) { e.Reply($"{number} 已存在黑名单内 (ц`ω´ц*)"); } else { config.Add(number); BlacklistConfig.Save(); e.Reply($"已将 {number} 加入黑名单 ❥(ゝω・✿ฺ)"); } } else { if (config.Contains(number, true)) { config.Remove(number, ref config); BlacklistConfig.Save(); e.Reply($"已将 {number} 移出黑名单 ❥(ゝω・✿ฺ)"); } else { e.Reply($"{number} 不存在黑名单内 (ц`ω´ц*)"); } } } } } }
protected override void Invoking(MessageReceivedEventArgs e, PlainText optionText, ComplexMessage elements) { var options = elements.OfType <PlainText>(); if (optionText.Content.ToLower() == "options" && options.Count() == elements.Count) { e.Reply((ISendable)RandomUtilities.RandomOption(options)); } }
protected override void Invoking(MessageReceivedEventArgs e, PlainText plainText, ComplexMessage elements) { e.Reply(Resources.Processing); if (HttpUtilities.HttpGet(string.Format(Resources.IPInfoApiURL, plainText), out string content)) { try { var json = JObject.Parse(content); if (json["status"].ToString() == "success") { e.Reply($"状态:获取成功\n" + $"IP {json["query"]} 信息:\n" + $"洲:{json["continent"]}({json["continentCode"]})\n" + $"国家:{json["country"]}({json["countryCode"]})\n" + $"地区:{json["regionName"]}({json["region"]})\n" + $"城市:{json["city"]}\n" + $"邮政编码:{json["zip"]}\n" + $"经纬度:{json["lat"]}, {json["lon"]}\n" + $"时区:{json["timezone"]}\n" + $"货币单位:{json["currency"]}\n" + $"ISP:{json["isp"]}\n" + $"所属组织:{json["org"]}\n" + $"AS:{json["asname"]}({json["as"]})\n" + $"反向DNS:{json["reverse"]}\n" + $"移动数据接入:{(json["mobile"].ToObject<bool>() ? "是" : "否")}\n" + $"代理:{(json["proxy"].ToObject<bool>() ? "是" : "否")}\n" + $"托管/数据中心:{(json["hosting"].ToObject<bool>() ? "是" : "否")}"); } else { e.Reply("获取 IP 信息失败" + (json.ContainsKey("message") ? ",错误原因:" + json["message"] : string.Empty)); } } catch { e.Reply("信息处理失败了 (;´д`)ゞ"); } } else { e.Reply("请求失败了 (;´д`)ゞ"); } }
protected override void Invoking(MessageReceivedEventArgs e, ComplexMessage elements) { var plainText = elements.OfType <PlainText>(); if (plainText.Count() == elements.Count) { e.Reply(Resources.Processing); string str = string.Join(" ", plainText); string musicName = str.Trim(); if (HttpUtilities.HttpGet(string.Format(Resources.MusicApiURL, WebUtility.UrlEncode(musicName)), out string content)) { try { var json = JObject.Parse(content); var musicJson = json["result"]["songs"][0]; e.Reply($"这是您点的歌曲哦 φ(>ω<*) :{string.Join(" / ", musicJson["artists"].Select(x => x["name"]))} - {musicJson["name"]}"); e.Source.Send(new Music { Id = musicJson["id"].ToObject <int>(), Platform = MusicPlatform.Netease }); } catch (ApiException ex) when(ex.ErrorCode == -11) { e.Reply("歌曲发送失败了 (;´д`)ゞ"); } catch (ApiException) { throw; } catch { e.Reply($"没有叫 {musicName} 的歌曲哦 (๑>ڡ<)☆"); } } else { e.Reply($"请求失败了 (;´д`)ゞ"); } } }
protected override void Invoking(MessageReceivedEventArgs e, PlainText plainText, ComplexMessage elements) { e.Reply(Resources.Processing); var version = VersionUtilities.GetTagVersion(); string str = plainText.Content.ToLower(); if (str == "run") { if (VersionUtilities.GetLatestVersion(out Version latestVersion, out string downloadUri)) { if (version < latestVersion) { try { if (HttpUtilities.HttpDownload(downloadUri, $"app\\{Constants.AppId}.cpk")) { e.Reply("更新完毕,请手动重载应用 (*๓´╰╯`๓)"); } else { e.Reply($"更新失败,发送 {Configuration.Prefix}update run 重试 (;´д`)ゞ"); } } catch { e.Reply("下载插件失败了 (;´д`)ゞ"); } } else { e.Source.Send("目前版本无需更新 (ノ´▽`)ノ♪"); } } else { e.Reply("获取最新版本信息失败了 (;´д`)ゞ"); } } }
protected override void Invoking(MessageReceivedEventArgs e, PlainText optionText, PlainText minValueText, PlainText maxValueText, ComplexMessage elements) { string option = optionText.Content.ToLower(); if (option == "number") { if (double.TryParse(minValueText, out double minValue) && double.TryParse(maxValueText, out double maxValue)) { e.Reply(RandomUtilities.NextDouble(minValue, maxValue).ToString()); Handled = true; } } else if (option == "numberint") { if (long.TryParse(minValueText, out long minValue) && long.TryParse(maxValueText, out long maxValue)) { e.Reply(RandomUtilities.Next(minValue, maxValue).ToString()); Handled = true; } } }
protected override void Invoking(MessageReceivedEventArgs e, PlainText plainText) { string[] splitText = plainText.Content.Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries); if (splitText != null && splitText.Length == 2) { try { var config = Commons.AppStatusConfig; var app = GetApps(e.Source, e.Sender).Where(x => x.Name == splitText[0]).Single(); bool?operation = splitText[1].ToLower().ToBool("on", "off"); if (app.CanDisable) { if (!operation.HasValue) { NotifyIncorrectUsage(e); } else { config.Config[e.Source.ToString(true)][app.Name] = operation.Value; e.Reply($"已{(operation.Value ? "启用" : "停用")}应用 {app.DisplayName}({app.Name}) ✧(≖ ◡ ≖✿ "); config.Save(); } } else { e.Reply($"该应用 {app.DisplayName}({app.Name})不允许被启用/停用 o(゚Д゚)っ!"); } } catch (InvalidOperationException) { e.Reply($"应用 {splitText[0]} 不存在"); } } else { NotifyIncorrectUsage(e); } }
protected override void Invoking(MessageReceivedEventArgs e, PlainText plainText, ComplexMessage elements) { var apps = AppUtilities.GetApps(e.Source, e.Subject); if (int.TryParse(plainText, out int pageIndex)) { var appInfos = apps.Select(GetAppInfo).OrderBy(x => x); int pageCount = (int)Math.Ceiling((float)appInfos.Count() / MaxCount); if (pageIndex > 0 && pageIndex <= pageCount) { int start = (pageIndex - 1) * MaxCount; int count = pageIndex < pageCount ? MaxCount : appInfos.Count() - start; var appInfosSplit = appInfos.Skip(start).Take(count); e.Source.Send($"帮助菜单 (第 {pageIndex} 页 / 共 {pageCount} 页):\n\n" + string.Join("\n", appInfosSplit)); } else if (pageIndex < 1) { e.Reply($"页数不能小于等于 0 (T▽T)"); } else if (pageIndex > pageCount) { e.Reply($"帮助菜单仅有 {pageCount} 页 |ω・`)"); } } else { try { var app = apps.Where(x => x.Name.ToLower() == plainText.Content.ToLower()).Single(); e.Source.Send(GetAppInfo(app) + ":\n" + string.Join("\n", app.Features.Where(f => f.Usage != null).Select(f => f.Usage))); } catch (InvalidOperationException) { e.Reply($"应用 {plainText} 不存在 (•́へ•́╬)"); } } string GetAppInfo(AppBase app) => $"{(app.IsEnabled(e.Source) ? string.Empty : "【已停用】")}{app.DisplayName} ({app.Name})"; }
internal override void Invoke(MessageReceivedEventArgs e) { var message = e.Message.Parse(); var mentions = message.OfType <Mention>(); var distinctedMentions = mentions.Distinct(); var slappeeMentions = distinctedMentions.Where(x => mentions.Where(x.Equals).Count() > 1); if (slappeeMentions.Any()) { e.Reply("拍了拍 " + string.Join(" ", slappeeMentions)); } }
protected override void Invoking(MessageReceivedEventArgs e, PlainText plainText, ComplexMessage elements) { e.Reply(Resources.Processing); if (HttpUtilities.HttpGet(string.Format(Resources.WeatherApiURL, plainText), out string content)) { try { var json = JObject.Parse(content); int errorCode = json["error"].ToObject <int>(); if (errorCode == 0) { var result = json["results"][0]; var weather = result["weather_data"]; string nowTemperature = Regex.Match(weather[0]["date"].ToString(), @"(实时:|\d{2}℃|)").Value; var weatherStrs = weather.Select(x => $"{x["date"].ToString().Substring(0, 2)}:{x["weather"]} {GetTemperature(x["temperature"].ToString())} {x["wind"]}"); e.Source.Send($"城市 {result["currentCity"]} 天气:\n实时:{nowTemperature} PM2.5:{result["pm25"]} μg/m³\n{string.Join("\n", weatherStrs)}"); } else if (errorCode == -3) { e.Reply($"城市 {plainText} 不存在 (๑>ڡ<)☆"); } else { e.Reply($"请求出错了,错误码:{json["error"]},错误原因:{json["status"]}"); } } catch { e.Reply($"信息处理失败了 (;´д`)ゞ"); } } else { e.Reply($"请求失败了 (;´д`)ゞ"); } }
protected override void Invoking(MessageReceivedEventArgs e, ComplexMessage elements) { e.Reply("帮助菜单用法:\n" + AppBase.Apps.Where(x => x.Name == "HelpMenu").Single().Features.Where(x => x.GetType().Name == "HelpMenuCommand").Single().Usage); }
internal override void Invoke(MessageReceivedEventArgs e) { if (Owner == -1) { Handled = true; } if (IsRunning) { if (CurrentUser == null && (Owner == -1 || e.Subject.Number == Owner)) { CurrentUser = e.Subject; } if (CurrentUser != null && CurrentUser.Equals(e.Subject)) { switch (CurrentStepId) { case 0: if (Owner == -1) { e.Reply("Hey! 别来无恙啊,欢迎使用 Minop Bot!"); } e.Reply("请输入管理员账号:(输入 -1 则设置为当前账号)"); break; case 1: if (long.TryParse(e.Message, out OwnerSet)) { if (OwnerSet < -1) { e.Reply("QQ 号不正确,请重新输入管理员账号:"); CurrentStepId--; break; } e.Reply("管理员设置完毕!"); e.Reply("请输入命令响应前缀:"); } else { e.Reply("获取 QQ 号失败,请重新输入管理员账号:"); CurrentStepId--; } break; case 2: Prefix = e.Message; e.Reply("命令响应前缀设置完毕!"); break; } if (CurrentStepId == LastStepId) { e.Reply("配置准备就绪,敬请使用吧!\n" + $"如果需要使用帮助菜单,请输入 {Prefix}help\n" + $"如果设置管理员账号有误,请删除 data\\app\\{AppId}\\PluginConfig.json,并重载应用,发送 minop config\n" + $"如果仅需修改其他内容,发送 {Prefix}config 重新配置即可"); if (OwnerSet == -1) { Owner = CurrentUser.Number; } else { Owner = OwnerSet; } PluginConfig.Save(); CurrentStepId = 0; CurrentUser = null; OwnerSet = -1; IsRunning = false; } else { CurrentStepId++; } } Handled = true; } }
private void OnMessageReceived(object sender, MessageReceivedEventArgs e) { string MesCon = e.Message.Content; if (MesCon.ToLower().StartsWith("cat ")) { string[] Words = MesCon.Split(' '); string AllWord = MesCon.Substring(MesCon.IndexOf(Words[1]) + Words[1].Length).Trim(); switch (Words[1].ToLower()) { case "list": e.Reply(Resources.FunctionList); break; case "ver": case "version": e.Reply(Resources.VersionString); break; case "m": case "music": if (Words.Length >= 3) { string html = GetWebpageSourceCode($"http://music.163.com/api/search/pc?s={WebUtility.UrlEncode(AllWord)}&type=1", new WebClient()); if (html.IndexOf("songs") == -1) { e.Source.Send($"错误:\n没有叫 {AllWord} 的歌曲"); } else { JToken FirstSong = JObject.Parse(html)["result"]["songs"][0]; Music FirstMusic = new Music { Platform = MusicPlatform.Netease, Id = Convert.ToInt64(FirstSong["id"]) }; e.Reply("http://music.163.com/song/media/outer/url?id=" + FirstSong["id"] + ".mp3"); e.Reply(FirstMusic); } } break; case "tl": case "translate": if (Words.Length >= 3) { string Chinese = Translate("zh", AllWord); string Final = Chinese == AllWord?Translate("en", AllWord) : Chinese; e.Reply(Final); } break; case "calc": if (Words.Length >= 3) { string Prefix = "成功:\n"; string Result; try { Result = new DataTable().Compute(AllWord, "").ToString(); } catch (Exception Exp) { Prefix = "失败:\n"; Result = Exp.Message; } if (string.IsNullOrEmpty(Result)) { Prefix = "失败"; } e.Reply(Prefix + Result); } break; } } }
internal void NotifyIncorrectUsage(MessageReceivedEventArgs e) { e.Reply(string.Format(Resources.FeatureIncorrectUsage, Usage)); }