From d38c8c7b1c6661d2a259a07dea6335ecd1398d9f Mon Sep 17 00:00:00 2001 From: Jackson Egan Date: Thu, 10 Sep 2020 23:30:16 -0400 Subject: [PATCH] Add welcome file --- docker-compose.yml | 1 + modules/welcome_room.py | 24 ++++++++++++------------ modules/welcome_server.py | 17 +++++++++-------- welcome.md | 1 + 4 files changed, 23 insertions(+), 20 deletions(-) create mode 100644 welcome.md diff --git a/docker-compose.yml b/docker-compose.yml index 173f931..165d563 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,5 +21,6 @@ services: - ${PWD}/config/:/bot/config - ${PWD}/credentials.json:/bot/credentials.json - ${PWD}/token.pickle:/bot/token.pickle + - ${PWD}/welcome.md:/bot/welcome.md stop_signal: SIGINT diff --git a/modules/welcome_room.py b/modules/welcome_room.py index ea20191..e15183d 100644 --- a/modules/welcome_room.py +++ b/modules/welcome_room.py @@ -11,14 +11,13 @@ class MatrixModule(BotModule): def __init__(self, name): super().__init__(name) - room_id = os.getenv("WELCOME_ROOMID") - self.room_id = room_id + self.room_id = os.getenv("WELCOME_ROOMID") self.last_welcome_room_user_count = 0 self.last_welcome_room_users = [] # If the provided welcome message is a file path, read the file into # the welcome message. Otherwise, use the variable data as the message. - if os.path.isFile(os.getenv("WELCOME_MESSAGE")): + if os.path.isfile(os.getenv("WELCOME_MESSAGE")): with open(os.getenv("WELCOME_MESSAGE"), "r") as file: self.welcome_message = file.read() else: @@ -38,13 +37,13 @@ class MatrixModule(BotModule): if pollcount != 1: new_users = newcomer_room_user_delta.get("recently_added", []) - if os.getenv("WELCOME_ROOM_NOTIFY_DEPARTURE") and \ + if os.getenv("WELCOME_ROOM_NOTIFY_DEPARTURE", 0) and \ len(newcomer_room_user_delta.get("recently_removed")) > 0: for owner in bot.owners: await bot.send_msg( owner, "Welcome Bot", - "User {left} left the Newcomers channel".format( + "User {left} left the welcome channel".format( left=newcomer_room_user_delta.get( "recently_removed") ) @@ -61,14 +60,15 @@ class MatrixModule(BotModule): "Welcome", self.welcome_message ) - for owner in bot.owners: - await bot.send_msg( - owner, - "Welcome Bot", - "Sent a welcome message to: {noobs}".format( - noobs=user_list + if len(user_list) > 0: + for owner in bot.owners: + await bot.send_msg( + owner, + "Welcome Bot", + "Sent a welcome message to: {noobs}".format( + noobs=user_list + ) ) - ) def get_user_list_delta( self, diff --git a/modules/welcome_server.py b/modules/welcome_server.py index a00e779..b1a45fb 100644 --- a/modules/welcome_server.py +++ b/modules/welcome_server.py @@ -22,7 +22,7 @@ class MatrixModule(BotModule): # If the provided welcome message is a file path, read the file into # the welcome message. Otherwise, use the variable data as the message. - if os.path.isFile(os.getenv("WELCOME_MESSAGE")): + if os.path.isfile(os.getenv("WELCOME_MESSAGE")): with open(os.getenv("WELCOME_MESSAGE"), "r") as file: self.welcome_message = file.read() else: @@ -51,14 +51,15 @@ class MatrixModule(BotModule): "Welcome", self.welcome_message ) - for owner in bot.owners: - await bot.send_msg( - owner, - "Welcome Bot", - "Sent a welcome message to: {new_users}".format( - new_users=user_list + if len(user_list) > 0: + for owner in bot.owners: + await bot.send_msg( + owner, + "Welcome Bot", + "Sent a welcome message to: {new_users}".format( + new_users=user_list + ) ) - ) def get_user_list_delta( self, diff --git a/welcome.md b/welcome.md new file mode 100644 index 0000000..a67a121 --- /dev/null +++ b/welcome.md @@ -0,0 +1 @@ +Welcome to the server.