diff --git a/build.sh b/build.sh index d02746d..21eb0b9 100755 --- a/build.sh +++ b/build.sh @@ -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/ diff --git a/module/help/main.php b/module/help/main.php index 9f733be..65be8e8 100644 --- a/module/help/main.php +++ b/module/help/main.php @@ -3,7 +3,7 @@ global $Queue; $msg=<< diff --git a/module/help/search.php b/module/help/search.php new file mode 100644 index 0000000..1584478 --- /dev/null +++ b/module/help/search.php @@ -0,0 +1,15 @@ + diff --git a/module/osu/drawScore.php b/module/osu/drawScore.php deleted file mode 100644 index 98943e5..0000000 --- a/module/osu/drawScore.php +++ /dev/null @@ -1,80 +0,0 @@ -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; -} - -?> diff --git a/module/osu/tools.php b/module/osu/tools.php index c3b77ff..039c3f7 100644 --- a/module/osu/tools.php +++ b/module/osu/tools.php @@ -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; +} diff --git a/module/recordStat/cancel.php b/module/recordStat/cancel.php new file mode 100644 index 0000000..d337f2e --- /dev/null +++ b/module/recordStat/cancel.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/module/recordStat/main.php b/module/recordStat/main.php new file mode 100644 index 0000000..3bdaddf --- /dev/null +++ b/module/recordStat/main.php @@ -0,0 +1,19 @@ + diff --git a/module/recordStat/verify.php b/module/recordStat/verify.php new file mode 100644 index 0000000..375bdcd --- /dev/null +++ b/module/recordStat/verify.php @@ -0,0 +1,23 @@ + \ No newline at end of file diff --git a/module/search/baidu.php b/module/search/baidu.php index 0361187..51bed6c 100644 --- a/module/search/baidu.php +++ b/module/search/baidu.php @@ -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, '+')); ?> diff --git a/module/search/google.php b/module/search/google.php index 9ea05d7..c7f8adc 100644 --- a/module/search/google.php +++ b/module/search/google.php @@ -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, '+')); ?> diff --git a/public/init.php b/public/init.php index 0ba3e71..fc5ff2d 100644 --- a/public/init.php +++ b/public/init.php @@ -9,6 +9,7 @@ $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); @@ -16,6 +17,7 @@ $DebugListen = config('DebugListen', config('master')); $Command = []; $Text = ''; +$StatDB = new SQLite3('../storage/data/stat.db'); block($Event['user_id']); diff --git a/public/tools/Autoload.php b/public/tools/Autoload.php index 3862c67..0eb7501 100644 --- a/public/tools/Autoload.php +++ b/public/tools/Autoload.php @@ -3,5 +3,6 @@ require('frame.php'); require('convert.php'); require('text.php'); +require('statDB.php'); ?> diff --git a/public/tools/frame.php b/public/tools/frame.php index ae6cfad..9a3f517 100644 --- a/public/tools/frame.php +++ b/public/tools/frame.php @@ -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 diff --git a/public/tools/statDB.php b/public/tools/statDB.php new file mode 100644 index 0000000..4e41a44 --- /dev/null +++ b/public/tools/statDB.php @@ -0,0 +1,38 @@ +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; +} + +?> diff --git a/stat.sql b/stat.sql new file mode 100644 index 0000000..7be3603 --- /dev/null +++ b/stat.sql @@ -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;