diff --git a/src/cqbot/mods/Entertain.php b/src/cqbot/mods/Entertain.php new file mode 100644 index 00000000..234ce4ae --- /dev/null +++ b/src/cqbot/mods/Entertain.php @@ -0,0 +1,27 @@ +reply("你好,我是CQBot!"); + return true; + case "robot": + $this->reply("机器人!\n机器人!"); + return true; + } + return false; + } +} \ No newline at end of file diff --git a/src/cqbot/mods/Example.php b/src/cqbot/mods/Example.php index ee9e3c7c..4bf7e5d4 100644 --- a/src/cqbot/mods/Example.php +++ b/src/cqbot/mods/Example.php @@ -19,6 +19,67 @@ class Example extends ModBase case "ping": $this->reply("pong"); return true; + case "王境泽动图": + $msg_help = "【王境泽动图帮助】"; + $msg_help .= "\n用法1:\n王境泽动图 第一句 第二句 第三句 第四句"; + $msg_help .= "\n[如果需要输入空格的话,用下面的方法]"; + $msg_help .= "\n王境泽动图 多行\n第一句\n第二句\n第三句\n第四句"; + $api = "https://sorry.xuty.tk/api/wangjingze/make"; + if (strstr($it[1], "\n") === false && count($it) < 5) { + $this->reply($msg_help); + return true; + } + array_shift($it); + if (mb_substr($it[0], 0, 2) == "多行") { + $ms = implode(" ", $it); + $ms = mb_substr($ms, 2); + $ms = trim($ms); + $ms = explode("\n", $ms); + if (count($ms) < 4) { + $this->reply($msg_help); + return true; + } + $content = [ + "3" => $ms[3], + "2" => $ms[2], + "1" => $ms[1], + "0" => $ms[0] + ]; + } elseif (count($it) >= 4) { + $content = [ + "3" => $it[3], + "0" => $it[0], + "1" => $it[1], + "2" => $it[2] + ]; + } else { + $this->reply($msg_help); + return true; + } + $opts = array('http' => array('method' => 'POST', 'header' => 'Content-Type: application/json; charset=utf-8', 'content' => json_encode($content, JSON_UNESCAPED_UNICODE))); + $context = stream_context_create($opts); + $this->reply("正在生成,请稍等"); + $result = file_get_contents($api, false, $context); + if ($result == false) { + $this->reply("抱歉,请求失败,请过一会儿再试吧~"); + return true; + } + $result = "https://sorry.xuty.tk" . $result; + $this->reply("[CQ:image,file=" . $result . "]"); + return true; + case "随机数": + if (!isset($it[1]) || !isset($it[2])) { + $this->reply("用法: 随机数 开始整数 结束整数"); + return true; + } + $c1 = intval($it[1]); + $c2 = intval($it[2]); + if ($c1 > $c2) { + $this->reply("随机数范围错误!应该从小的一方到大的一方!例如:\n随机数 1 99"); + return true; + } + $this->reply("生成的随机数是 " . mt_rand($c1, $c2)); + return true; case "test": $this->reply("Hello world"); return true; diff --git a/src/cqbot/mods/Help.php b/src/cqbot/mods/Help.php new file mode 100644 index 00000000..64ff98b9 --- /dev/null +++ b/src/cqbot/mods/Help.php @@ -0,0 +1,35 @@ +reply($msg); + return true; + case "如何增加机器人功能": + $msg = "机器人功能是在框架中src/cqbot/mods/xxx.php文件中编写的。"; + $msg .= "CQBot采用关键词系统,你可以直接像现有源码一样添加case在switch里面,"; + $msg .= "也可以自己新建一个任意名称的Mod名称,例如Entertain.php,你可以在里面编写娱乐功能。"; + $msg .= "你可以直接复制框架中Entertain.php文件的内容进行编辑。"; + $msg .= "你也可以在tasks/Scheduler.php中tick函数里添加自己的定时执行的功能。"; + $msg .= "预先封装好的机器人函数均在CQUtil类中,只需直接使用静态方法调用即可!"; + $msg .= "更多示例功能会逐渐添加到框架中,记得更新哦~"; + $this->reply($msg); + return true; + } + return false; + } +} \ No newline at end of file diff --git a/src/cqbot/tasks/Scheduler.php b/src/cqbot/tasks/Scheduler.php index f8436ddf..9e2af310 100644 --- a/src/cqbot/tasks/Scheduler.php +++ b/src/cqbot/tasks/Scheduler.php @@ -27,7 +27,9 @@ class Scheduler } public function tick($id, $tick_time) { + //900秒执行一次文件保存功能 if($tick_time - $this->framework->run_time % 900 == 0) CQUtil::saveAllFiles(); + //这里添加计时器上处理的内容 } } \ No newline at end of file