Compare commits

...

3 Commits

Author SHA1 Message Date
Stefano Assenzo 64cd15908b
Update requirements.txt 2023-03-06 17:24:40 +01:00
Stefano Assenzo 2ec9cfcc6d
Update main.py 2023-03-06 17:23:21 +01:00
Stefano Assenzo f3513ac50c
Update Dockerfile 2023-03-06 17:20:26 +01:00
3 changed files with 14 additions and 3 deletions

View File

@ -6,4 +6,6 @@ COPY . .
RUN pip install -r requirements.txt RUN pip install -r requirements.txt
CMD [ "python", "./main.py" ] CMD [ "python", "./main.py" ]
EXPOSE 8080/tcp

10
main.py
View File

@ -1,5 +1,6 @@
from src.commands import command_soon, command_subscribe, command_start, command_freegame #All commands of the bot are in the folder src.commands from src.commands import command_soon, command_subscribe, command_start, command_freegame #All commands of the bot are in the folder src.commands
from src.events import check_game #All events of the bot are in the folder src.events (ex. check_game = check when Epic Games change the game) from src.events import check_game #All events of the bot are in the folder src.events (ex. check_game = check when Epic Games change the game)
from flask import Flask
from bson.objectid import ObjectId #Library for MongoDB (read ObjectId) from bson.objectid import ObjectId #Library for MongoDB (read ObjectId)
from dotenv import load_dotenv #Library for .env file from dotenv import load_dotenv #Library for .env file
from telebot import telebot #Libraries for Telegram bot from telebot import telebot #Libraries for Telegram bot
@ -10,6 +11,7 @@ import threading #Library for threading (ex. Check game every 10 seconds)
#Load all variables from .env file #Load all variables from .env file
load_dotenv() #Load .env file load_dotenv() #Load .env file
app = Flask(__name__)
API_TOKEN = os.getenv('BOT_TOKEN') #Token for Telegram bot API_TOKEN = os.getenv('BOT_TOKEN') #Token for Telegram bot
USER_MONGO = os.getenv('USER_MONGODB') #User for MongoDB USER_MONGO = os.getenv('USER_MONGODB') #User for MongoDB
PASSWORD_MONGO = os.getenv('PASSWORD_MONGODB') #Password for MongoDB PASSWORD_MONGO = os.getenv('PASSWORD_MONGODB') #Password for MongoDB
@ -24,6 +26,10 @@ collection_game = database["list-game"] #Collection name (list-game)
bot = telebot.TeleBot(API_TOKEN) #Connect to Telegram API bot = telebot.TeleBot(API_TOKEN) #Connect to Telegram API
@app.route('/')
def homepage():
return 'Hello'
#Command /start #Command /start
@bot.message_handler(commands=['start']) @bot.message_handler(commands=['start'])
def start(message, bot=bot): def start(message, bot=bot):
@ -51,4 +57,6 @@ def event_game(collection_game=collection_game, collection_id=collection_id, bot
t1 = threading.Thread(target=event_game, args=()) t1 = threading.Thread(target=event_game, args=())
t1.start() t1.start()
bot.polling() if __name__ == '__main__':
app.run(port=8080)
bot.polling()

View File

@ -2,4 +2,5 @@ pytelegrambotapi == 4.7.0
python-dotenv == 0.20.0 python-dotenv == 0.20.0
requests == 2.28.1 requests == 2.28.1
schedule == 1.1.0 schedule == 1.1.0
pymongo[srv] == 4.1.1 pymongo[srv] == 4.1.1
Flask==2.2.2