Skip to content

Commit

Permalink
break changes: add evenything.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chenwe_i_lin committed Feb 20, 2020
0 parents commit feb6f31
Show file tree
Hide file tree
Showing 31 changed files with 1,436 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode
13 changes: 13 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
pylint = "*"

[packages]
aiohttp = "*"

[requires]
python_version = "3.8"
188 changes: 188 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## Mirai Framework for Python

#### 这是什么?
以 OICQ(QQ) 协议驱动的高性能机器人开发框架 [Mirai](https://github.com/mamoe/mirai) 的 Python 版, 通过其提供的 `HTTP API` 与无头客户端(`Mirai`)交互.

#### 一些Demo

``` python
import asyncio
from mirai import Session, MiraiProtocol
from mirai import MessageChain, PlainMessage, FriendMessage, GroupMessage, AtMessage
from typing import Union

async def main():
authKey: str = "your authKey"
qq: int = "your qq"

async with Session(f"mirai://localhost:8080/?authKey={authKey}&qq={qq}") as session:
print(session.enabled) # 判断 session 是否已经可用

@session.receiver("FriendMessage")
@session.receiver("GroupMessage", lambda m: m.sender.group == 234532452345) # 已经实现一些上下文应用
async def event_handler(
message: Union[FriendMessage, GroupMessage],
session_: Session, protocol: MiraiProtocol):
if isinstance(message, GroupMessage):
await protocol.sendGroupMessage(
message.sender.group,
PlainMessage(text="meow.") + AtMessage(target=message.sender.id)
)

while True: # Session 不会帮你堵塞主线程, 自行实现一个吧.
try:
await asyncio.sleep(1)
except KeyboardInterrupt:
session.close_session()

asyncio.run(main())
```
37 changes: 37 additions & 0 deletions mirai/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from .session import Session
from .protocol import MiraiProtocol
from .group import Group, Member
from .friend import Friend
from .message import (
AtMessage,
AtAllMessage,
FaceMessage,
ImageMessage,
PlainMessage,
SourceMessage
)
from .message.chain import MessageChain
from .message.item import FriendMessage, GroupMessage
from .image import Image

__all__ = [
"Session",
"MiraiProtocol",

"Group",
"Member",
"Friend",
"Image",

"AtMessage",
"AtAllMessage",
"FaceMessage",
"ImageMessage",
"PlainMessage",
"SourceMessage",

"MessageChain",

"FriendMessage",
"GroupMessage"
]
Binary file added mirai/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added mirai/__pycache__/event.cpython-38.pyc
Binary file not shown.
Binary file added mirai/__pycache__/face.cpython-38.pyc
Binary file not shown.
Binary file added mirai/__pycache__/friend.cpython-38.pyc
Binary file not shown.
Binary file added mirai/__pycache__/group.cpython-38.pyc
Binary file not shown.
Binary file added mirai/__pycache__/image.cpython-38.pyc
Binary file not shown.
Binary file added mirai/__pycache__/misc.cpython-38.pyc
Binary file not shown.
Binary file added mirai/__pycache__/network.cpython-38.pyc
Binary file not shown.
Binary file added mirai/__pycache__/protocol.cpython-38.pyc
Binary file not shown.
Binary file added mirai/__pycache__/session.cpython-38.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions mirai/event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from collections import namedtuple

Event = namedtuple("Event", ("name", "body"))
Loading

0 comments on commit feb6f31

Please sign in to comment.