-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chenwe_i_lin
committed
Feb 20, 2020
0 parents
commit feb6f31
Showing
31 changed files
with
1,436 additions
and
0 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 @@ | ||
.vscode |
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,13 @@ | ||
[[source]] | ||
name = "pypi" | ||
url = "https://pypi.org/simple" | ||
verify_ssl = true | ||
|
||
[dev-packages] | ||
pylint = "*" | ||
|
||
[packages] | ||
aiohttp = "*" | ||
|
||
[requires] | ||
python_version = "3.8" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,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()) | ||
``` |
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,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 not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,3 @@ | ||
from collections import namedtuple | ||
|
||
Event = namedtuple("Event", ("name", "body")) |
Oops, something went wrong.