-
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.
breaking change: context is disabled no longer in event body.
- Loading branch information
Chenwe_i_lin
committed
Feb 27, 2020
1 parent
2c004ba
commit ba74158
Showing
10 changed files
with
118 additions
and
127 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
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,16 +1,30 @@ | ||
from .session import Session | ||
from . import ( | ||
MessageChain, | ||
Plain | ||
) | ||
|
||
class Command: | ||
prefix: str | ||
match_string: str | ||
|
||
pass | ||
|
||
class CommandManager: | ||
session: Session | ||
registered_command = {} | ||
# prefix -> Union[main_name, aliases] -> action | ||
|
||
def __init__(self, session): | ||
def __init__(self, | ||
session: Session, | ||
listenEvents=("GroupMessage", "FriendMessage")): | ||
self.session = Session | ||
|
||
|
||
def newCommand(self, prefix="/", addon_parser={}): | ||
pass | ||
pass | ||
|
||
def event_listener(self, context): | ||
"""用于监听事件, 并做出分析, 解析到相应的 Command 上. | ||
""" | ||
context.message.messageChain: MessageChain | ||
context.message.messageChain.getFirstComponent(Plain) |
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,2 +1,5 @@ | ||
class NetworkError(Exception): | ||
pass | ||
|
||
class UnknownTarget(Exception): | ||
pass |
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
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
setup( | ||
name="kuriyama", | ||
version='0.1.5', | ||
version='0.1.8', | ||
description='A framework for OICQ(QQ, made by Tencent) headless client "Mirai".', | ||
author='Chenwe-i-lin', | ||
author_email="[email protected]", | ||
|
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,104 +1,27 @@ | ||
import asyncio | ||
import traceback | ||
from pprint import pprint | ||
|
||
from mirai import Session, Plain, Friend, BotMuteEvent | ||
from devtools import debug | ||
|
||
from mirai import ( | ||
At, | ||
ExternalEvents, | ||
Face, | ||
FriendMessage, | ||
GroupMessage, | ||
Image, | ||
MessageContextBody, | ||
Plain, | ||
QQFaces, | ||
Session, | ||
UnexceptedException, | ||
ImageType, | ||
Direct | ||
) | ||
from mirai.event import external | ||
|
||
from context_test import is_startwith | ||
authKey = "213we355gdfbaerg" | ||
qq = 208924405 | ||
|
||
async def main(): | ||
authKey = "213we355gdfbaerg" | ||
qq = 208924405 | ||
|
||
print("???") | ||
async with Session(f"mirai://localhost:8070/?authKey={authKey}&qq={qq}") as session: | ||
print(session.enabled) | ||
@session.receiver("FriendMessage") | ||
async def event_friendmessage(session: Session, sender: Friend): | ||
await session.sendFriendMessage( | ||
sender.id, | ||
[Plain(text="Hello, world!")] | ||
) | ||
|
||
""" | ||
@session.receiver(GroupMessage) | ||
async def normal_handle(context): | ||
if isinstance(context.message, GroupMessage): | ||
print(f"[{context.message.sender.group.id}][{context.message.sender.id}]:", context.message.messageChain.toString()) | ||
#debug(context) | ||
if context.message.messageChain.toString().startswith("/raiseAnother"): | ||
raise ValueError("fa") | ||
elif context.message.messageChain.toString().startswith("/raise"): | ||
raise Exception("test") | ||
elif context.message.messageChain.toString().startswith("/test-at"): | ||
await context.session.sendGroupMessage( | ||
context.message.sender.group.id, | ||
[ | ||
At(target=context.message.sender.id), | ||
Plain(text="meow"), | ||
Face(faceId=QQFaces["jingkong"]) | ||
] | ||
) | ||
elif context.message.messageChain.toString().startswith("/test-localimage"): | ||
await context.session.sendGroupMessage( | ||
context.message.sender.group.id, | ||
[ | ||
await Image.fromFileSystem("2019-05-04_15.52.03.png", session, ImageType.Group), | ||
Plain(text="faq") | ||
] | ||
) | ||
elif context.message.messageChain.toString().startswith("/muteMe"): | ||
await context.session.mute( | ||
context.message.sender.group.id, | ||
context.message.sender.id, | ||
60 | ||
) | ||
await asyncio.sleep(5) | ||
await context.session.unmute( | ||
context.message.sender.group.id, | ||
context.message.sender.id | ||
) | ||
elif context.message.messageChain.toString().startswith("/replyMe"): | ||
debug(await context.session.sendGroupMessage( | ||
context.message.sender.group.id, | ||
"reply da!", | ||
quoteSource=context.message.messageChain.getSource() | ||
)) | ||
if context.message.messageChain.hasComponent(Image): | ||
pass | ||
@session.receiver(ExternalEvents.MemberMuteEvent) | ||
@session.receiver(external.BotMuteEvent) | ||
async def _(context): | ||
debug(context) | ||
@session.exception_handler(UnexceptedException) | ||
async def exception_handle(context: UnexceptedException): | ||
debug(context) | ||
""" | ||
@session.receiver(GroupMessage) | ||
async def normal_handle(context): | ||
if is_startwith("/"): | ||
await context.session.sendGroupMessage( | ||
context.message.sender.group.id, | ||
[Plain(text="嗯?你刚才以斜杠开头写了什么啊")] | ||
) | ||
@session.receiver("BotMuteEvent") | ||
async def event_BotMuteEvent(event: BotMuteEvent): | ||
debug(event) | ||
|
||
await session.joinMainThread() | ||
|
||
try: | ||
asyncio.run(main()) | ||
except KeyboardInterrupt: | ||
exit() | ||
exit() |