async def message(self, room, event): """Callback for when a message event is received Args: room (nio.rooms.MatrixRoom): The room the event came from event (nio.events.room_events.RoomMessageText): The event defining the message """ # Extract the message text msg = event.body # Ignore messages from ourselves if event.sender == self.client.user: return logger.debug(f"Bot message received for room {room.display_name} | " f"{room.user_name(event.sender)}: {msg}") # Ignore message if in a public room without command prefix has_command_prefix = msg.startswith(self.command_prefix) if not has_command_prefix and not room.is_group: return if has_command_prefix: # Remove the command prefix msg = msg[len(self.command_prefix):] command = Command(self.client, self.store, msg, room, event) await command.process()
async def message(self, room, event): """Callback for when a message event is received Args: room (nio.rooms.MatrixRoom): The room the event came from event (nio.events.room_events.RoomMessageText): The event defining the message """ # Extract the message text msg = event.body # Ignore messages from ourselves if event.sender == self.client.user: return logger.debug(f"Bot message received for room {room.display_name} | " f"{room.user_name(event.sender)}: {msg}") # Process as message if in a public room without command prefix has_command_prefix = msg.startswith(self.command_prefix) if not has_command_prefix and not room.is_group: # General message listener message = Message(self.client, self.store, self.config, msg, room, event) await message.process() return # Otherwise if this is in a 1-1 with the bot or features a command prefix, # treat it as a command if has_command_prefix: # Remove the command prefix msg = msg[len(self.command_prefix):] command = Command(self.client, self.store, self.config, msg, room, event) # Spawn a task and don't wait for it create_task(command.process())
async def message(self, room, event): """Callback for when a message event is received Args: room (nio.rooms.MatrixRoom): The room the event came from event (nio.events.room_events.RoomMessageText): The event defining the message """ # Extract the message text msg = event.body # Ignore messages from ourselves if event.sender == self.client.user: return logger.debug(f"Bot message received for room {room.display_name} | " f"{room.user_name(event.sender)}: {msg}") # process each line as separate message to check for commands messages = msg.split("\n\n") for split_message in messages: # Process as message if in a public room without command prefix has_command_prefix = split_message.startswith(self.command_prefix) if not has_command_prefix and not room.is_group: # General message listener message = Message(self.client, self.store, self.config, split_message, room, event, self.plugin_loader) await message.process() continue # Otherwise if this is in a 1-1 with the bot or features a command prefix, # treat it as a command if has_command_prefix: # Remove the command prefix split_message = split_message[len(self.command_prefix):] # remove leading spaces split_message = split_message.lstrip() if split_message != "": command = Command(self.client, self.store, self.config, split_message, room, event, self.plugin_loader) await command.process()
async def message(self, room, event): """Handle an incoming message event. Arguments: --------- room (nio.rooms.MatrixRoom): The room the event came from event (nio.events.room_events.RoomMessageText): The event defining the message """ # Extract the message text msg = event.body # Ignore messages from ourselves if event.sender == self.client.user: return logger.debug( f"Bot message received for room {room.display_name} | " f"{room.user_name(event.sender)}: {msg}" ) # Process as message if in a public room without command prefix has_command_prefix = msg.startswith(self.command_prefix) # room.is_group is often a DM, but not always. # room.is_group does not allow room aliases # room.member_count > 2 ... we assume a public room # room.member_count <= 2 ... we assume a DM if not has_command_prefix and room.member_count > 2: # General message listener message = Message(self.client, self.store, self.config, msg, room, event) await message.process() return # Otherwise if this is in a 1-1 with the bot or features a command # prefix, treat it as a command if has_command_prefix: # Remove the command prefix msg = msg[len(self.command_prefix):] command = Command(self.client, self.store, self.config, msg, room, event) await command.process()