2022-09-05 15:53:42 +02:00
|
|
|
#Libraries for Telegram bot
|
2022-12-10 14:49:04 +01:00
|
|
|
from src.commands import soon_command, subscribe_command, start_command, command_freegame
|
|
|
|
from src.events import check_game
|
2022-09-05 15:53:42 +02:00
|
|
|
import telebot
|
2022-09-11 12:04:51 +02:00
|
|
|
from telebot import telebot
|
2022-09-05 15:53:42 +02:00
|
|
|
import os
|
2022-12-10 14:49:04 +01:00
|
|
|
import sys
|
2022-09-08 13:26:38 +02:00
|
|
|
import urllib
|
|
|
|
import pymongo
|
|
|
|
from bson.objectid import ObjectId
|
2022-12-10 14:49:04 +01:00
|
|
|
from dotenv import load_dotenv
|
2022-12-09 13:32:36 +01:00
|
|
|
import threading
|
2022-09-11 11:03:52 +02:00
|
|
|
|
2022-12-10 14:49:04 +01:00
|
|
|
|
2022-09-05 15:53:42 +02:00
|
|
|
load_dotenv()
|
|
|
|
API_TOKEN = os.getenv('BOT_TOKEN')
|
2022-09-11 12:04:51 +02:00
|
|
|
PASSWORD_MONGO = os.getenv('PASSWORD_MONGODB')
|
|
|
|
URL_MONGO = os.getenv('URL_MONGODB')
|
2022-12-09 13:32:36 +01:00
|
|
|
OBJECTID_game1 = os.getenv('OBJECTID_game1')
|
|
|
|
OBJECTID_game2 = os.getenv('OBJECTID_game2')
|
|
|
|
OBJECTID_idlist = os.getenv('OBJECTID_idlist')
|
2022-09-05 15:53:42 +02:00
|
|
|
bot = telebot.TeleBot(API_TOKEN)
|
2022-09-11 12:04:51 +02:00
|
|
|
mongo_url = "mongodb+srv://stefano:" + urllib.parse.quote_plus(PASSWORD_MONGO) + URL_MONGO
|
2022-09-08 13:26:38 +02:00
|
|
|
client = pymongo.MongoClient(mongo_url)
|
2022-12-09 13:32:36 +01:00
|
|
|
database = client["epicgames-notifier"]
|
|
|
|
collection_id = database["id-user"]
|
|
|
|
collection_game = database["list-game"]
|
2022-09-08 13:26:38 +02:00
|
|
|
|
2022-09-05 15:53:42 +02:00
|
|
|
#Command /start
|
|
|
|
@bot.message_handler(commands=['start'])
|
2022-12-10 14:49:04 +01:00
|
|
|
def start(message, bot=bot):
|
|
|
|
start_command.start_command(message, bot)
|
|
|
|
|
2022-09-05 15:53:42 +02:00
|
|
|
|
2022-09-05 16:48:37 +02:00
|
|
|
#Command /comingsoon
|
|
|
|
@bot.message_handler(commands=['comingsoon'])
|
2022-12-10 14:49:04 +01:00
|
|
|
def comingsoon(message, bot=bot):
|
|
|
|
soon_command.soon_command(message, bot)
|
2022-09-05 16:59:09 +02:00
|
|
|
|
2022-09-05 17:18:59 +02:00
|
|
|
#Command /freenow
|
|
|
|
@bot.message_handler(commands=['freenow'])
|
2022-12-10 14:49:04 +01:00
|
|
|
def freegame_command(message, bot=bot):
|
|
|
|
command_freegame.freegame_command(message, bot)
|
2022-09-05 17:18:59 +02:00
|
|
|
|
2022-09-08 13:26:38 +02:00
|
|
|
#Command /subscribe
|
|
|
|
@bot.message_handler(commands=['subscribe'])
|
2022-12-10 14:49:04 +01:00
|
|
|
def subscribe(message, bot=bot, collection_game=collection_game):
|
|
|
|
subscribe_command.subscribe_command(message, bot, collection_game)
|
2022-12-07 17:15:09 +01:00
|
|
|
|
2022-12-10 14:49:04 +01:00
|
|
|
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)
|
2022-09-11 10:49:13 +02:00
|
|
|
|
2022-12-10 14:49:04 +01:00
|
|
|
t1 = threading.Thread(target=event_game, args=())
|
2022-12-09 13:32:36 +01:00
|
|
|
t1.start()
|
|
|
|
|
2022-12-10 14:49:04 +01:00
|
|
|
bot.polling()
|