summaryrefslogtreecommitdiff
path: root/tgbot.py
blob: 97dcbd03fe57ea31e9e9a49894018571bbb0b260 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python3

import os
import time, threading, schedule
from telebot import TeleBot
from fortniteStatusWrapper import formatFortniteStatus
from pythonFortniteStatus.FortniteStatus import *

if "TELEBOT_BOT_TOKEN" not in os.environ:
    raise AssertionError("Please configure TELEBOT_BOT_TOKEN as environment variables")

bot = TeleBot(os.environ["TELEBOT_BOT_TOKEN"])
fortniteStatus = FortniteStatus()

@bot.message_handler(commands = ['start'])
def startCommand(message):
    bot.reply_to(message, "This bot is doing nothing so far..")

@bot.message_handler(commands = ['status'])
def fortniteStatusCommand(message):
    bot.send_message(
        message.chat.id,
        formatFortniteStatus(fortniteStatus.getStatus()),
        parse_mode='MarkdownV2'
    )

#bot.polling(none_stop=True, interval=0)

def beep(chat_id) -> None:
    """Send the beep message."""
    bot.send_message(chat_id, text='Beep!')


@bot.message_handler(commands=['set'])
def set_timer(message):
    args = message.text.split()
    if len(args) > 1 and args[1].isdigit():
        sec = int(args[1])
        schedule.every(sec).seconds.do(beep, message.chat.id).tag(message.chat.id)
    else:
        bot.reply_to(message, 'Usage: /set <seconds>')


@bot.message_handler(commands=['unset'])
def unset_timer(message):
    schedule.clear(message.chat.id)


if __name__ == '__main__':
    threading.Thread(target=bot.infinity_polling, name='bot_infinity_polling', daemon=True).start()
    while True:
        schedule.run_pending()
        time.sleep(1)