Use a config file for credentials

This commit is contained in:
Michael De Roover 2021-03-26 21:51:02 +01:00
parent 7fd51b127d
commit 90c018165f
Signed by: vim
GPG Key ID: 075496E232CE04CB
3 changed files with 19 additions and 3 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
config.py

17
install Executable file
View File

@ -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

View File

@ -1,10 +1,8 @@
#!/usr/bin/python3 #!/usr/bin/python3
import os import os
from telethon import TelegramClient, events 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 = TelegramClient('ubot', api_id, api_hash)
@client.on(events.NewMessage) @client.on(events.NewMessage)