Merge pull request #2 from stevavoliajvar/feature/use-config-file

Added config parser and example config.ini file, removed hardcoded va…
This commit is contained in:
Aleksej 2022-06-12 22:04:32 +00:00 committed by GitHub
commit 21404a22a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 5 deletions

6
config.ini Normal file
View File

@ -0,0 +1,6 @@
[credentials]
JID = "botusername@example.org"
PASSWORD = "bot_password"
NICK = "mirrorbot"
ROOM1 = "room1_jid@example1.org"
ROOM2 = "room2_jid@example2.org"

View File

@ -2,12 +2,9 @@
# XMPP bot that mirrors chat between two MUC rooms # XMPP bot that mirrors chat between two MUC rooms
import argparse import argparse
import slixmpp import slixmpp
import configparser
JID='bot_username@example.org' CONFIG_PATH = "./config.ini"
PASSWORD='bot_password'
NICK = 'mirrorbot'
ROOM1 = 'room1_jid@example1.org'
ROOM2 = 'room2_jid@example2.org'
VERSION='0.1.0' VERSION='0.1.0'
@ -51,6 +48,14 @@ if __name__ == '__main__':
print("There is NO WARRANTY, to the extent permitted by law.") print("There is NO WARRANTY, to the extent permitted by law.")
exit() 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 = MUCBot(JID, PASSWORD, NICK, ROOM1, ROOM2)
xmpp.register_plugin('xep_0030') # Service Discovery xmpp.register_plugin('xep_0030') # Service Discovery