Skip to content

Commit dc41b19

Browse files
author
lixiaopei
committed
vbot升级到2.0以上
1 parent 074a8c9 commit dc41b19

File tree

7 files changed

+114
-24
lines changed

7 files changed

+114
-24
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
!/log/.gitignore
44
composer.lock
55
example
6+
/tmp
7+
68

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"require": {
88
"php": ">=7.0",
99
"ext-swoole": ">=1.8.9",
10-
"hanson/vbot": "dev-dev"
10+
"hanson/vbot": ">=2.0"
1111
},
1212
"authors": [
1313
{

log/.gitignore

-1
This file was deleted.

src/Process.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/*
44
* This file is part of PHP CS Fixer.
5-
* (c) kcloze <pei.greet@qq.com>
5+
* (c) php-team@yaochufa <php-team@yaochufa.com>
66
* This source file is subject to the MIT license that is bundled
77
* with this source code in the file LICENSE.
88
*/
@@ -19,7 +19,7 @@ class Process
1919

2020
public function start($config)
2121
{
22-
\Swoole\Process::daemon();
22+
//\Swoole\Process::daemon();
2323
$this->config = $config;
2424
//开启多个进程消费队列
2525
for ($i = 0; $i < $this->workNum; $i++) {
@@ -39,7 +39,7 @@ public function reserveBot($workNum)
3939
//设置进程名字
4040
$this->setProcessName('job ' . $workNum . $self::PROCESS_NAME_LOG);
4141
try {
42-
$job = new Robot($self->config);
42+
$job = new Robots($self->config);
4343
$job->run();
4444
} catch (Exception $e) {
4545
echo $e->getMessage();
@@ -77,7 +77,7 @@ public function registSignal($workers)
7777

7878
private function exitMaster()
7979
{
80-
@unlink($this->config['logPath'] . '/master.pid.log');
80+
@unlink($this->config['log']['system'] . '/master.pid.log');
8181
$this->log('Time: ' . microtime(true) . '主进程退出' . "\n");
8282
exit();
8383
}
@@ -97,6 +97,6 @@ private function setProcessName($name)
9797

9898
private function log($txt)
9999
{
100-
file_put_contents($this->config['logPath'] . '/worker.log', $txt . "\n", FILE_APPEND);
100+
file_put_contents($this->config['log']['system'].'/worker.log', $txt . "\n", FILE_APPEND);
101101
}
102102
}

src/Robots.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* This file is part of PHP CS Fixer.
5+
* (c) php-team@yaochufa <[email protected]>
6+
* This source file is subject to the MIT license that is bundled
7+
* with this source code in the file LICENSE.
8+
*/
9+
10+
namespace Kcloze\Bot;
11+
12+
class Robots
13+
{
14+
private $robot;
15+
private $options;
16+
17+
public function __construct($options)
18+
{
19+
$this->robot = new \Hanson\Vbot\Foundation\Vbot($options);
20+
$this->options =$options;
21+
}
22+
23+
public function run()
24+
{
25+
$this->robot->messageHandler->setHandler(function ($message) {
26+
\Hanson\Vbot\Message\Text::send($message['from']['UserName'], 'Hi, I\'m Vbot!');
27+
});
28+
$this->robot->server->serve();
29+
}
30+
}

src/config.php

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
/*
4+
* This file is part of PHP CS Fixer.
5+
* (c) php-team@yaochufa <[email protected]>
6+
* This source file is subject to the MIT license that is bundled
7+
* with this source code in the file LICENSE.
8+
*/
9+
$path = __DIR__ . '/../tmp/';
10+
return $options = [
11+
'path' => $path,
12+
/*
13+
* swoole 配置项(执行主动发消息命令必须要开启,且必须安装 swoole 插件)
14+
*/
15+
'swoole' => [
16+
'status' => true,
17+
'ip' => '127.0.0.1',
18+
'port' => '8866',
19+
],
20+
/*
21+
* 下载配置项
22+
*/
23+
'download' => [
24+
'image' => true,
25+
'voice' => true,
26+
'video' => true,
27+
'emoticon' => true,
28+
'file' => true,
29+
'emoticon_path' => $path . 'emoticons', // 表情库路径(PS:表情库为过滤后不重复的表情文件夹)
30+
],
31+
/*
32+
* 输出配置项
33+
*/
34+
'console' => [
35+
'output' => true, // 是否输出
36+
'message' => true, // 是否输出接收消息 (若上面为 false 此处无效)
37+
],
38+
/*
39+
* 日志配置项
40+
*/
41+
'log' => [
42+
'level' => 'debug',
43+
'permission' => 0777,
44+
'system' => $path . 'log', // 系统报错日志
45+
'message' => $path . 'log', // 消息日志
46+
],
47+
/*
48+
* 缓存配置项
49+
*/
50+
'cache' => [
51+
'default' => 'file', // 缓存设置 (支持 redis 或 file)
52+
'stores' => [
53+
'file' => [
54+
'driver' => 'file',
55+
'path' => $path . 'cache',
56+
],
57+
'redis' => [
58+
'driver' => 'redis',
59+
'connection' => 'default',
60+
],
61+
],
62+
],
63+
/*
64+
* 拓展配置
65+
* ==============================
66+
* 如果加载拓展则必须加载此配置项
67+
*/
68+
'extension' => [
69+
// 管理员配置(必选),优先加载 remark_name
70+
'admin' => [
71+
'remark' => '',
72+
'nickname' => '',
73+
],
74+
],
75+
];

src/start.php

+1-17
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,7 @@
1212

1313
require __DIR__ . '/../vendor/autoload.php';
1414

15-
$config = [
16-
17-
'logPath' => __DIR__ . '/../log',
18-
'debug' => true,
19-
'params' => [
20-
//图灵机器人api
21-
'tulingApi'=> 'http://www.tuling123.com/openapi/api',
22-
'tulingKey'=> '1dce02aef026258eff69635a06b0ab7d',
23-
24-
'nickname' => 'web开发',
25-
//管理员微信号
26-
'adminAlias'=> 'kcloze',
27-
//暗号
28-
'cipher' => '666',
29-
],
30-
31-
];
15+
$config = require_once __DIR__ . '/config.php';
3216

3317
//启动
3418
$process = new Kcloze\Bot\Process();

0 commit comments

Comments
 (0)