Skip to content

Commit

Permalink
v3.1.8 Demo 基於內置定時任務的整點語音報時
Browse files Browse the repository at this point in the history
  • Loading branch information
OPQBOT committed Sep 8, 2020
1 parent 3e8bd92 commit 3f56b7f
Show file tree
Hide file tree
Showing 26 changed files with 47 additions and 6 deletions.
Binary file added .DS_Store
Binary file not shown.
53 changes: 47 additions & 6 deletions Plugins/CronDemo1.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,42 @@ local Api = require("coreApi")
local json = require("json")
local http = require("http")
local mysql = require("mysql")
--该插件运行在CronSchedules目录下 食用请注意

--语音整点报时 cron 0 0 */1 * * ?每小时执行一次
function TimeReport(CurrentQQ, task)
log.info("%s", "\n TimeReport")

FromGroupIdArr = {987654321,123456789}
--启用报时的群数组 如果想动态添加可以考虑本地配置文件或mysql
NowHour = os.date("%H", os.time())
--取当前小时
TimePath = string.format("./Plugins/TimeSilk/%s_00.silk", NowHour)
--拼接文件路径
res = ReadAll(TimePath)
--读入文件
base64 = PkgCodec.EncodeBase64(res)
--将音频文件base64编码
len = #FromGroupIdArr
for i = 1, len, 1 do
Api.Api_SendMsg(
--发送语音
CurrentQQ,
{
toUser = FromGroupIdArr[i],
sendToType = 2,
sendMsgType = "VoiceMsg",
voiceBase64Buf = base64
}
)
end
log.info("TimeReport.lua Log\n%s", TimePath)
return 1 --返回个任意整数即可
end

--定时指定的群 发送消息
function ScheduleJobOne(CurrentQQ, task)
log.info("%s", "\n ScheduleJobOne")
SendGroupText(CurrentQQ, 123456789, "dojob")
SendGroupText(CurrentQQ, 960839480, "dojob")
str = string.format("%s%s task ticks %d taskid %d", "ScheduleJobOne", "done", task.Ticks, task.TaskID)
log.info("Crondemo1.lua Log\n%s", str)
return 1 --返回个任意整数即可
Expand All @@ -19,7 +50,7 @@ function ScheduleJobTwo(CurrentQQ, task)
-- 取结果
local ls = ts:read("*all")
--os.execute("ping 192.168.1") --不担心结果 执行即可 尽量不要执行耗时或卡死的命令
SendGroupText(CurrentQQ, 123456789, ls)
SendGroupText(CurrentQQ, 960839480, ls)
--结果上报到群
str = string.format("%s%s task ticks %d taskid %d", "ScheduleJobTwo", "done", task.Ticks, task.TaskID)
log.info("Crondemo1.lua Log\n%s", str)
Expand All @@ -32,7 +63,7 @@ function TaskOne(CurrentQQ, task)
local html = response.body
local j = json.decode(html)
--解码json
SendGroupText(CurrentQQ, 123456789, j.errmsg)
SendGroupText(CurrentQQ, 960839480, j.errmsg)
--结果上报到群
str = string.format("%s%s task ticks %d taskid %d", "TaskOne", "done", task.Ticks, task.TaskID)
log.info("Crondemo1.lua Log\n%s", str)
Expand All @@ -45,14 +76,14 @@ function TaskTwo(CurrentQQ, task)

if task.Ticks == 2 then --执行2次后 就删除任务
resp = Api.Api_DelCrons(task.TaskID)
SendGroupText(CurrentQQ, 123456789, resp.Msg)
SendGroupText(CurrentQQ, 960839480, resp.Msg)
return 1
end
response, error_message = http.request("GET", "https://v0.yiketianqi.com/api")
local html = response.body
local j = json.decode(html)
--解码json
SendGroupText(CurrentQQ, 123456789, j.errmsg)
SendGroupText(CurrentQQ, 960839480, j.errmsg)
--结果上报到群
str = string.format("%s%s task ticks %d taskid %d", "TaskTwo", "done", task.Ticks, task.TaskID)
log.info("Crondemo1.lua Log\n%s", str)
Expand All @@ -70,3 +101,13 @@ function SendGroupText(CurrentQQ, toUid, content)
}
)
end

function ReadAll(filePath)
local f, err = io.open(filePath, "rb")
if err ~= nil then
return nil
end
local content = f:read("*all")
f:close()
return content
end
Binary file added Plugins/TimeSilk/00_00.silk
Binary file not shown.
Binary file added Plugins/TimeSilk/01_00.silk
Binary file not shown.
Binary file added Plugins/TimeSilk/02_00.silk
Binary file not shown.
Binary file added Plugins/TimeSilk/03_00.silk
Binary file not shown.
Binary file added Plugins/TimeSilk/04_00.silk
Binary file not shown.
Binary file added Plugins/TimeSilk/05_00.silk
Binary file not shown.
Binary file added Plugins/TimeSilk/06_00.silk
Binary file not shown.
Binary file added Plugins/TimeSilk/07_00.silk
Binary file not shown.
Binary file added Plugins/TimeSilk/08_00.silk
Binary file not shown.
Binary file added Plugins/TimeSilk/09_00.silk
Binary file not shown.
Binary file added Plugins/TimeSilk/10_00.silk
Binary file not shown.
Binary file added Plugins/TimeSilk/11_00.silk
Binary file not shown.
Binary file added Plugins/TimeSilk/12_00.silk
Binary file not shown.
Binary file added Plugins/TimeSilk/13_00.silk
Binary file not shown.
Binary file added Plugins/TimeSilk/14_00.silk
Binary file not shown.
Binary file added Plugins/TimeSilk/15_00.silk
Binary file not shown.
Binary file added Plugins/TimeSilk/16_00.silk
Binary file not shown.
Binary file added Plugins/TimeSilk/17_00.silk
Binary file not shown.
Binary file added Plugins/TimeSilk/18_00.silk
Binary file not shown.
Binary file added Plugins/TimeSilk/19_00.silk
Binary file not shown.
Binary file added Plugins/TimeSilk/20_00.silk
Binary file not shown.
Binary file added Plugins/TimeSilk/21_00.silk
Binary file not shown.
Binary file added Plugins/TimeSilk/22_00.silk
Binary file not shown.
Binary file added Plugins/TimeSilk/23_00.silk
Binary file not shown.

0 comments on commit 3f56b7f

Please sign in to comment.