-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from botuniverse/develop
发布 0.3.0
- Loading branch information
Showing
53 changed files
with
1,377 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "composer" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" | ||
target-branch: "develop" | ||
labels: | ||
- "area/dependency" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Configuration for Label Actions - https://github.com/dessant/label-actions | ||
|
||
resolution/cannot-reproduce: | ||
comment: > | ||
我们的开发人员无法复现此问题,如有可能,请提供完整的复现用例及截图等资料。 | ||
resolution/duplicate: | ||
comment: > | ||
这与现有的一个Issue/PR重复了。 | ||
close: true | ||
lock: true | ||
|
||
resolution/invalid: | ||
comment: > | ||
我们的开发人员认为这是一个无效的问题,请确保您查阅了我们的贡献指南及提供了必要的信息。 | ||
close: true | ||
|
||
resolution/rejected: | ||
comment: > | ||
此提案已被我们的开发人员拒绝。 | ||
close: true | ||
|
||
resoluton/wontfix: | ||
comment: > | ||
抱歉,我们暂时不会处理。 | ||
close: true | ||
|
||
'accept PRs': | ||
comment: > | ||
我们的开发人员认为这是一个不错的提案,您(或其他有意向的人)可以就此提交 PR。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Close Stale Issue PR | ||
|
||
on: | ||
schedule: | ||
- cron: '0 * * * *' | ||
workflow_dispatch: | ||
|
||
permissions: | ||
issues: write | ||
pull-requests: write | ||
|
||
jobs: | ||
action: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Lock outdated issues and prs | ||
uses: dessant/lock-threads@v3 | ||
with: | ||
issue-inactive-days: '7' | ||
exclude-any-issue-labels: 'lifecycle/keep-open' | ||
add-issue-labels: 'lifecycle/stale' | ||
issue-comment: > | ||
由于在关闭后没有更多信息,此Issue已被自动锁定。如有需要请提出一个新Issue。 | ||
pr-comment: > | ||
由于在关闭后没有更多信息,此PR已被自动锁定。如有需要请提出一个新Issue。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: 'Label Actions' | ||
|
||
on: | ||
issues: | ||
types: [ labeled, unlabeled ] | ||
pull_request: | ||
types: [ labeled, unlabeled ] | ||
discussion: | ||
types: [ labeled, unlabeled ] | ||
|
||
permissions: | ||
contents: read | ||
issues: write | ||
pull-requests: write | ||
discussions: write | ||
|
||
jobs: | ||
action: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: dessant/label-actions@v2 | ||
with: | ||
config-path: '.github/label-actions.yaml' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
{ | ||
"lib": { | ||
"db": false | ||
}, | ||
"communications": { | ||
"http": { | ||
"enable": true, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
parameters: | ||
reportUnmatchedIgnoredErrors: false | ||
level: 0 | ||
paths: | ||
- ./src/ | ||
ignoreErrors: | ||
- '#Used constant OS_TYPE_(LINUX|WINDOWS) not found#' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OneBot\Database\SQLite; | ||
|
||
use OneBot\ObjectPool\AbstractObjectPool; | ||
|
||
/** | ||
* Class ConnectionPool. | ||
*/ | ||
class ConnectionPool extends AbstractObjectPool | ||
{ | ||
protected function makeObject(): object | ||
{ | ||
return new SQLite(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OneBot\Database\SQLite; | ||
|
||
use OneBot\V12\Exception\OneBotException; | ||
|
||
/** | ||
* Class SQLite. | ||
*/ | ||
class SQLite extends \PDO | ||
{ | ||
public function __construct() | ||
{ | ||
if (ob_config('lib.db', false)) { | ||
parent::__construct('sqlite:' . __DIR__ . '/../../../../cache/db'); | ||
} else { | ||
throw new OneBotException('数据库支持未启用'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OneBot\ObjectPool; | ||
|
||
use Exception; | ||
use Swoole\Coroutine\Channel; | ||
|
||
/** | ||
* 抽象对象池 | ||
* 只能在Swoole协程中使用 | ||
*/ | ||
abstract class AbstractObjectPool | ||
{ | ||
/** @var Channel 队列 */ | ||
private $queue; | ||
|
||
/** @var array 活跃对象 */ | ||
private $actives; | ||
|
||
public function __construct() | ||
{ | ||
// TODO: 添加更多可配置项 | ||
$this->queue = new Channel(swoole_cpu_num()); | ||
} | ||
|
||
/** | ||
* 取出对象 | ||
* | ||
* @throws Exception | ||
*/ | ||
public function take(): object | ||
{ | ||
if ($this->getFreeCount() > 0) { | ||
// 如有可用对象则取用 | ||
$object = $this->queue->pop(5); | ||
if (!$object) { | ||
throw new Exception('取出对象时等待超时'); | ||
} | ||
} else { | ||
// 没有就整个新的 | ||
$object = $this->makeObject(); | ||
} | ||
$hash = spl_object_hash($object); | ||
// 为方便在归还时删除,使用数组key存储 | ||
$this->actives[$hash] = ''; | ||
|
||
return $object; | ||
} | ||
|
||
/** | ||
* 归还对象 | ||
*/ | ||
public function return(object $object): bool | ||
{ | ||
$hash = spl_object_hash($object); | ||
unset($this->actives[$hash]); | ||
|
||
// 放回队列里 | ||
return $this->queue->push($object, 5); | ||
} | ||
|
||
abstract protected function makeObject(): object; | ||
|
||
/** | ||
* 获取可用的对象数量 | ||
*/ | ||
protected function getFreeCount(): int | ||
{ | ||
$count = $this->queue->stats()['queue_num']; | ||
return $count < 0 ? 0 : $count; | ||
} | ||
|
||
/** | ||
* 获取活跃(已被取用)的对象数量 | ||
*/ | ||
protected function getActiveCount(): int | ||
{ | ||
return count($this->actives); | ||
} | ||
|
||
/** | ||
* 获取所有的对象数量 | ||
*/ | ||
protected function getTotalCount(): int | ||
{ | ||
return $this->getFreeCount() + $this->getActiveCount(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.