/// <summary> /// 群消息处理 /// </summary> /// <param name="msgContent"></param> /// <param name="urls"></param> private void QqForm_GroupMsgHandler(long msgCode, long gid, string msgGroupName, string msgContent, string FullMessageContent, List <string> urls) { QQGroup group = QQGlobal.listenGroups.Find(g => { return(g.Gid == gid); }); //TODO:接收群消息 QQGroupMessageModel message = new QQGroupMessageModel() { GroupName = group != null?group.GetGroupName() : msgGroupName, MessageContent = msgContent, FullMessageContent = FullMessageContent, MessageStatus = 0, Code = msgCode }; if (urls != null) { if (urls.Count() > 0) { message.MessageUrl1 = urls[0]; } if (urls.Count() > 1) { message.MessageUrl2 = urls[1]; } } SetMessageView(message); if (BuildGoodsHandler != null) { MessageHandler(urls, message); } }
/// <summary> /// 收到信息的函数 /// 并匹配相应指令 /// </summary> public async void GetChat(RegexCommand cmdType) { if (PCREventArgs == null || Sender == null) { return; } switch (cmdType) { //查询公会排名 case RegexCommand.GetGuildRank: //以群名为查询名 if (PCREventArgs.Message.RawText.Length <= 6) { var groupInfo = await QQGroup.GetGroupInfo(); if (groupInfo.apiStatus != APIStatusType.OK) { await QQGroup.SendGroupMessage("调用onebot API时发生错误"); Log.Error("api error", $"调用onebot API时发生错误 Status={groupInfo.apiStatus}"); return; } await KyoukaRank(DBHelper.GetGuildName(PCREventArgs.SourceGroup)); } else //手动指定 { await KyoukaRank(PCREventArgs.Message.RawText.Substring(6)); } break; } }
/// <summary> /// 结束单元格编辑 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvContact_CellEndEdit(object sender, DataGridViewCellEventArgs e) { try { //dgvContact[e.ColumnIndex, e.RowIndex].ReadOnly = true; //dgvContact.EndEdit(); DataGridViewCellCollection cells = dgvContact.Rows[e.RowIndex].Cells; if (cells == null) { return; } long gid = Convert.ToInt64(cells["GroupGid"].Value); object an = cells["GroupAlias"].Value; string aliasName = an == null ? "" : an.ToString(); QQGroup group = null; if (LoginType == 2) { var g = KQ.GetGroupInfo(gid.ToString()); group = new QQGroup(); group.Gid = gid; group.Name = g.group_name; group.Alias = aliasName; } else { group = QQGlobal.store.GetGroupByGin(gid); } var it = QQGlobal.listenGroups.Find((g) => { return(g.Gid == gid); }); if (it != null) { QQGlobal.listenGroups.ForEach(item => { if (item.Gid == gid) { item.Alias = aliasName; } }); cells["GroupAlias"].Value = aliasName; if (it != null) { cells["GroupStatus"].Value = (it.isListen ? "已监控" : ""); } } else { group.Alias = aliasName; QQGlobal.listenGroups.Add(group); } } catch (Exception ex) { } }
/// <summary> /// 添加监控 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolAddListen_Click(object sender, EventArgs e) { if (this.dgvContact.CurrentRow == null) { return; } DataGridViewCellCollection cells = this.dgvContact.CurrentRow.Cells; if (cells == null) { return; } long gid = Convert.ToInt64(cells["GroupGid"].Value); QQGroup group = null; if (LoginType == 2) { var g = KQ.GetGroupInfo(gid.ToString()); group = new QQGroup(); group.Gid = gid; group.Name = g.group_name; } else { group = QQGlobal.store.GetGroupByGin(gid); } if (QQGlobal.listenGroups.Exists((g) => { return(g.Gid == gid); })) { QQGlobal.listenGroups.ForEach(item => { if (item.Gid == gid) { item.isListen = !item.isListen; } }); QQGroup gg = QQGlobal.listenGroups.Find(g => { return(g.Gid == gid); }); cells["GroupTitle"].Value = group.Name; if (gg != null) { cells["GroupStatus"].Value = (gg.isListen ? "已监控" : ""); cells["GroupAlias"].Value = gg.Alias; } } else { group.isListen = true; QQGlobal.listenGroups.Add(group); cells["GroupTitle"].Value = group.Name; cells["GroupStatus"].Value = "已监控"; } }
/// <summary> /// 重构的对比添加 /// </summary> /// <param name="n">项</param> /// <returns></returns> public bool Add(QQGroup n) { if (q.Exists((QQGroup k) => k.GroupId == n.GroupId)) { return(false); } else { q.Add(n); return(true); } }
public override void OnHttpStatusOK(QQHttpResponse response) { JObject json = JObject.Parse(response.GetResponseString()); List <object> recents = new List <object>(); QQStore store = Context.Store; if (json["retcode"].ToString() == "0") { JArray result = json["result"].ToObject <JArray>(); for (int i = 0; i < result.Count; i++) { JObject rejson = result[i].ToObject <JObject>(); switch (rejson["type"].ToObject <int>()) { case 0: { //好友 QQBuddy buddy = store.GetBuddyByUin(rejson["uin"].ToObject <long>()); if (buddy != null) { recents.Add(buddy); } break; } case 1: { //群 QQGroup group = store.GetGroupByCode(rejson["uin"].ToObject <long>()); if (group != null) { recents.Add(group); } break; } case 2: { //讨论组 QQDiscuz discuz = store.GetDiscuzByDid(rejson["uin"].ToObject <long>()); if (discuz != null) { recents.Add(discuz); } break; } } } NotifyActionEvent(QQActionEventType.EVT_OK, recents); } else { NotifyActionEvent(QQActionEventType.EVT_ERROR, new QQException(QQErrorCode.UNEXPECTED_RESPONSE)); } }
public JsonResult Save(QQGroup account) { if (account.Id != default(Guid)) { db.Entry(account).State = System.Data.Entity.EntityState.Modified; } else { db.QQGroups.Add(account); } db.SaveChanges(); return(Json(new { code = "ok", message = "success saved" })); }
public override void OnHttpStatusOK(QQHttpResponse response) { // {"retcode":0,"result":{"gmasklist":[{"gid":1000,"mask":0},{"gid":1638195794,"mask":0},{"gid":321105219,"mask":0}], // "gnamelist":[{"flag":16777217,"name":"iQQ","gid":1638195794,"code":2357062609},{"flag":1048577,"name":"iQQ核心开发区","gid":321105219,"code":640215156}],"gmarklist":[]}} QQStore store = Context.Store; JObject json = JObject.Parse(response.GetResponseString()); int retcode = json["retcode"].ToObject<int>(); if (retcode == 0) { // 处理好友列表 JObject results = json["result"].ToObject<JObject>(); JArray groupJsonList = results["gnamelist"].ToObject<JArray>(); // 群列表 // 禁止接收群消息标志:正常 0, 接收不提醒 1, 完全屏蔽 2 JArray groupMaskJsonList = results["gmasklist"].ToObject<JArray>(); foreach (JToken t in groupJsonList) { JObject groupJson = t.ToObject<JObject>(); QQGroup group = new QQGroup(); group.Gin = groupJson["gid"].ToObject<long>(); group.Code = groupJson["code"].ToObject<long>(); group.Flag = groupJson["flag"].ToObject<int>(); group.Name = groupJson["name"].ToString(); //添加到Store store.AddGroup(group); } foreach (JToken t in groupMaskJsonList) { JObject maskObj = t.ToObject<JObject>(); long gid = maskObj["gid"].ToObject<long>(); int mask = maskObj["mask"].ToObject<int>(); QQGroup group = store.GetGroupByGin(gid); if (group != null) { group.Mask = mask; } } NotifyActionEvent(QQActionEventType.EVT_OK, store.GetGroupList()); } else { // LOG.warn("unknown retcode: " + retcode); NotifyActionEvent(QQActionEventType.EVT_ERROR, null); } }
public QQGroup GetOrAddGroupByGid(long gid) { var g = GetGroupByGid(gid); if (g == null) { g = new QQGroup() { Gid = gid }; AddGroup(g); } return(g); }
public QQGroup GetOrAddGroupByGid(long code) { var g = GetGroupByGid(code); if (g == null) { g = new QQGroup() { Code = code }; AddGroup(g); } return(g); }
public override void onHttpStatusOK(QQHttpResponse response) { JSONObject json = new JSONObject(response.getResponseString()); List <Object> recents = new List <Object>(); QQStore store = getContext().getStore(); if (json.getInt("retcode") == 0) { JSONArray result = json.getJSONArray("result"); for (int i = 0; i < result.length(); i++) { JSONObject rejson = result.getJSONObject(i); switch (rejson.getInt("type")) { case 0: { //好友 QQBuddy buddy = store.getBuddyByUin(rejson.getLong("uin")); if (buddy != null) { recents.Add(buddy); } } break; case 1: { //群 QQGroup group = store.getGroupByCode(rejson.getLong("uin")); if (group != null) { recents.Add(group); } } break; case 2: { //讨论组 QQDiscuz discuz = store.getDiscuzByDid(rejson.getLong("uin")); if (discuz != null) { recents.Add(discuz); } break; } } } notifyActionEvent(QQActionEvent.Type.EVT_OK, recents); } else { notifyActionEvent(QQActionEvent.Type.EVT_ERROR, new QQException(QQWpfApplication1.action.QQException.QQErrorCode.UNEXPECTED_RESPONSE)); } }
/** {@inheritDoc} */ public override void onHttpStatusOK(QQHttpResponse response) { // {"retcode":0,"result":{"gmasklist":[{"gid":1000,"mask":0},{"gid":1638195794,"mask":0},{"gid":321105219,"mask":0}], // "gnamelist":[{"flag":16777217,"name":"iQQ","gid":1638195794,"code":2357062609},{"flag":1048577,"name":"iQQ核心开发区","gid":321105219,"code":640215156}],"gmarklist":[]}} QQStore store = getContext().getStore(); JSONObject json = new JSONObject(response.getResponseString()); int retcode = json.getInt("retcode"); if (retcode == 0) { // 处理好友列表 JSONObject results = json.getJSONObject("result"); JSONArray groupJsonList = results.getJSONArray("gnamelist"); // 群列表 JSONArray groupMaskJsonList = results.getJSONArray("gmasklist"); //禁止接收群消息标志:正常 0, 接收不提醒 1, 完全屏蔽 2 for (int i = 0; i < groupJsonList.length(); i++) { JSONObject groupJson = groupJsonList.getJSONObject(i); QQGroup group = new QQGroup(); group.setGin(groupJson.getLong("gid")); group.setCode(groupJson.getLong("code")); group.setFlag(groupJson.getInt("flag")); group.setName(groupJson.getString("name")); //添加到Store store.addGroup(group); } for (int i = 0; i < groupMaskJsonList.length(); i++) { JSONObject maskObj = groupMaskJsonList.getJSONObject(i); long gid = maskObj.getLong("gid"); int mask = maskObj.getInt("mask"); QQGroup group = store.getGroupByGin(gid); if (group != null) { group.setMask(mask); } } notifyActionEvent(QQActionEvent.Type.EVT_OK, store.getGroupList()); } else { notifyActionEvent(QQActionEvent.Type.EVT_ERROR, null); } }
public override int GetHashCode() { int hash = 1; if (WeiXinCode.Length != 0) { hash ^= WeiXinCode.GetHashCode(); } if (QQGroup.Length != 0) { hash ^= QQGroup.GetHashCode(); } if (WeiXinGroup.Length != 0) { hash ^= WeiXinGroup.GetHashCode(); } return(hash); }
private async void SendLocalPic(Hso hso) { string[] picNames = Directory.GetFiles(IOUtils.GetHsoPath()); if (picNames.Length == 0) { await QQGroup.SendGroupMessage("机器人管理者没有在服务器上塞色图\r\n你去找他要啦!"); return; } Random randFile = new Random(); string localPicPath = $"{picNames[randFile.Next(0, picNames.Length - 1)]}"; Log.Debug("发送图片", localPicPath); await QQGroup.SendGroupMessage(hso.CardImage ?CQCode.CQCardImage(localPicPath) : CQCode.CQImage(localPicPath)); }
/// <summary> /// 签到 /// </summary> private void SignIn() { ConsoleLog.Info("收到消息", "慧酱签到"); SuiseiDBHelper suiseiDB = new SuiseiDBHelper(Sender, SuiseiEventArgs); suiseiDB.SignIn(); SuiseiData userData = suiseiDB.UserData; //数据库查询到的用户数据 //签到成功判断 if (userData.ChatDate == suiseiDB.TriggerTime && suiseiDB.IsExists) //今天已经签到过了 { QQGroup.SendGroupMessage("neeeeeeee\nmooooooo\n今天已经贴过了"); } else //签到 { suiseiDB.FavorRateUp(); QQGroup.SendGroupMessage("奇怪的好感度增加了!\n当前好感度为:", userData.FavorRate); } }
private async void GetGuildRank(string[] commandArgs) { //检查参数 switch (Utils.CheckForLength(commandArgs, 1)) { case LenType.Illegal: await BiliWikiRank(QQGroup.GetGroupInfo().Name); break; case LenType.Legitimate: await BiliWikiRank(commandArgs[1]); break; default: case LenType.Extra: QQGroup.SendGroupMessage("有多余参数"); return; } }
private void toolAddListen_Click(object sender, EventArgs e) { DataGridViewCellCollection cells = this.dgvContact.CurrentRow.Cells; if (cells == null) { return; } long gid = (long)cells["GroupGid"].Value; QQGroup group = QQGlobal.store.GetGroupByGin(gid); if (QQGlobal.listenGroups.Exists((g) => { return(g.Gid == gid); })) { QQGlobal.listenGroups.Remove(group); cells["GroupTitle"].Value = group.Name; } else { QQGlobal.listenGroups.Add(group); cells["GroupTitle"].Value += "(已监控)"; } }
/// <summary> /// 下载图片保存到本地 /// </summary> /// <param name="url">目标URL</param> /// <param name="receivePath">接收文件的地址</param> private void DownloadFileFromURL(string url, string receivePath) { try { int progressPercentage = 0; long bytesReceived = 0; DateTime flashTime = DateTime.Now; Console.WriteLine("开始从网络下载文件"); WebClient client = new WebClient(); //文件下载 client.DownloadProgressChanged += (sender, args) => { if (progressPercentage != args.ProgressPercentage) { progressPercentage = args.ProgressPercentage; ConsoleLog .Debug("Download Pic", $"Downloading {args.ProgressPercentage}% " + $"({(args.BytesReceived - bytesReceived) / 1024.0 / (DateTime.Now - flashTime).TotalSeconds}KB/s) "); flashTime = DateTime.Now; bytesReceived = args.BytesReceived; } }; //文件下载完成 client.DownloadFileCompleted += (sender, args) => { ConsoleLog.Info("Hso", "下载数据成功,发送图片"); QQGroup.SendGroupMessage(CQApi.CQCode_Image(receivePath)); ConsoleLog.Debug("file", Path.GetFileName(receivePath)); }; client.DownloadFileAsync(new Uri(url), receivePath); } catch (Exception e) { ConsoleLog.Error("色图下载失败", $"网络下载数据错误\n{ConsoleLog.ErrorLogBuilder(e)}"); } }
private void KyoukaRank(string guildName) { //网络响应 string response; //获取网络响应 try { //初始化查询JSON JObject clanInfoJson = new JObject { ["clanName"] = guildName, ["history"] = 0 }; ConsoleLog.Info("NET", "尝试查询结果"); //获取查询结果 QQGroup.SendGroupMessage("查询中..."); response = HTTPUtils.PostHttpResponse("https://service-kjcbcnmw-1254119946.gz.apigw.tencentcs.com/name/0", clanInfoJson, "Windows", "application/json", "https://kengxxiao.github.io/Kyouka/", 3000, "BOT"); } catch (Exception e) { QQGroup.SendGroupMessage($"哇哦~发生了网络错误,请联系机器人所在服务器管理员\n{e.Message}"); ConsoleLog.Error("网络发生错误", e); //阻止下一步处理 return; } //JSON数据处理 try { if (string.IsNullOrEmpty(response)) { QQGroup.SendGroupMessage("发生了未知错误,请请向开发者反馈问题"); ConsoleLog.Error("JSON数据读取错误", "从网络获取的文本为空"); return; } ConsoleLog.Info("获取JSON成功", response); JObject responseJObject = JObject.Parse(response); if (responseJObject["full"] == null) { QQGroup.SendGroupMessage("发生了未知错误,请请向开发者反馈问题"); ConsoleLog.Error("JSON数据读取错误", "从网络获取的JSON格式可能有问题"); return; } //在有查询结果时查找值 if (!responseJObject["full"].ToString().Equals("0")) { if (!responseJObject["full"].ToString().Equals("1")) { QQGroup.SendGroupMessage("查询到多个公会,可能存在重名或关键词错误"); } string rank = responseJObject["data"]?[0]?["rank"]?.ToString(); string totalScore = responseJObject["data"]?[0]?["damage"]?.ToString(); string leaderName = responseJObject["data"]?[0]?["leader_name"]?.ToString(); ConsoleLog.Info("JSON处理成功", "向用户发送数据"); QQGroup.SendGroupMessage("查询成功!\n" + $"公会 |{guildName}\n" + $"排名 |{rank}\n" + $"总分数|{totalScore}\n" + $"会长 |{leaderName}\n" + "如果查询到的信息有误,有可能关键词错误或公会排名在20060之后"); } else { QQGroup.SendGroupMessage("未找到任意公会\n请检查是否查询的错误的公会名或公会排名在20060之后"); ConsoleLog.Info("JSON处理成功", "所查询列表为空"); } } catch (Exception e) { QQGroup.SendGroupMessage($"在处理数据时发生了错误,请请向开发者反馈问题\n{e.Message}"); ConsoleLog.Error("JSON数据读取错误", e); } }
public GetGroupFaceAction(IQQContext context, QQActionListener listener, QQGroup group) : base(context, listener) { this._group = group; }
public GetGroupMemberStatusAction(QQContext context, QQActionEventHandler listener, QQGroup group) : base(context, listener) { this.group = group; }
public void DeleteGroup(QQGroup group) { _groupMap.TryRemove(group.Gin, out group); }
public void AddGroup(QQGroup group) { _groupMap.Add(group.Code, group, AddChoice.Update); }
public void AddGroup(QQGroup group) { _groupMap[group.Code] = group; }
/// <summary> /// 获取群成员状态 /// </summary> /// <param name="group"></param> /// <param name="listener"></param> /// <returns></returns> public IQQActionFuture GetGroupMemberStatus(QQGroup group, QQActionListener listener) { var mod = GetModule <GroupModule>(QQModuleType.GROUP); return(mod.GetMemberStatus(group, listener)); }
/// <summary> /// <para>从色图源获取色图</para> /// <para>不会支持R18的哦</para> /// </summary> /// <param name="hso">hso配置实例</param> private async Task GiveMeSetu(Hso hso) { string localPicPath; JObject response; ConsoleLog.Debug("源", hso.Source); //本地模式 if (hso.Source == SetuSourceType.Local) { string[] picNames = Directory.GetFiles(IOUtils.GetHsoPath()); if (picNames.Length == 0) { await QQGroup.SendGroupMessage("机器人管理者没有在服务器上塞色图\r\n你去找他要啦!"); return; } Random randFile = new Random(); localPicPath = $"{picNames[randFile.Next(0, picNames.Length - 1)]}"; ConsoleLog.Debug("发送图片", localPicPath); await QQGroup.SendGroupMessage(hso.CardImage ?CQCode.CQCardImage(localPicPath) : CQCode.CQImage(localPicPath)); return; } //网络部分 try { ConsoleLog.Info("NET", "尝试获取色图"); await QQGroup.SendGroupMessage("正在获取色图中..."); string apiKey; string serverUrl; //源切换 switch (hso.Source) { case SetuSourceType.Mix: Random randSource = new Random(); if (randSource.Next(1, 100) > 50) { serverUrl = "https://api.lolicon.app/setu/"; apiKey = hso.LoliconApiKey ?? string.Empty; } else { serverUrl = "https://api.yukari.one/setu/"; apiKey = hso.YukariApiKey ?? string.Empty; } break; case SetuSourceType.Yukari: serverUrl = "https://api.yukari.one/setu/"; apiKey = hso.YukariApiKey ?? string.Empty; break; case SetuSourceType.Lolicon: serverUrl = "https://api.yukari.one/setu/"; apiKey = hso.YukariApiKey ?? string.Empty; break; default: await QQGroup.SendGroupMessage("发生了未知错误"); ConsoleLog.Error("Hso", "发生了未知错误"); return; } //向服务器发送请求 ReqResponse reqResponse = await Requests.GetAsync(serverUrl, new ReqParams { Timeout = 3000, Params = new Dictionary <string, string> { { "apikey", apiKey } } }); if (reqResponse.StatusCode != HttpStatusCode.OK) { ConsoleLog.Error("Net", $"{serverUrl} return code {(int)reqResponse.StatusCode}"); await HsoEventArgs.SourceGroup.SendGroupMessage($"哇哦~发生了网络错误[{reqResponse.StatusCode}],请联系机器人所在服务器管理员"); return; } response = reqResponse.Json(); ConsoleLog.Debug("Get Json", response); } catch (Exception e) { //网络错误 await QQGroup.SendGroupMessage("哇哦~发生了网络错误,请联系机器人所在服务器管理员"); ConsoleLog.Error("网络发生错误", ConsoleLog.ErrorLogBuilder(e.InnerException)); return; } //json处理 try { if ((int)response["code"] == 0) { //图片链接 string picUrl = response["data"]?[0]?["url"]?.ToString() ?? ""; ConsoleLog.Debug("获取到图片", picUrl); //本地图片存储路径 localPicPath = $"{IOUtils.GetHsoPath()}/{Path.GetFileName(picUrl)}".Replace('\\', '/'); if (File.Exists(localPicPath)) //检查是否已缓存过图片 { await QQGroup.SendGroupMessage(hso.CardImage ?CQCode.CQCardImage(localPicPath) : CQCode.CQImage(localPicPath)); } else { //文件名处理(mirai发送网络图片时pixivcat会返回403暂时无法使用代理发送图片 //QQGroup.SendGroupMessage(CQApi.Mirai_UrlImage(picUrl)); //检查是否有设置代理 if (!string.IsNullOrEmpty(hso.PximyProxy)) { string[] fileNameArgs = Regex.Split(Path.GetFileName(picUrl), "_p"); StringBuilder proxyUrlBuilder = new StringBuilder(); proxyUrlBuilder.Append(hso.PximyProxy); //图片Pid部分 proxyUrlBuilder.Append(hso.PximyProxy.EndsWith("/") ? $"{fileNameArgs[0]}" : $"/{fileNameArgs[0]}"); //图片Index部分 proxyUrlBuilder.Append(fileNameArgs[1].Split('.')[0].Equals("0") ? string.Empty : $"/{fileNameArgs[1].Split('.')[0]}"); ConsoleLog.Debug("Get Proxy Url", proxyUrlBuilder); DownloadFileFromURL(proxyUrlBuilder.ToString(), localPicPath, hso.UseCache, hso.CardImage); } else { DownloadFileFromURL(picUrl, localPicPath, hso.UseCache, hso.CardImage); } } return; } if (((int)response["code"] == 401 || (int)response["code"] == 429) && hso.Source == SetuSourceType.Lolicon) { ConsoleLog.Warning("API Token 失效", $"code:{response["code"]}"); } else { ConsoleLog.Warning("没有找到图片信息", "服务器拒绝提供信息"); } await QQGroup.SendGroupMessage("哇奧色图不见了\n请联系机器人服务器管理员"); } catch (Exception e) { ConsoleLog.Error("色图下载失败", $"网络下载数据错误\n{ConsoleLog.ErrorLogBuilder(e)}"); } }
/// <summary> /// 下载图片保存到本地 /// </summary> /// <param name="url">目标URL</param> /// <param name="receivePath">接收文件的地址</param> /// <param name="useCache">是否启用本地缓存</param> /// <param name="cardImg">使用装逼大图</param> private void DownloadFileFromURL(string url, string receivePath, bool useCache, bool cardImg) { try { int progressPercentage = 0; long bytesReceived = 0; DateTime flashTime = DateTime.Now; Console.WriteLine(@"开始从网络下载文件"); WebClient client = new WebClient(); //文件下载 client.DownloadProgressChanged += (sender, args) => { if (progressPercentage == args.ProgressPercentage) { return; } progressPercentage = args.ProgressPercentage; ConsoleLog .Debug("Download Pic", $"Downloading {args.ProgressPercentage}% " + $"({(args.BytesReceived - bytesReceived) / 1024.0 / ((DateTime.Now - flashTime).TotalMilliseconds / 1000)}KB/s) "); flashTime = DateTime.Now; bytesReceived = args.BytesReceived; }; //文件下载完成 client.DownloadFileCompleted += async(sender, args) => { ConsoleLog.Info("Hso", "下载数据成功,发送图片"); var(code, _) = await QQGroup.SendGroupMessage(cardImg ?CQCode.CQCardImage(receivePath) : CQCode.CQImage(receivePath)); ConsoleLog.Debug("file", Path.GetFileName(receivePath)); if (code == APIStatusType.OK) { ConsoleLog.Info("Hso", "色图发送成功"); } else { ConsoleLog.Error("Hso", $"色图发送失败 code={(int) code}"); await QQGroup.SendGroupMessage($"哇奧色图不见了\r\n色图发送失败了\r\nAPI ERROR [{code}]"); } //检查是否出现空文件 if (code == APIStatusType.OK || !File.Exists(receivePath)) { return; } FileInfo file = new FileInfo(receivePath); ConsoleLog.Debug("File Size Check", file.Length); if (file.Length != 0) { return; } ConsoleLog.Error("Hso", "色图下载失败"); //删除下载失败的文件 try { file.Delete(); } catch (Exception e) { ConsoleLog.Error("IO", ConsoleLog.ErrorLogBuilder(e)); } }; client.DownloadDataCompleted += async(sender, args) => { ConsoleLog.Info("Hso", "下载数据成功,发送图片"); try { StringBuilder ImgBase64Str = new StringBuilder(); ImgBase64Str.Append("base64://"); ImgBase64Str.Append(Convert.ToBase64String(args.Result)); var(code, _) = await QQGroup.SendGroupMessage(cardImg ?CQCode.CQCardImage(ImgBase64Str.ToString()) : CQCode.CQImage(ImgBase64Str.ToString())); if (code == APIStatusType.OK) { ConsoleLog.Info("Hso", "色图发送成功"); } else { ConsoleLog.Error("Hso", $"色图发送失败 code={(int) code}"); await QQGroup.SendGroupMessage($"哇奧色图不见了\r\n色图发送失败了\r\nAPI ERROR [{code}]"); } ConsoleLog.Debug("base64 length", ImgBase64Str.Length); } catch (Exception e) { Console.WriteLine(e); } }; if (useCache) { client.DownloadFileAsync(new Uri(url), receivePath); } else { client.DownloadDataAsync(new Uri(url)); } } catch (Exception e) { ConsoleLog.Error("色图下载失败", $"网络下载数据错误\n{ConsoleLog.ErrorLogBuilder(e)}"); } }
public void DeleteGroup(QQGroup group) { _groupMap.Remove(group.Gin); }
/// <summary> /// 从比利比利源查询排名 /// </summary> private Task BiliWikiRank(string guildName) { string response; //获取响应 try { //获取查询结果 ConsoleLog.Info("NET", $"尝试查询{guildName}会站排名"); QQGroup.SendGroupMessage("查询中..."); response = HTTPUtils .GetHttpResponse($"https://tools-wiki.biligame.com/pcr/getTableInfo?type=search&search={HttpUtility.UrlEncode(guildName)}&page=0"); } catch (Exception e) { QQGroup.SendGroupMessage("哇哦~发生了网络错误,请联系机器人所在服务器管理员"); ConsoleLog.Error("网络发生错误", ConsoleLog.ErrorLogBuilder(e)); //阻止下一步处理 return(Task.CompletedTask); } //JSON数据处理 try { if (string.IsNullOrEmpty(response)) { QQGroup.SendGroupMessage("发生了未知错误,请请向开发者反馈问题"); ConsoleLog.Error("JSON数据读取错误", "从网络获取的文本为空"); return(Task.CompletedTask); } ConsoleLog.Debug("获取JSON成功", response); JArray responseJArray = JArray.Parse(response); //对返回值进行判断 if (responseJArray.Count == 0) { QQGroup.SendGroupMessage("未找到任意公会\n请检查是否查询的错误的公会名或公会排名在70000之后"); ConsoleLog.Info("JSON处理成功", "所查询列表为空"); return(Task.CompletedTask); } if (responseJArray.Count > 1) { QQGroup.SendGroupMessage("查询到多个公会,可能存在重名或关键词错误"); } if (responseJArray[0] is JObject rankData) { string rank = rankData["rank"]?.ToString(); string totalScore = rankData["damage"]?.ToString(); string leaderName = rankData["leader_name"]?.ToString(); ConsoleLog.Info("JSON处理成功", "向用户发送数据"); QQGroup.SendGroupMessage("查询成功!\n" + $"公会:{guildName}\n" + $"排名:{rank}\n" + $"总分数:{totalScore}\n" + $"会长:{leaderName}\n" + "如果查询到的信息有误,有可能关键词错误或公会排名在70000之后"); } } catch (Exception e) { QQGroup.SendGroupMessage("发生了未知错误,请请向开发者反馈问题"); ConsoleLog.Error("JSON数据读取错误", $"从网络获取的JSON格式无法解析{ConsoleLog.ErrorLogBuilder(e)}"); return(Task.CompletedTask); } return(Task.CompletedTask); }
public GetGroupMemberStatusAction(IQQContext context, QQActionListener listener, QQGroup group) : base(context, listener) { _group = group; }