diff --git a/chatbridge/impl/cqhttp/entry.py b/chatbridge/impl/cqhttp/entry.py index 903a0a8..e2e3630 100644 --- a/chatbridge/impl/cqhttp/entry.py +++ b/chatbridge/impl/cqhttp/entry.py @@ -6,7 +6,7 @@ from chatbridge.common.logger import ChatBridgeLogger from chatbridge.core.client import ChatBridgeClient -from chatbridge.core.network.protocol import ChatPayload, CommandPayload +from chatbridge.core.network.protocol import ChatPayload, CommandPayload, CustomPayload from chatbridge.impl import utils from chatbridge.impl.cqhttp.config import CqHttpConfig from chatbridge.impl.tis.protocol import StatsQueryResult, OnlineQueryResult @@ -162,6 +162,22 @@ def on_command(self, sender: str, payload: CommandPayload): result = OnlineQueryResult.deserialize(payload.result) cq_bot.send_text('====== 玩家列表 ======\n{}'.format('\n'.join(result.data))) + def on_custom(self, sender: str, payload: CustomPayload): + global cq_bot + if cq_bot is None: + return + try: + __example_data = { + 'cqhttp_client.action': 'send_text', + 'text': 'the message you want to send' + } + if payload.data.get('cqhttp_client.action') == 'send_text': + text = payload.data.get('text') + self.logger.info('Triggered custom text, sending message {} to qq'.format(text)) + cq_bot.send_text(text) + except: + self.logger.exception('Error in on_custom()') + def main(): global chatClient, cq_bot