From f2707e440fee6c4650d4354d30ea907fbf5188fc Mon Sep 17 00:00:00 2001 From: nop surfer Date: Sun, 12 Jun 2022 23:33:56 +0200 Subject: [PATCH] Added config parser and example config.ini file, removed hardcoded values from code --- config.ini | 6 ++++++ xmppmirror | 15 ++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 config.ini diff --git a/config.ini b/config.ini new file mode 100644 index 0000000..74bf58d --- /dev/null +++ b/config.ini @@ -0,0 +1,6 @@ +[credentials] +JID = "botusername@example.org" +PASSWORD = "bot_password" +NICK = "mirrorbot" +ROOM1 = "room1_jid@example1.org" +ROOM2 = "room2_jid@example2.org" diff --git a/xmppmirror b/xmppmirror index 7b9bff8..ea17fdc 100755 --- a/xmppmirror +++ b/xmppmirror @@ -2,12 +2,9 @@ # XMPP bot that mirrors chat between two MUC rooms import argparse import slixmpp +import configparser -JID='bot_username@example.org' -PASSWORD='bot_password' -NICK = 'mirrorbot' -ROOM1 = 'room1_jid@example1.org' -ROOM2 = 'room2_jid@example2.org' +CONFIG_PATH = "./config.ini" VERSION='0.1.0' @@ -51,6 +48,14 @@ if __name__ == '__main__': print("There is NO WARRANTY, to the extent permitted by law.") exit() + config = configparser.ConfigParser() + config.read(CONFIG_PATH) + JID = config.get('credentials', 'JID') + PASSWORD = config.get('credentials', 'PASSWORD') + NICK = config.get('credentials', 'NICK') + ROOM1 = config.get('credentials', 'ROOM1') + ROOM2 = config.get('credentials', 'ROOM2') + xmpp = MUCBot(JID, PASSWORD, NICK, ROOM1, ROOM2) xmpp.register_plugin('xep_0030') # Service Discovery