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

Update to 2.4 #65

Merged
merged 6 commits into from
Jul 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ php composer.phar install
mkdir storage/
mkdir storage/data/
mkdir storage/cache/
cd storage/data/
sqlite3 stat.db ".read ../../stat.sql"
cd ../../
chmod -R 0777 storage/
2 changes: 1 addition & 1 deletion module/help/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
global $Queue;
$msg=<<<EOT
可用命令:
checkin credit issue osu pixiv roll sleep time unsleep version voice
checkin credit issue osu pixiv recordStat roll search sleep time unsleep version voice
EOT;

$Queue[]= sendBack($msg);
Expand Down
13 changes: 13 additions & 0 deletions module/help/recordStat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

$msg=<<<EOT
kjBot 用户使用情况记录
用法:
!recordStat 阅读用户协议
!recordStat.verify 同意
!recordStat.cancel 取消同意
EOT;

leave($msg);

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

$msg=<<<EOT
搜索
用法:
!search{.pixiv|.baidu|.google}

返回指定的搜索引擎链接

更多搜索即将到来™
EOT;

leave($msg);

?>
80 changes: 0 additions & 80 deletions module/osu/drawScore.php

This file was deleted.

75 changes: 74 additions & 1 deletion module/osu/tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,77 @@ function setOsuID($qq, $id){
}
}

loadModule('osu.drawScore');
function imageFont($file = 1, $size = 12, $color = '#000000', $align = 'left', $valign = 'buttom', $angle = 0){
return function($font) use ($file, $size, $color, $align, $valign, $angle){
$font->file($file);
$font->size($size);
$font->color($color);
$font->align($align);
$font->valign($valign);
$font->angle($angle);
};
}

function drawScore($recent, $map, $u){
Image::configure(array('driver' => 'imagick'));

$exo2 = '/usr/share/fonts/truetype/exo2/exo2.ttf';
$exo2b = '/usr/share/fonts/truetype/exo2/exo2-bold.ttf';
$here = __DIR__.'/';
$venera = $here.'Venera.ttf';
$blue = '#44AADD';
$gray = '#AAAAAA';
$pink = '#B21679';

$acc=ACCof($recent);

$scoreImg = getBG($map['beatmap_id']);

$sideText = imageFont($exo2b, 38, $blue, 'center', 'buttom'); //两侧字体
$songText = imageFont($exo2b, 15, $blue, 'center', 'buttom'); //歌名、歌手
$performText = imageFont($exo2b, 20, $blue, 'center', 'buttom'); //表现情况
$ppText = imageFont($exo2b, 25, $blue, 'center', 'buttom'); //PP

$result_pp=getPP($recent['beatmap_id'], $recent);

$scoreImg
//准备模版
->blur(8)
->insert(Image::make($here.'template.png')->opacity(80), 'center')
//两侧文字
->text($recent['maxcombo'].'x', 310, 350, $sideText)
->text($acc, 975, 350, $sideText)
//昵称
->text($u, 640, 225, imageFont($exo2b, 30, $gray, 'center', 'buttom'))
//Rank
->insert(Image::make($here.$recent['rank'].'.png'), 'top-left', 580, 210)
//MOD
->insert(getModImage(praseMod($recent['enabled_mods'])), 'top', 640, 302)
//分数
->text(number_format($recent['score']), 640, 375, imageFont($venera, $recent['score']>1000000?55:60, $pink, 'center', 'buttom'))
//四维
->text('CS: '.sprintf('%.2f', $map['cs']).' OD: '.sprintf('%.2f', $map['od']).' Stars: '.sprintf('%.2f', $map['stars']).' HP: '.sprintf('%.2f', $map['hp']).' AR: '.sprintf('%.2f', $map['ar']), 640, 400, imageFont($exo2b, 15, $pink, 'center', 'buttom'))
//歌名
->text($map['title'], 640, 420, $songText)
//歌手
->text($map['artist'], 640, 435, $songText)
//谱面难度及谱师
->text($map['version'].' - mapped by '.$map['creator'], 640, 450, imageFont($exo2b, 15, $gray, 'center', 'buttom'))
//日期
->text($recent['date'], 640, 473, imageFont($exo2, 15, $gray, 'center', 'buttom'))
//表现情况
->text(sprintf('%04d', $recent['count300']), 553, 515, $performText)
->text(sprintf('%04d', $recent['count100']), 615, 515, $performText)
->text(sprintf('%04d', $recent['count50']), 675, 515, $performText)
->text(sprintf('%04d', $recent['countmiss']), 735, 515, $performText)
//三维pp
->text($result_pp['pp'].'PP', 605, 646, imageFont($exo2b, 30, $blue, 'right', 'buttom'))
->text(getFCPP($recent['beatmap_id'], $recent).'PP', 680, 646, imageFont($exo2b, 30, $blue, 'left', 'buttom'))
->text($result_pp['aim'], 540, 680, $ppText)
->text($result_pp['spd'], 640, 680, $ppText)
->text($result_pp['acc'], 740, 680, $ppText)
;


return $scoreImg;
}
15 changes: 15 additions & 0 deletions module/recordStat/cancel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

global $User_id;
loadModule('credit.tools');

if(fromGroup())leave();
if(trim(getData('recordStat/'.$User_id))!='true')leave();

if(trim(getData('recordStat/r'.$User_id))=='true')decCredit($User_id, 415);
setData('recordStat/'.$User_id, 'cancel');
setData('recordStat/r'.$User_id, 'false');

leave('您已取消 kjBot 的个人记录。');

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

global $Queue, $User_id;

$agreement=<<<EOT
感谢您使用 kjBot!

kjBot 需要使用您个人的命令使用情况来优化您的使用体验。
如果您不同意(我们默认您不同意),kjBot 将不会记名收集您的使用记录。
不同意记名记录不会影响您的正常使用。

如果您同意,请输入
!recordStat.verify
EOT;

setData('recordStat/'.$User_id, 'read');
$Queue[]= sendPM($agreement); //仅在私聊中发送用户协议

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

global $User_id;
loadModule('credit.tools');

if(fromGroup())leave(); //禁止在群内进行验证
switch(trim(getData('recordStat/'.$User_id))){
case 'cancel':
setData('recordStat/'.$User_id, 'true');
leave('感谢您的支持');
case 'read':
addCredit($User_id, 415);
setData('recordStat/'.$User_id, 'true');
setData('recordStat/r'.$User_id, 'true');
leave("感谢您的支持,奖励 415 金币\n请注意,如果您在将来要求取消记录,需要将这 415 金币交还。");
case 'true':
leave("您已经同意 kjBot 记录您的使用情况,如需取消请输入\n!recordStat.cancel");
default:
leave('请先阅读协议!');
}


?>
2 changes: 1 addition & 1 deletion module/search/baidu.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
$arg = nextArg();
$query.=urlencode($arg).'+';
}while($arg!==NULL);
$Queue[]= sendBack('https://baidu.com/s?word='.$query);
$Queue[]= sendBack('https://baidu.com/s?word='.rtrim($query, '+'));

?>
2 changes: 1 addition & 1 deletion module/search/google.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
$arg = nextArg();
$query.=urlencode($arg).'+';
}while($arg!==NULL);
$Queue[]= sendBack('https://google.com/search?q='.$query);
$Queue[]= sendBack('https://google.com/search?q='.rtrim($query, '+'));

?>
2 changes: 2 additions & 0 deletions public/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
$Config = parse_ini_file('../config.ini', false, INI_SCANNER_RAW);
$Event = json_decode(file_get_contents('php://input'), true);
$Event['message'] = CQCode::DecodeCQCode($Event['message']);
$User_id = $Event['user_id'];
$CQ = new CoolQ(config('API', '127.0.0.1:5700'), config('token', ''));
$Queue = [];
$MsgSender = new MessageSender($CQ);
$Debug = ('true'===config('DEBUG', 'false'))?true:false;
$DebugListen = config('DebugListen', config('master'));
$Command = [];
$Text = '';
$StatDB = new SQLite3('../storage/data/stat.db');

block($Event['user_id']);

Expand Down
1 change: 1 addition & 0 deletions public/tools/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
require('frame.php');
require('convert.php');
require('text.php');
require('statDB.php');

?>
4 changes: 4 additions & 0 deletions public/tools/frame.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ function loadModule(string $module){
}

if(file_exists('../module/'.$moduleFile)){
if(strpos($module, '.tools')===false){ //防止记录工具类模块
global $Event;
addCommandCount($Event['user_id'], $module);
}
require('../module/'.$moduleFile);
}else{
if(strpos($module, 'help')!==0){ //防止无限尝试加载help
Expand Down
38 changes: 38 additions & 0 deletions public/tools/statDB.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
function addCommandCount($user_id, $command){
global $StatDB;
if(trim(getData('recordStat/'.$user_id))==='true'){ //如果用户同意记名记录
$row = getCommandCount($user_id, $command);
if($row === false){
$StatDB->query("INSERT INTO record VALUES ({$user_id}, '{$command}', 1)");
}else{
$count = $row['count'];
$StatDB->query("UPDATE record SET count = {$count}+1 WHERE user_id={$user_id} AND command='{$command}'");
}

}
$row = getCommandCount($user_id, $command);
if($row === false){
$StatDB->query("INSERT INTO record VALUES (0, '{$command}', 1)");
}else{
$count = $row['count'];
$StatDB->query("UPDATE record SET count = {$count}+1 WHERE user_id=0 AND command='{$command}'");
}
}

function getCommandCount($user_id, $command){
global $StatDB;
$result = $StatDB->query("SELECT count FROM record WHERE user_id={$user_id} AND command='{$command}'");
return $result->fetchArray();
}

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']}";
}
return $text;
}

?>
8 changes: 8 additions & 0 deletions stat.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE record(
user_id BIGINT NOT NULL,
command TEXT NOT NULL,
count NOT NULL
);
COMMIT;