Skip to content

Commit

Permalink
cqhttp client support sending any text via custom payload
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallen-Breath committed Mar 13, 2023
1 parent 1b0f109 commit 251bb12
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion chatbridge/impl/cqhttp/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 251bb12

Please sign in to comment.