Skip to content

Commit

Permalink
改造搜番接口以适应sdk更改,去除搜图功能
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxuuu committed May 24, 2019
1 parent fb75a73 commit aea7a63
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 99 deletions.
6 changes: 3 additions & 3 deletions appdata/lua/require/app/animeSearch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
local key = apiXmlGet("settings","trace.moe")

return function (msg)
local imageUrl = apiGetImageUrl(msg)--获取图片链接
if imageUrl == "" then return "未在消息中过滤出图片" end
local base64 = apiBase64File(imageUrl)--获取base64结果
local imagePath = apiGetImagePath(msg)--获取图片路径
if imagePath == "" then return "未在消息中过滤出图片" end
local base64 = apiBase64File(imagePath)--获取base64结果
local html = apiHttpPost("https://trace.moe/api/search?token="..key,
"image=data:image/jpeg;base64,"..base64,15000)
if not html or html:len() == 0 then
Expand Down
39 changes: 0 additions & 39 deletions appdata/lua/require/app/hitokoto.lua

This file was deleted.

26 changes: 0 additions & 26 deletions appdata/lua/require/app/messageSolve.lua
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,6 @@ local apps = {
return "[CQ:emoji,id=128444]查动画 加 没裁剪过的视频截图"
end
},
{--搜图
check = function ()
return msg:find("搜图") or msg:find("查图")
end,
run = function ()
local imageSearch = require("app.imageSearch")
sendMessage(cqCode_At(qq).."\r\n"..imageSearch(msg))
return true
end,
explain = function ()
return "[CQ:emoji,id=128444]搜图 加 完整p站图片"
end
},
{--象棋
check = function ()
return msg:find("象棋") == 1
Expand Down Expand Up @@ -248,19 +235,6 @@ local apps = {
return "[CQ:emoji,id=9728]签到"
end
},
{--直链
check = function ()
return msg:find("直链") == 1
end,
run = function ()
local reply = apiGetImageUrl(msg)
sendMessage(reply == "" and "未过滤出图片" or reply)
return true
end,
explain = function ()
return "[CQ:emoji,id=128247]直链+图片"
end
},
{--b站av号解析
check = function ()
return msg:find("av%d+")
Expand Down
34 changes: 8 additions & 26 deletions com.papapoi.ReceiverMeow/Native.Csharp/App/LuaEnv/LuaApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,16 @@ public static string GetPath()
}

/// <summary>
/// 获取qq消息中图片的网址
/// 获取qq消息中图片的路径
/// </summary>
/// <param name="image">图片字符串,如“[CQ:image,file=123123]”</param>
/// <returns>网址</returns>
public static string GetImageUrl(string image)
public static string GetImagePath(string image)
{
string fileName = Tools.Reg_get(image, "\\[CQ:image,file=(?<name>.*?)\\]", "name") + ".cqimg";//获取文件名
if (File.Exists(AppDomain.CurrentDomain.SetupInformation.ApplicationBase +
@"data\image\" + fileName))
return Tools.Reg_get(File.ReadAllText(AppDomain.CurrentDomain.SetupInformation.ApplicationBase +
@"data\image\" + fileName).Replace("\r", "").Replace("\n", ""),
"url=(?<name>.*?)addtime=", "name");//过滤出图片网址
return "";//没这个文件
string fileName = Tools.Reg_get(image, "\\[CQ:image,file=(?<name>.*?)\\]", "name");//获取文件
if (fileName == "")
return "";
return Common.CqApi.ReceiveImage(fileName);
}


Expand Down Expand Up @@ -284,26 +281,11 @@ public static string HttpPost(string Url, string postDataStr, int timeout = 5000
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public static string Base64File(string url)
public static string Base64File(string path)
{
try
{
//请求前设置一下使用的安全协议类型 System.Net
if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
{
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback((object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) =>
{
return true; //总是接受
});
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
}
//获取网址里的图片
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
WebResponse response = request.GetResponse();
request.Timeout = 15000;
Stream stream = response.GetResponseStream();

Bitmap bmp = new Bitmap(stream);
Bitmap bmp = new Bitmap(path);
MemoryStream ms = new MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] arr = new byte[ms.Length];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public static void Initial(NLua.Lua lua)
lua.RegisterFunction("apiGetDir", null, typeof(LuaApi).GetMethod("GetDir"));
//保存并获取图片路径

lua.RegisterFunction("apiGetImageUrl", null, typeof(LuaApi).GetMethod("GetImageUrl"));
lua.RegisterFunction("apiGetImagePath", null, typeof(LuaApi).GetMethod("GetImagePath"));
//获取qq消息中图片的网址

lua.RegisterFunction("apiHttpDownload", null, typeof(LuaApi).GetMethod("HttpDownload"));
Expand Down
24 changes: 20 additions & 4 deletions com.papapoi.ReceiverMeow/Native.Csharp/App/LuaEnv/TimerRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ public static void TimerStart()
start = true;
System.Timers.Timer timer = new System.Timers.Timer();
timer.Enabled = true;
timer.Interval = 1000;// 执行间隔时间, 单位为毫秒
timer.Interval = 1000;//1s
timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer1_Elapsed);
timer.Start();

System.Timers.Timer timer2 = new System.Timers.Timer();
timer2.Enabled = true;
timer2.Interval = 60000;//1m
timer2.Elapsed += new System.Timers.ElapsedEventHandler(Timer2_Elapsed);
timer2.Start();
}

public static void Timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e) //定时程序
public static void Timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e) //1s定时程序
{
// 得到 hour minute second 如果等于某个值就开始执行某个程序。
int intHour = e.SignalTime.Hour;
Expand All @@ -31,6 +37,13 @@ public static void Timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs

if (intSecond == 0)//每分钟执行脚本
LuaEnv.RunLua("", "envent/TimerMinute.lua");
}

public static void Timer2_Elapsed(object sender, System.Timers.ElapsedEventArgs e) //1m定时程序
{
// 得到 hour minute second 如果等于某个值就开始执行某个程序。
int intHour = e.SignalTime.Hour;
int intMinute = e.SignalTime.Minute;

//删除过期图片文件
DirectoryInfo downloadDir = new DirectoryInfo(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "data/image/");
Expand All @@ -39,10 +52,13 @@ public static void Timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs
{
FileInfo file = downloadFiles[i] as FileInfo;
//是文件
if (file != null && file.Name.IndexOf(".luatemp") == file.Name.Length - (".luatemp").Length)
if (file != null && file.Name.IndexOf(".luatemp") == file.Name.Length - (".luatemp").Length ||
file != null && file.Name.IndexOf(".jpg") == file.Name.Length - (".jpg").Length ||
file != null && file.Name.IndexOf(".png") == file.Name.Length - (".png").Length ||
file != null && file.Name.IndexOf(".gif") == file.Name.Length - (".gif").Length)
{
TimeSpan time = DateTime.Now - file.CreationTime;
if (time.TotalSeconds > 60)
if (time.TotalSeconds > 120)
file.Delete();
}
}
Expand Down

0 comments on commit aea7a63

Please sign in to comment.