From 90c018165f4a53dfd0acebc4db6a3c8ea4f60c35 Mon Sep 17 00:00:00 2001 From: Michael De Roover Date: Fri, 26 Mar 2021 21:51:02 +0100 Subject: [PATCH] Use a config file for credentials --- .gitignore | 1 + install | 17 +++++++++++++++++ ubot.py | 4 +--- 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100755 install diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4acd06b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.py diff --git a/install b/install new file mode 100755 index 0000000..ef9f776 --- /dev/null +++ b/install @@ -0,0 +1,17 @@ +#!/bin/sh + +# Functions +mkconfig(){ + echo "Please get your credentials from https://my.telegram.org." + read -p "App API ID (api_id): " api_id + read -p "App API hash (api_hash): " api_hash + echo "api_id = $api_id" >> config.py + echo "api_hash = '$api_hash'" >> config.py +} + +# Preliminary sanity checks +[ ! -f ubot.py ] && echo "ubot.py not found, quitting." && exit 1 +[ $0 != ./install ] && echo "Not launched from current directory." && exit 1 +[ ! -f config.py ] && mkconfig + +return 0 diff --git a/ubot.py b/ubot.py index d21721f..984a48c 100755 --- a/ubot.py +++ b/ubot.py @@ -1,10 +1,8 @@ #!/usr/bin/python3 import os from telethon import TelegramClient, events +from config import * -# Use your own values from my.telegram.org -api_id = os.environ['api_id'] -api_hash = os.environ['api_hash'] client = TelegramClient('ubot', api_id, api_hash) @client.on(events.NewMessage)