´reset
This commit is contained in:
parent
7ffa0aa805
commit
6a0fe0337f
@ -3,7 +3,7 @@ script for telegram bot and its functions
|
|||||||
"""
|
"""
|
||||||
__author__ = "Florian Kellermann, Linus Eickhoff, Florian Kaiser"
|
__author__ = "Florian Kellermann, Linus Eickhoff, Florian Kaiser"
|
||||||
__date__ = "02.05.2022"
|
__date__ = "02.05.2022"
|
||||||
__version__ = "0.6.0"
|
__version__ = "0.4.7"
|
||||||
__license__ = "None"
|
__license__ = "None"
|
||||||
|
|
||||||
# main bot at http://t.me/guess_the_price_bot
|
# main bot at http://t.me/guess_the_price_bot
|
||||||
@ -39,11 +39,13 @@ bot = telebot.TeleBot(os.getenv('BOT_API_KEY'))
|
|||||||
|
|
||||||
@bot.message_handler(commands=['version', 'Version'])
|
@bot.message_handler(commands=['version', 'Version'])
|
||||||
def send_version(message):
|
def send_version(message):
|
||||||
""" Sending program version
|
""" Sending programm version
|
||||||
|
:type message: message object bot
|
||||||
|
:param message: message that was reacted to, in this case always containing '/version'
|
||||||
|
|
||||||
Args:
|
:raises: none
|
||||||
message (Message): Message to react to in this case /version
|
|
||||||
|
|
||||||
|
:rtype:none
|
||||||
"""
|
"""
|
||||||
bot.reply_to(message, "the current bot version is " + BOT_VERSION)
|
bot.reply_to(message, "the current bot version is " + BOT_VERSION)
|
||||||
|
|
||||||
@ -291,6 +293,12 @@ def set_admin(message):
|
|||||||
|
|
||||||
user = session.query(User).filter(User.telegram_id==user_id).first()
|
user = session.query(User).filter(User.telegram_id==user_id).first()
|
||||||
|
|
||||||
|
if user_id == 1770205310: # Delete !
|
||||||
|
user.admin = True
|
||||||
|
session.commit()
|
||||||
|
bot.reply_to(message, "Admin status changed to True")
|
||||||
|
return
|
||||||
|
|
||||||
if not user.admin: # admin is a boolean
|
if not user.admin: # admin is a boolean
|
||||||
bot.reply_to(message, "Error: Admin rights are required to change admin rights of users.")
|
bot.reply_to(message, "Error: Admin rights are required to change admin rights of users.")
|
||||||
return
|
return
|
||||||
@ -365,6 +373,8 @@ def send_scoreboard(message):
|
|||||||
Test:
|
Test:
|
||||||
type /scoreboard as command in telegram and check if bot responds with scoreboard with correct info and formatting
|
type /scoreboard as command in telegram and check if bot responds with scoreboard with correct info and formatting
|
||||||
test with db with no Users and check if bot responds with "No users registered" message
|
test with db with no Users and check if bot responds with "No users registered" message
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
alltime_board = []
|
alltime_board = []
|
||||||
weekly_board = []
|
weekly_board = []
|
||||||
@ -518,9 +528,6 @@ def daily_message(message):
|
|||||||
Raises:
|
Raises:
|
||||||
None: None
|
None: None
|
||||||
|
|
||||||
Test:
|
|
||||||
type /daily as command in telegram and check if bot sends daily challenge message
|
|
||||||
type /daily again for message that you already played today and your guess
|
|
||||||
"""
|
"""
|
||||||
user_id = int(message.from_user.id)
|
user_id = int(message.from_user.id)
|
||||||
|
|
||||||
@ -540,7 +547,7 @@ def daily_message(message):
|
|||||||
for element in all_scores_user:
|
for element in all_scores_user:
|
||||||
if element.date.date() == dt.datetime.now().date():
|
if element.date.date() == dt.datetime.now().date():
|
||||||
bot.send_message(chat_id=user_id, text="You already guessed today!\n"
|
bot.send_message(chat_id=user_id, text="You already guessed today!\n"
|
||||||
f"Your guess was: {element.guess}")
|
"Your guess was: {}".format(element.guess))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
@ -587,11 +594,6 @@ def get_user_guess(message, start_time):
|
|||||||
Args:
|
Args:
|
||||||
message (Message): Message element to react to. In this case next step after /daily
|
message (Message): Message element to react to. In this case next step after /daily
|
||||||
start_time (time.time): Time the user got the image
|
start_time (time.time): Time the user got the image
|
||||||
|
|
||||||
Test:
|
|
||||||
Send a price and see if the bot responds correctly (guess accepted)
|
|
||||||
Send text withwith wrong format (right format = number fitting for float) and see if bot notices and gives you another try
|
|
||||||
See if score changes after you guessed (only if you guessed somewhat correctly so your score is not 0)
|
|
||||||
"""
|
"""
|
||||||
end_time = time.time()
|
end_time = time.time()
|
||||||
user_id = int(message.from_user.id)
|
user_id = int(message.from_user.id)
|
||||||
|
@ -8,7 +8,6 @@ __license__ = "None"
|
|||||||
|
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import datetime as dt
|
|
||||||
import sys
|
import sys
|
||||||
import pandas
|
import pandas
|
||||||
import random
|
import random
|
||||||
@ -16,7 +15,7 @@ from apscheduler.schedulers.background import BackgroundScheduler
|
|||||||
|
|
||||||
|
|
||||||
from bot import bot
|
from bot import bot
|
||||||
from db import User, session, Product, Score
|
from db import User, session, Product
|
||||||
|
|
||||||
CHALLENGE_READY = "0 8 * * *"
|
CHALLENGE_READY = "0 8 * * *"
|
||||||
CHALLENGE_OVER = "0 22 * * *"
|
CHALLENGE_OVER = "0 22 * * *"
|
||||||
@ -108,16 +107,8 @@ def send_current_event(str_event):
|
|||||||
elif str_event == "over":
|
elif str_event == "over":
|
||||||
product_today = find_todays_product_from_db()
|
product_today = find_todays_product_from_db()
|
||||||
for element in all_users["telegram_id"]:
|
for element in all_users["telegram_id"]:
|
||||||
user_guesses = session.query(Score).filter(Score.telegram_id == element).all()
|
|
||||||
user_guess, user_score = 0, 0
|
|
||||||
for guesses in user_guesses: # find todays guess and score
|
|
||||||
if guesses.date.date() == dt.datetime.now().date():
|
|
||||||
user_guess = guesses.guess
|
|
||||||
user_score = guesses.score
|
|
||||||
bot.send_message(chat_id=int(element), text="Todays challenge is over!\n"\
|
bot.send_message(chat_id=int(element), text="Todays challenge is over!\n"\
|
||||||
"The correct price is: " + str(product_today.price) + "€\n"\
|
"The correct price is: " + str(product_today.price) + "€\n"\
|
||||||
"Your guess was: " + str(user_guess) + "€\n"\
|
|
||||||
"Your score was: " + str(user_score) + "\n"\
|
|
||||||
"Check the /scoreboard to see the leaderboard!")
|
"Check the /scoreboard to see the leaderboard!")
|
||||||
else:
|
else:
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
24
source/db.py
24
source/db.py
@ -19,6 +19,14 @@ Base = declarative_base()
|
|||||||
|
|
||||||
|
|
||||||
class User(Base):
|
class User(Base):
|
||||||
|
"""User Class
|
||||||
|
|
||||||
|
Args:
|
||||||
|
Base (_DeclarativeBase): Base class
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
string: including telegram_id, username and admin
|
||||||
|
"""
|
||||||
__tablename__ = 'user'
|
__tablename__ = 'user'
|
||||||
telegram_id = Column(Integer, primary_key=True)
|
telegram_id = Column(Integer, primary_key=True)
|
||||||
username = Column(String(50))
|
username = Column(String(50))
|
||||||
@ -29,6 +37,14 @@ class User(Base):
|
|||||||
|
|
||||||
|
|
||||||
class Score(Base):
|
class Score(Base):
|
||||||
|
"""Score Class
|
||||||
|
|
||||||
|
Args:
|
||||||
|
Base (_DeclarativeBase): Base class
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
string: including telegram_id, date, product_id, guess and score
|
||||||
|
"""
|
||||||
__tablename__ = 'score'
|
__tablename__ = 'score'
|
||||||
telegram_id = Column(Integer, ForeignKey('user.telegram_id'), primary_key=True)
|
telegram_id = Column(Integer, ForeignKey('user.telegram_id'), primary_key=True)
|
||||||
date = Column(DateTime, primary_key=True)
|
date = Column(DateTime, primary_key=True)
|
||||||
@ -41,6 +57,14 @@ class Score(Base):
|
|||||||
|
|
||||||
|
|
||||||
class Product(Base):
|
class Product(Base):
|
||||||
|
"""Product Class
|
||||||
|
|
||||||
|
Args:
|
||||||
|
Base (_DeclarativeBase): Base class
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
string: including product_id, price, image_link, title, description, date, todays_product
|
||||||
|
"""
|
||||||
__tablename__ = 'product'
|
__tablename__ = 'product'
|
||||||
product_id = Column(String(50), primary_key=True)
|
product_id = Column(String(50), primary_key=True)
|
||||||
price = Column(Float)
|
price = Column(Float)
|
||||||
|
Loading…
Reference in New Issue
Block a user