From 8c0ec5f759c77b1be0f6f4e9cfa4c8fb6410872d Mon Sep 17 00:00:00 2001 From: 8go Date: Mon, 24 Aug 2020 10:39:50 +0000 Subject: [PATCH] built-with-matrix-nio badge + permit aliases (#15) * added built-with-matrix-nio badge to README * permit aliases - using room.is_group is not ideal to determine if a room is a DM - if a room alias is created for a DM, the existing code will break - changing to check for room.member_count seems to be more appropriate - new code also works on DMs that have aliases * moving badge next to existing badge * Update my_project_name/callbacks.py Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> --- README.md | 2 +- my_project_name/callbacks.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 78c0cb1..01ca401 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Nio Template +# Nio Template [![Built with matrix-nio](https://img.shields.io/badge/built%20with-matrix--nio-brightgreen)](https://github.com/poljar/matrix-nio) A template for creating bots with [matrix-nio](https://github.com/poljar/matrix-nio). The documentation for diff --git a/my_project_name/callbacks.py b/my_project_name/callbacks.py index 4d09bea..7152e64 100644 --- a/my_project_name/callbacks.py +++ b/my_project_name/callbacks.py @@ -46,7 +46,12 @@ class Callbacks(object): # 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: + + # 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()