calamity-0.1.0
توضیحات
Remote Graia Broadcast.
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | calamity-0.1.0 |
| نام | calamity |
| نسخه کتابخانه | 0.1.0 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | - |
| ایمیل نویسنده | luxuncang <luxuncang@qq.com> |
| آدرس صفحه اصلی | - |
| آدرس اینترنتی | https://pypi.org/project/calamity/ |
| مجوز | MIT |
<div align="center">
# Calamity
_传说中有柄魔剑斩下了灾祸,灾祸带给人们以痛苦以幸福以哀嚎以歌颂,何来彼此._
> 子非鱼,安知鱼之乐
[](https://www.codefactor.io/repository/github/luxuncang/calamity)
[](https://github.com/luxuncang/lacia/blob/master/LICENSE)
[](https://github.com/luxuncang/calamity/blob/master/.github/workflows/codeql-analysis.yml)
</div>
## 安装
```bash
pip install calamity
```
```bash
pdm add calamity
```
## 特性
* 兼容 [Graia Broadcast](https://github.com/GraiaProject/BroadcastControl)
* 兼容 [Lacia](https://github.com/luxuncang/lacia)
## 使用
### 入门
**Server 端**
```python
from calamity import Calamity
Calamity.server()
```
**Client 端**
* 客户端 A
```python
import asyncio
from calamity import Calamity
from graia.broadcast import Broadcast, Dispatchable, BaseDispatcher, DispatcherInterface
loop = asyncio.get_event_loop()
bcc = Broadcast(loop=loop)
bcc = Calamity.patch()
class ExampleEvent(Dispatchable):
class Dispatcher(BaseDispatcher):
@staticmethod
async def catch(interface: DispatcherInterface):
if interface.annotation is str:
return "Calamity"
@bcc.receiver(ExampleEvent, remote=True)
async def event_receiver(event: str):
print("Hello Broadcast!", event)
@bcc.receiver(ExampleEvent)
async def event_receiver1(event: str):
print("Hello Lacia!", event)
async def main():
bcc.postEvent(ExampleEvent())
loop.run_until_complete(main())
loop.run_forever()
```
* 客户端 B
```python
import asyncio
from calamity import Calamity
from graia.broadcast import Broadcast, Dispatchable, BaseDispatcher, DispatcherInterface
loop = asyncio.get_event_loop()
bcc = Broadcast(loop=loop)
bcc = Calamity.patch(debug=True)
class ExampleEvent(Dispatchable):
class Dispatcher(BaseDispatcher):
@staticmethod
async def catch(interface: DispatcherInterface):
if interface.annotation is str:
return "Calamity"
@bcc.receiver(ExampleEvent)
async def event_receiver(event: str):
print("Hello Broadcast!", event)
@bcc.receiver(ExampleEvent)
async def event_receiver1(event: str):
print("Hello Lacia!", event)
async def main():
bcc.postEvent(ExampleEvent(), remote=True)
loop.run_until_complete(main())
loop.run_forever()
```
### 提示
```python
bcc = Broadcast(loop=loop) # 声明 bcc
bcc = Calamity.patch(debug=True) # remote bcc
```
نیازمندی
| مقدار | نام |
|---|---|
| - | graia-broadcast>=0.18.2 |
| - | lacia>=0.0.5 |
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >=3.9 | Python |
نحوه نصب
نصب پکیج whl calamity-0.1.0:
pip install calamity-0.1.0.whl
نصب پکیج tar.gz calamity-0.1.0:
pip install calamity-0.1.0.tar.gz