implemented /news and deleted debugbot (edit BOT_API_KEY instead) #2

Merged
Rripped merged 40 commits from bot-features into main 2022-03-16 09:08:43 +00:00
Showing only changes of commit 50a4df4e71 - Show all commits

View File

@ -9,7 +9,7 @@ __license__ = "None"
# side-dependencies: none
# Work in Progress
# Api-Key: 5228016873:AAGFrh0P6brag7oD3gxXjCh5gnLLE8JMvMs
# Api-Key: 5228016873:AAGFrh0P6brag7oD3gxXjCh5gnLLE8JMvMs /debugAPI Key: 5108535940:AAF5FpPHNV96WxGCDt8aMrGGKke1VILYib4 (https://t.me/mynewdebugbot)
# text bot at t.me/projektaktienbot
# API Documentation https://core.telegram.org/bots/api
# Code examples https://github.com/eternnoir/pyTelegramBotAPI#getting-started
@ -21,7 +21,12 @@ import time
import sys
import logging
import news_fetcher
from telebot import types
from dotenv import load_dotenv
load_dotenv()
bot_version = "0.0.1"
user_list = []
@ -32,6 +37,7 @@ class User: # Currently saving users in this class to test functionality -> late
self.chat_id = int(p_chat_id)
self.user_name = str(p_user_name)
print(os.getenv('BOT_API_KEY'))
bot = telebot.TeleBot(os.getenv('BOT_API_KEY'))
@bot.message_handler(commands=['start']) # /start -> saving as new user and sending welcome
@ -45,15 +51,18 @@ def send_start(message):
user_list.append(new_user)
bot.reply_to(message, "Welcome to this share bot project. Type /help to get information on what this bot can do")
@bot.message_handler(commands=['version'])
def send_version(message):
bot.reply_to(message, bot_version)
@bot.message_handler(commands=['help']) # /help -> sending all functions
def send_welcome(message):
bot.reply_to(message, "/id or /auth for authentication. /update to get updates on your shares. /users to see all users. For further details see aktienbot.flokaiser.com")
@bot.message_handler(commands=['users'])
def send_all_users(message):
print('Debug: users command')
@ -78,6 +87,15 @@ def send_update(message):
bot.send_message(chat_id=user_id, text='This is your update')
@bot.message_handler(commands=['news']) # /news -> send news by keyword
def send_news(message):
user_id = int(message.from_user.id)
#Get Information for user with this id
articles = news_fetcher.get_top_news_by_keyword("bitcoin") #tbd: get keyword from db
formatted_article = news_fetcher.format_article(articles["articles"][0])
bot.send_message(chat_id=user_id, text=formatted_article)
@bot.message_handler(func=lambda message: True) # Returning that command is unkown for any other statement
def echo_all(message):
answer = 'Do not know this command or text: ' + message.text