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