コード例 #1
0
        /// <summary>
        /// 本地图片拉取
        /// </summary>
        /// <param name="ls"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public static SendText LocalPic_Image(string orderText, long GroupID, long QQID)
        {
            SendText     result = new SendText();
            CustomObject item   = LocalPicOrderList.Where(x => x.Order == orderText)
                                  .OrderBy(_ => Guid.NewGuid()).First();

            result.HandlingFlag = item.AutoRevoke;
            try
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(item.Path);
                FileInfo[]    fileInfos     = directoryInfo.GetFiles("*.*")
                                              .Where(x => x.FullName.EndsWith("jpg") || x.FullName.EndsWith("gif") ||
                                                     x.FullName.EndsWith("png") || x.FullName.EndsWith("bmp") ||
                                                     x.FullName.EndsWith("webp") || x.FullName.EndsWith("tif") || x.FullName.EndsWith("tga")).ToArray();
                //随机取一个
                var    picinfo       = fileInfos.OrderBy(_ => Guid.NewGuid()).First();
                string picpathOrigin = picinfo.FullName;
                if (!Directory.Exists(MainSave.ImageDirectory + "\\LocalPic"))
                {
                    Directory.CreateDirectory(MainSave.ImageDirectory + "\\LocalPic");
                }
                string picpathFinal = MainSave.ImageDirectory + "\\LocalPic\\" + picinfo.Name;
                if (!File.Exists(picpathFinal))
                {
                    File.Copy(picpathOrigin, picpathFinal);
                }
                MainSave.CQLog.Info("本地图片接口", $"图片获取成功,尝试发送");
                CommonHelper.AntiHX(picpathFinal);
                string imageCQCodePath = Path.Combine("LocalPic", picinfo.Name);
                result.MsgToSend.Add(CQApi.CQCode_Image(imageCQCodePath).ToSendString());
                return(result);
            }
            catch (Exception exc)
            {
                result.MsgToSend.Add("本地图片接口调用失败");
                MainSave.CQLog.Info("本地图片接口", $"调用失败,错误信息:{exc.Message}");
                if (item.Usestrict)
                {
                    QuotaHelper.PlusMemberQuota(GroupID, QQID);
                }
                return(result);
            }
        }
コード例 #2
0
        public FunctionResult Progress(CQGroupMessageEventArgs e)
        {
            FunctionResult result = new FunctionResult()
            {
                Result   = true,
                SendFlag = false,
            };

            //检查额度限制
            if (QuotaHelper.QuotaCheck(e.FromGroup, e.FromQQ) is false)
            {
                return(result);
            }
            //拉取图片,处理时间受地区与网速限制
            var pic = GetLoliConPicHelper
                      .GetSetuPic(e.Message.Text.Substring(GetOrderStr().Length), out string objectTostring);

            pic.SendID = e.FromGroup.Id;
            try
            {
                SendText text = new SendText
                {
                    MsgToSend = new List <string>(),
                    SendID    = e.FromGroup,
                };
                objectTostring.Replace("<@>", e.FromQQ.CQCode_At().ToSendString());
                // 处理返回文本,替换可配置文本为结果,发送处理结果
                if (!string.IsNullOrWhiteSpace(objectTostring))
                {
                    text.MsgToSend.Add(objectTostring);
                }
                result.SendObject.Add(text);
                result.SendFlag = true;
                IniConfig ini = MainSave.ConfigMain;
                if (pic.HandlingFlag)//是否成功处理消息
                {
                    //TODO: Improve this code
                    //处理一番后发现, 成功发送时只有一个图片文本, 虽说不规范, 以后再说吧
                    var msg = e.FromGroup.SendGroupMessage(pic.MsgToSend[0]);
                    if (PublicVariables.R18_PicRevoke)//自动撤回
                    {
                        Task task = new Task(() =>
                        {
                            Thread.Sleep(PublicVariables.R18_RevokeTime * 1000);
                            e.CQApi.RemoveMessage(msg.Id);
                        }); task.Start();
                    }
                }
                else//处理消息失败
                {
                    result.SendFlag = true;
                    result.SendObject.Add(pic);
                    QuotaHelper.PlusMemberQuota(e.FromGroup.Id, e.FromQQ.Id);
                }
            }
            catch (Exception exc)
            {
                SendText text = new SendText
                {
                    MsgToSend = new List <string>(),
                    SendID    = e.FromGroup,
                };
                text.MsgToSend.Add($"发生未知错误,错误信息:在{exc.Source}上, 发生错误: {exc.Message}");
                result.SendObject.Add(text);
                result.SendFlag = true;
            }
            return(result);
        }