New try for bot and bot_updates #80
@ -14,6 +14,7 @@ __license__ = "None"
|
||||
# API Documentation https://core.telegram.org/bots/api
|
||||
# Code examples https://github.com/eternnoir/pyTelegramBotAPI#getting-started
|
||||
|
||||
import email
|
||||
import os
|
||||
|
||||
import telebot
|
||||
@ -32,16 +33,16 @@ from dotenv import load_dotenv
|
||||
from api_handling.api_handler import API_Handler
|
||||
|
||||
|
||||
load_dotenv(dotenv_path='.env')
|
||||
load_dotenv(dotenv_path='.env') # load environment variables
|
||||
|
||||
bot_version = "1.0.1"
|
||||
user_list = []
|
||||
|
||||
#create api handler
|
||||
api_handler = API_Handler("https://gruppe1.testsites.info/api", str(os.getenv("BOT_EMAIL")), str(os.getenv("BOT_PASSWORD")))
|
||||
api_handler = API_Handler("https://gruppe1.testsites.info/api", str(os.getenv("BOT_EMAIL")), str(os.getenv("BOT_PASSWORD"))) # get creds from env vars.
|
||||
print("Webserver Token: " + str(api_handler.token))
|
||||
|
||||
class User: # Currently saving users in this class to test functionality -> later database
|
||||
class User: # Currently saving users in this class to test functionality -> later database REMOVABLE
|
||||
def __init__(self, p_user_id, p_user_name, p_chat_id):
|
||||
|
||||
""" Initialize a new user
|
||||
@ -79,7 +80,7 @@ def send_start(message):
|
||||
|
||||
:rtype: none
|
||||
"""
|
||||
new_user = User(int(message.from_user.id), message.from_user.first_name, int(message.chat.id))
|
||||
new_user = User(int(message.from_user.id), message.from_user.first_name, int(message.chat.id)) # now Database driven CHANGE
|
||||
existing_already = False
|
||||
for known_user in user_list:
|
||||
if known_user.user_id == new_user.user_id:
|
||||
@ -129,7 +130,6 @@ def send_all_users(message):
|
||||
|
||||
:rtype: none
|
||||
"""
|
||||
print('Debug: users command')
|
||||
user_id = int(message.from_user.id)
|
||||
|
||||
# tbd check if user is admin
|
||||
@ -152,12 +152,16 @@ def send_user(message):
|
||||
:rtype: none
|
||||
"""
|
||||
user_id = int(message.from_user.id)
|
||||
user_data = api_handler.get_user(user_id) # tbd: formatting
|
||||
if not user_data or user_data == None:
|
||||
user_data = api_handler.get_user(user_id)
|
||||
if not user_data or user_data == None: # true if user is not registered
|
||||
bot.reply_to(message, "This didn\'t work. Make sure to connect your telegram id (/id) on https://gruppe1.testsites.info")
|
||||
return
|
||||
|
||||
bot.reply_to(message, 'Your user data:\n' + str(user_data))
|
||||
username = user_data['username']
|
||||
email = user_data['email']
|
||||
user_id = user_data['telegram_user_id']
|
||||
cron = user_data['cron']
|
||||
admin = user_data['admin']
|
||||
bot.reply_to(message, f'Username: {username}\nEmail: {email}\nID: {user_id}\nCron: {cron}\nAdmin: {admin}') # format user data into readable message text
|
||||
|
||||
|
||||
@bot.message_handler(commands=['id', 'auth', 'Id', 'Auth']) # /auth or /id -> Authentication with user_id over web tool
|
||||
|
Loading…
Reference in New Issue
Block a user