add pong callback
This commit is contained in:
parent
8165f2b1c0
commit
0de8d9f036
1 changed files with 15 additions and 0 deletions
|
@ -7,11 +7,25 @@ from typing import (
|
||||||
Any,
|
Any,
|
||||||
NoReturn
|
NoReturn
|
||||||
)
|
)
|
||||||
|
import nio
|
||||||
from matrix_bot.client import Client
|
from matrix_bot.client import Client
|
||||||
from matrix_bot.invite_policy import WhiteList
|
from matrix_bot.invite_policy import WhiteList
|
||||||
|
from matrix_bot.utils import ignore_client_message
|
||||||
from .config import Config
|
from .config import Config
|
||||||
from .format import Message
|
from .format import Message
|
||||||
|
|
||||||
|
@ignore_client_message
|
||||||
|
async def __pong(
|
||||||
|
client: Client,
|
||||||
|
room: nio.rooms.MatrixRoom,
|
||||||
|
message: nio.events.room_events.RoomMessageText
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
If the bot is pinged, send "Pong"
|
||||||
|
"""
|
||||||
|
if (client.user_name + ':') in message.body:
|
||||||
|
await client.send_message(room.room_id, "Pong")
|
||||||
|
|
||||||
async def __send_messsages(
|
async def __send_messsages(
|
||||||
message_queue: asyncio.Queue[Message],
|
message_queue: asyncio.Queue[Message],
|
||||||
bot: Client,
|
bot: Client,
|
||||||
|
@ -45,6 +59,7 @@ async def send_messages(
|
||||||
)
|
)
|
||||||
invite_policy = await WhiteList(bot, config.alert_rooms)
|
invite_policy = await WhiteList(bot, config.alert_rooms)
|
||||||
bot.set_invite_policy(invite_policy)
|
bot.set_invite_policy(invite_policy)
|
||||||
|
bot.add_message_callback(__pong)
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
bot.run(),
|
bot.run(),
|
||||||
__send_messsages(
|
__send_messsages(
|
||||||
|
|
Loading…
Reference in a new issue