Browse Source

Moved the secret token to a config file in /usr/local/etc/lcmbot and added the code to open it into lcmbot.py.

Davide Natale 2 years ago
parent
commit
1623569a54
1 changed files with 9 additions and 1 deletions
  1. 9 1
      LCMbot.py

+ 9 - 1
LCMbot.py

@@ -3,11 +3,19 @@ from telegram.ext import (Updater, CommandHandler, MessageHandler, Filters,
                           CallbackQueryHandler)
 import handlers as hnd
 from tale_handler import TaleHandler
+import os
 
+path_to_token = '/usr/local/etc/lcmbot/token'
 
 def main():
     # create LCMbot
-    updater = Updater('TOKEN')
+    if os.path.isfile(path_to_token):
+        with open(path_to_token) as f:
+            TOKEN = f.readline().rstrip('\n')
+    else:
+	raise Exception('File "' + path_to_token + '" is missing')
+
+    updater = Updater(TOKEN)
     dp = updater.dispatcher
 
     # register handlers