Rename files and reorder main file

This commit is contained in:
Stefano Assenzo 2022-12-10 14:09:51 +00:00
parent e9365864a7
commit 42173ad5df
5 changed files with 29 additions and 29 deletions

58
main.py
View File

@ -1,41 +1,40 @@
#Libraries for Telegram bot 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 soon_command, subscribe_command, start_command, command_freegame 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 from bson.objectid import ObjectId #Library for MongoDB (read ObjectId)
import telebot from dotenv import load_dotenv #Library for .env file
from telebot import telebot from telebot import telebot #Libraries for Telegram bot
import os import os #Library for .env file (get env variables)
import sys import urllib #Library for MongoDB (read password)
import urllib import pymongo #Library for MongoDB
import pymongo import threading #Library for threading (ex. Check game every 10 seconds)
from bson.objectid import ObjectId
from dotenv import load_dotenv
import threading
#Load all variables from .env file
load_dotenv() #Load .env file
API_TOKEN = os.getenv('BOT_TOKEN') #Token for Telegram bot
PASSWORD_MONGO = os.getenv('PASSWORD_MONGODB') #Password for MongoDB
URL_MONGO = os.getenv('URL_MONGODB') #URL for MongoDB
OBJECTID_game1 = os.getenv('OBJECTID_game1') #ObjectID for game1 in MongoDB
OBJECTID_game2 = os.getenv('OBJECTID_game2') #ObjectID for game2 in MongoDB
OBJECTID_idlist = os.getenv('OBJECTID_idlist') #ObjectID for idlist in MongoDB
load_dotenv() #Connect to MongoDB
API_TOKEN = os.getenv('BOT_TOKEN') mongo_url = "mongodb+srv://stefano:" + urllib.parse.quote_plus(PASSWORD_MONGO) + URL_MONGO #URL for MongoDB (with password)
PASSWORD_MONGO = os.getenv('PASSWORD_MONGODB') client = pymongo.MongoClient(mongo_url) #Connect to MongoDB
URL_MONGO = os.getenv('URL_MONGODB') database = client["epicgames-notifier"] #Database name
OBJECTID_game1 = os.getenv('OBJECTID_game1') collection_id = database["id-user"] #Collection name (id-user)
OBJECTID_game2 = os.getenv('OBJECTID_game2') collection_game = database["list-game"] #Collection name (list-game)
OBJECTID_idlist = os.getenv('OBJECTID_idlist')
bot = telebot.TeleBot(API_TOKEN) bot = telebot.TeleBot(API_TOKEN) #Connect to Telegram API
mongo_url = "mongodb+srv://stefano:" + urllib.parse.quote_plus(PASSWORD_MONGO) + URL_MONGO
client = pymongo.MongoClient(mongo_url)
database = client["epicgames-notifier"]
collection_id = database["id-user"]
collection_game = database["list-game"]
#Command /start #Command /start
@bot.message_handler(commands=['start']) @bot.message_handler(commands=['start'])
def start(message, bot=bot): def start(message, bot=bot):
start_command.start_command(message, bot) command_start.start_command(message, bot)
#Command /comingsoon #Command /comingsoon
@bot.message_handler(commands=['comingsoon']) @bot.message_handler(commands=['comingsoon'])
def comingsoon(message, bot=bot): def comingsoon(message, bot=bot):
soon_command.soon_command(message, bot) command_soon.soon_command(message, bot)
#Command /freenow #Command /freenow
@bot.message_handler(commands=['freenow']) @bot.message_handler(commands=['freenow'])
@ -45,11 +44,12 @@ def freegame_command(message, bot=bot):
#Command /subscribe #Command /subscribe
@bot.message_handler(commands=['subscribe']) @bot.message_handler(commands=['subscribe'])
def subscribe(message, bot=bot, collection_game=collection_game): def subscribe(message, bot=bot, collection_game=collection_game):
subscribe_command.subscribe_command(message, bot, collection_game) command_subscribe.subscribe_command(message, bot, collection_game)
def event_game(collection_game=collection_game, collection_id=collection_id, bot=bot, OBJECTID_idlist=OBJECTID_idlist, OBJECTID_game1=OBJECTID_game1, OBJECTID_game2=OBJECTID_game2): def event_game(collection_game=collection_game, collection_id=collection_id, bot=bot, OBJECTID_idlist=OBJECTID_idlist, OBJECTID_game1=OBJECTID_game1, OBJECTID_game2=OBJECTID_game2):
check_game.a(collection_game, collection_id, bot, OBJECTID_idlist, OBJECTID_game1, OBJECTID_game2) check_game.a(collection_game, collection_id, bot, OBJECTID_idlist, OBJECTID_game1, OBJECTID_game2)
#Threading for check game every 5 seconds
t1 = threading.Thread(target=event_game, args=()) t1 = threading.Thread(target=event_game, args=())
t1.start() t1.start()