Commit 1069688f by HanSon

Merge branch 'dev' into master1

# Conflicts:
#	src/Core/MessageHandler.php
2 parents 5572cfba 8ec8c3e1
...@@ -9,8 +9,7 @@ ...@@ -9,8 +9,7 @@
namespace Hanson\Vbot\Collections; namespace Hanson\Vbot\Collections;
use Hanson\Vbot\Core\Server; use Hanson\Vbot\Support\FileManager;
use Hanson\Vbot\Support\Console;
class ContactFactory class ContactFactory
{ {
...@@ -58,12 +57,15 @@ class ContactFactory ...@@ -58,12 +57,15 @@ class ContactFactory
} }
$this->getBatchGroupMembers(); $this->getBatchGroupMembers();
myself()->alias = contact()->get(myself()->username)['Alias'] ? : myself()->username;
if(server()->config['debug']){ if(server()->config['debug']){
file_put_contents(server()->config['tmp'] . 'contact.json', json_encode(contact()->all())); FileManager::download('contact.json', json_encode(contact()->all()));
file_put_contents(server()->config['tmp'] . 'member.json', json_encode(member()->all())); FileManager::download('member.json', json_encode(member()->all()));
file_put_contents(server()->config['tmp'] . 'group.json', json_encode(group()->all())); FileManager::download('group.json', json_encode(group()->all()));
file_put_contents(server()->config['tmp'] . 'official.json', json_encode(Official::getInstance()->all())); FileManager::download('official.json', json_encode(official()->all()));
file_put_contents(server()->config['tmp'] . 'special.json', json_encode(Special::getInstance()->all())); FileManager::download('special.json', json_encode(Special::getInstance()->all()));
} }
} }
......
...@@ -15,6 +15,7 @@ use Hanson\Vbot\Message\Entity\Message; ...@@ -15,6 +15,7 @@ use Hanson\Vbot\Message\Entity\Message;
use Hanson\Vbot\Message\Entity\Text; use Hanson\Vbot\Message\Entity\Text;
use Hanson\Vbot\Message\Entity\Video; use Hanson\Vbot\Message\Entity\Video;
use Hanson\Vbot\Support\Console; use Hanson\Vbot\Support\Console;
use Hanson\Vbot\Support\System;
class MessageHandler class MessageHandler
{ {
...@@ -193,7 +194,7 @@ class MessageHandler ...@@ -193,7 +194,7 @@ class MessageHandler
{ {
message()->put($message->msg['MsgId'], $message); message()->put($message->msg['MsgId'], $message);
$file = fopen(server()->config['tmp'].'/message.json', 'a'); $file = fopen(System::getPath() .'message.json', 'a');
fwrite($file, json_encode($message) . PHP_EOL); fwrite($file, json_encode($message) . PHP_EOL);
fclose($file); fclose($file);
} }
......
...@@ -22,6 +22,8 @@ class Myself ...@@ -22,6 +22,8 @@ class Myself
public $sex; public $sex;
public $alias;
public static function getInstance() public static function getInstance()
{ {
if (!static::$instance) { if (!static::$instance) {
......
...@@ -13,6 +13,8 @@ use Endroid\QrCode\QrCode; ...@@ -13,6 +13,8 @@ use Endroid\QrCode\QrCode;
use Hanson\Vbot\Collections\ContactFactory; use Hanson\Vbot\Collections\ContactFactory;
use Hanson\Vbot\Collections\Group; use Hanson\Vbot\Collections\Group;
use Hanson\Vbot\Support\Console; use Hanson\Vbot\Support\Console;
use Hanson\Vbot\Support\FileManager;
use Hanson\Vbot\Support\System;
class Server class Server
{ {
...@@ -140,7 +142,9 @@ class Server ...@@ -140,7 +142,9 @@ class Server
mkdir($this->config['tmp'], 0700, true); mkdir($this->config['tmp'], 0700, true);
} }
$file = $this->config['tmp'] . 'qr.png'; $file = System::getPath() . 'qr.png';
FileManager::download('qr.png', file_get_contents($url));
$qrCode->save($file); $qrCode->save($file);
} }
......
...@@ -49,10 +49,10 @@ class Recall extends Message implements MessageInterface ...@@ -49,10 +49,10 @@ class Recall extends Message implements MessageInterface
$msgId = $this->parseMsgId($this->msg['Content']); $msgId = $this->parseMsgId($this->msg['Content']);
/** @var Message $message */ /** @var Message $message */
$this->origin = $message = message()->get($msgId, null); $this->origin = message()->get($msgId, null);
if(!$message){ if($this->origin){
$this->nickname = $message->sender ? $message->sender['NickName'] : account()->getAccount($message->msg['FromUserName'])['NickName']; $this->nickname = $this->origin->sender ? $message->sender['NickName'] : account()->getAccount($this->origin->msg['FromUserName'])['NickName'];
$this->setContent(); $this->setContent();
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
*/ */
namespace Hanson\Vbot\Message; namespace Hanson\Vbot\Message;
use Hanson\Vbot\Support\System;
/** /**
...@@ -19,7 +20,7 @@ trait MediaTrait ...@@ -19,7 +20,7 @@ trait MediaTrait
public static function getPath($folder) public static function getPath($folder)
{ {
$path = server()->config['tmp'] . $folder; $path = System::getPath() . $folder;
return realpath($path); return realpath($path);
} }
......
...@@ -12,9 +12,9 @@ namespace Hanson\Vbot\Support; ...@@ -12,9 +12,9 @@ namespace Hanson\Vbot\Support;
class FileManager class FileManager
{ {
public static function download($name, $data, $path) public static function download($name, $data, $path = '')
{ {
$path = server()->config['tmp'] . $path; $path = System::getPath() . $path;
if(!is_dir(realpath($path))){ if(!is_dir(realpath($path))){
mkdir($path, 0700, true); mkdir($path, 0700, true);
} }
......
...@@ -21,4 +21,9 @@ class System ...@@ -21,4 +21,9 @@ class System
{ {
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'; return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
} }
public static function getPath()
{
return server()->config['tmp'] . '/' . myself()->alias . '/';
}
} }
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!