├── .gitignore ├── LICENSE ├── README.md ├── composer.json └── src └── Tuling.php /.gitignore: -------------------------------------------------------------------------------- 1 | composer.phar 2 | /vendor/ 3 | 4 | # Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file 5 | # You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file 6 | # composer.lock 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Vbot 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tuling 2 | [Vbot](https://github.com/hanson/vbot) 聊天机器人扩展,开启好友陪聊模式,注意:好友聊天自动回复,群聊中需要被@ 才自动回复。 3 | 4 | 机器人除了聊天,自带“智能工具”(如数学计算、问答百科、中英互译)、“休闲娱乐”(如成语接龙、讲故事、讲笑话、星座运势)和“生活服务”(如天气查询、快递查询)功能,直接聊天提问就行。 5 | 6 | ## 安装 7 | 8 | ``` 9 | composer require vbot/tuling 10 | ``` 11 | 12 | 详细安装示例看Vbot官方文档[扩展](http://create.hanc.cc/vbot/docs/extension.html)部分 13 | 14 | ## 扩展属性 15 | 16 | ```php 17 | name: tuling 18 | zhName: 图灵机器人 19 | author: 雪风 20 | ``` 21 | 22 | ## 触发关键字 23 | 24 | 开启后所有聊天对话自动触发,特殊功能需要什么直接问就好,以下为部分特殊功能关键词示例: 25 | * `数字计算`:“2乘2”、“2开根号”、“8的阶乘” 26 | * `问答互动`:“周杰伦是谁”、“给我讲个故事”、“说个笑话吧” 27 | * `中英互译`:“苹果用英语怎么说”、“苹果英语怎么说”、“英语说苹果” 28 | * `成语接龙`:“成语接龙”、“我要玩成语接龙” 29 | * `快递查询`:“查快递 3803030087242” 30 | 31 | ## 扩展配置 32 | 33 | 可以不自定义配置,所有配置为可选项^_^ 34 | 35 | * `status` - (可选)聊天机器人开关,默认为 `true`,管理员可以向机器人回复 `tuling on/off` 开关 36 | * `key` - (可选)图灵机器人APIkey,如果需要自定义机器人请换成自己的图灵APIKey 37 | * `error_message` - (可选)服务异常时的提示,默认值为 `图灵机器人失灵了,暂时没法陪聊了,T_T!` 38 | 39 | ```php 40 | // 配置示范 41 | 'tuling' => [ 42 | 'status' => true, 43 | 'key' => '2b700ebfec6593f3e2f452b3bcb8be6e', 44 | 'error_message' => '图灵机器人失灵了,暂时没法陪聊了,T_T!', 45 | ], 46 | ``` 47 | 48 | ## 扩展负责人 49 | 50 | [雪风](https://github.com/oiuv) 51 | 52 | i@oiuv.cn -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vbot/tuling", 3 | "description": "Vbot 自动聊天机器人", 4 | "keywords": [ 5 | "Vbot", 6 | "图灵机器人", 7 | "聊天机器人" 8 | ], 9 | "license": "MIT", 10 | "authors": [ 11 | { 12 | "name": "Xuefeng", 13 | "email": "i@oiuv.cn" 14 | } 15 | ], 16 | "require": { 17 | "vbot/http": "^1.0" 18 | }, 19 | "require-dev": { 20 | "hanson/vbot": "^2.0" 21 | }, 22 | "autoload": { 23 | "psr-4": { 24 | "Vbot\\Tuling\\": "src/" 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Tuling.php: -------------------------------------------------------------------------------- 1 | true, 32 | 'api' => 'http://www.tuling123.com/openapi/api', 33 | 'key' => '2b700ebfec6593f3e2f452b3bcb8be6e', 34 | 'error_message' => '图灵机器人失灵了,暂时没法陪聊了,T_T!', 35 | ]; 36 | $this->config = array_merge($default_config, $this->config ?? []); 37 | $this->status = $this->config['status']; 38 | } 39 | 40 | public function handler(Collection $message) 41 | { 42 | if ($this->config['status'] && $message['type'] === 'text' && ($message['fromType'] === 'Friend' || $message['isAt'])) { 43 | $username = $message['from']['UserName']; 44 | $options = [ 45 | 'form_params' => [ 46 | 'key' => $this->config['key'], 47 | 'info' => $message['pure'], 48 | 'userid' => $message['from']['NickName'] 49 | ] 50 | ]; 51 | try { 52 | $response = Http::request('POST', $this->config['api'], $options); 53 | vbot('console')->log($response, '图灵消息'); 54 | $data = json_decode($response); 55 | switch ($data->code) { 56 | case 100000: 57 | return Text::send($username, $data->text); 58 | case 200000: 59 | return Text::send($username, "$data->text :$data->url"); 60 | default: 61 | return Text::send($username, $this->config['error_message']); 62 | } 63 | } catch (\Exception $e) { 64 | vbot('console')->log($e->getMessage(), Console::ERROR); 65 | return Text::send($username, $this->config['error_message']); 66 | } 67 | } 68 | } 69 | } --------------------------------------------------------------------------------