Skip to content
This repository has been archived by the owner on Nov 22, 2019. It is now read-only.

Commit

Permalink
Merge pull request #69 from kj415j45/patch-2.4
Browse files Browse the repository at this point in the history
Update to 2.5
  • Loading branch information
kj415j45 authored Jul 18, 2018
2 parents 1640e8d + 1315ddb commit 313a944
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 40 deletions.
21 changes: 0 additions & 21 deletions Open Source Licenses/kilingzhang/coolq-php-sdk/LICENSE

This file was deleted.

15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ kjBot 是一个轻量级多功能的酷Q机器人框架。

```
/
|--Open Source Licenses/ #存放开源许可证
|--SDK/ #kjBot\SDK
|--public/
|--tools/ #各类开放函数的文件
Expand Down Expand Up @@ -82,6 +81,20 @@ if(!fromGroup()){ //如果消息不是来自群聊

![](https://user-images.githubusercontent.com/18349191/42219471-99b181e4-7efe-11e8-92a8-20535f40d126.png)

## 感谢

- [richardchien/coolq-http-api](https://github.com/richardchien/coolq-http-api)
- 酷Q 与许多 Bot 之间的桥梁
- [kilingzhang/coolq-php-sdk](https://github.com/kilingzhang/coolq-php-sdk)
- 本项目的起源
- [kj415j45/jkBot](https://github.com/kj415j45/jkBot)
- 本项目的零代
- 贡献者
- [Cyanoxygen](https://github.com/Cyanoxygen)
- [Baka-D](https://github.com/Baka-D)
- [lslqtz](https://github.com/lslqtz)
- [LovelyA72](https://github.com/LovelyA72)

## LICENSE

kjBot 框架及 SDK 均为 MIT 协议。但是模块与中间件均为 AGPL 协议,如果您希望闭源开发,请不要使用该项目提供的模块和中间件。
4 changes: 1 addition & 3 deletions SDK/API.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
namespace kjBot\SDK;

///以下源码部分来自kilingzhang/coolq-php-sdk : src/URL.php
class API{
const send_private_msg = '/send_private_msg';
const send_private_msg_async = '/send_private_msg_async';
Expand Down Expand Up @@ -32,6 +31,7 @@ class API{
const get_group_member_list = '/get_group_member_list';
const get_cookies = '/get_cookies';
const get_csrf_token = '/get_csrf_token';
const get_credentials = '/get_credentials';
const get_record = '/get_record';
const get_status = '/get_status';
const get_version_info = '/get_version_info';
Expand All @@ -44,5 +44,3 @@ class API{
const __check_update = '/.check_update';
const __handle_quick_operation = '/.handle_quick_operation';
}
///以上源码部分来自kilingzhang/coolq-php-sdk : src/URL.php
///许可证:Open Source Licenses/kilingzhang/coolq-php-sdk/LICENSE
15 changes: 10 additions & 5 deletions SDK/CoolQ.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public function __construct($host = '127.0.0.1:5700', $token = ''){
$this->token = $token;
}

///以下源码部分来自kilingzhang/coolq-php-sdk : src/CoolQ.php
public function sendPrivateMsg($user_id, $message, $auto_escape = false){
$api = API::send_private_msg;
$param = [
Expand Down Expand Up @@ -280,6 +279,12 @@ public function getCsrfToken(){
return $this->query($api, $param);
}

public function get_credentials(){
$api = API::get_credentials;
$param = [];
return $this->query($api, $param);
}

public function getRecord($file, $out_format){
$api = API::get_record;
$param = [
Expand Down Expand Up @@ -337,9 +342,11 @@ public function _getFriendList(){
return $this->query($api, $param);
}

public function _getGroupInfo(){
public function _getGroupInfo($flat = false){
$api = API::_get_group_info;
$param = [];
$param = [
'flat' => $flat,
];
return $this->query($api, $param);
}

Expand All @@ -359,8 +366,6 @@ public function __handleQuickOperation($context, $operation){
];
return $this->query($api, $param);
}
///以上源码部分来自kilingzhang/coolq-php-sdk : src/CoolQ.php
///许可证:Open Source Licenses/kilingzhang/coolq-php-sdk/LICENSE

private function query($api, $param){
$queryStr = '?';
Expand Down
1 change: 1 addition & 0 deletions config.ini.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ WelcomeMsg=感谢您添加 kjBot 为好友,发送 !help 查看帮助列表
;DEBUG=true
DebugListen=919815238
;Listen=
recordStat=true
;这里往下是模块定义的 config,以后可能会改为使用 data
Github_Integration_ID=
Github_Installation_ID=
Expand Down
8 changes: 8 additions & 0 deletions module/recordStat/global.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

global $Queue;
requireMaster();

$Queue[]= sendPM(getUserCommandCount(0));

?>
14 changes: 14 additions & 0 deletions module/recordStat/me.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

global $Queue, $User_id;

if(!allowRecord($User_id))leave(<<<EOT
您还没有同意 kjBot 记录您的使用情况,请使用命令
!recordStat
了解更多
EOT
);

$Queue[]= sendPM(getUserCommandCount($User_id));

?>
2 changes: 1 addition & 1 deletion module/unsleep/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

$group = nextArg();
$CQ->setGroupBan($group, $Event['user_id'], 0);
$Queue[]= '已在 '.$group.' 解除禁言';
$Queue[]= sendBack('已在 '.$group.' 解除禁言');

?>
2 changes: 1 addition & 1 deletion public/tools/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
require('frame.php');
require('convert.php');
require('text.php');
require('statDB.php');
if(config('recordStat', 'true')=='true')require('statDB.php');

?>
8 changes: 5 additions & 3 deletions public/tools/frame.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,11 @@ function loadModule(string $module){
}

if(file_exists('../module/'.$moduleFile)){
if(strpos($module, '.tools')===false){ //防止记录工具类模块
global $Event;
addCommandCount($Event['user_id'], $module);
if(config('recordStat', 'true')=='true'){
if(strpos($module, '.tools')===false){ //防止记录工具类模块
global $Event;
addCommandCount($Event['user_id'], $module);
}
}
require('../module/'.$moduleFile);
}else{
Expand Down
14 changes: 9 additions & 5 deletions public/tools/statDB.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php
function allowRecord($user_id){
return trim(getData('recordStat/'.$user_id))==='true';
}

function addCommandCount($user_id, $command){
global $StatDB;
if(trim(getData('recordStat/'.$user_id))==='true'){ //如果用户同意记名记录
if(allowRecord($user_id)){ //如果用户同意记名记录
$row = getCommandCount($user_id, $command);
if($row === false){
$StatDB->query("INSERT INTO record VALUES ({$user_id}, '{$command}', 1)");
Expand All @@ -11,7 +15,7 @@ function addCommandCount($user_id, $command){
}

}
$row = getCommandCount($user_id, $command);
$row = getCommandCount(0, $command);
if($row === false){
$StatDB->query("INSERT INTO record VALUES (0, '{$command}', 1)");
}else{
Expand All @@ -28,9 +32,9 @@ function getCommandCount($user_id, $command){

function getUserCommandCount($user_id){
global $StatDB;
$result = $StatDB->query("SELECT command, count FROM record WHERE user_id={$user_id}");
while($row = $result->fetchArray() && $row !== false){
$text.="{$row['command']} {$row['count']}";
$result = $StatDB->query("SELECT command, count FROM record WHERE user_id={$user_id} ORDER BY count DESC");
while(($row = $result->fetchArray()) && ($row !== false)){
$text.="{$row['command']} {$row['count']}\n";
}
return $text;
}
Expand Down

0 comments on commit 313a944

Please sign in to comment.