diff --git a/discord/discordBot.py b/discord/Dockerfile similarity index 100% rename from discord/discordBot.py rename to discord/Dockerfile diff --git a/discordBot.py b/discordBot.py new file mode 100644 index 0000000..e69de29 diff --git a/functions.py b/functions.py index 5847b6e..b9467d9 100644 --- a/functions.py +++ b/functions.py @@ -37,4 +37,3 @@ def nextLaunch(): "video": data["vidURLs"][0], } return launch - diff --git a/telegram/Dockerfile b/telegram/Dockerfile new file mode 100644 index 0000000..e69de29 diff --git a/telegram/telegramBot.py b/telegram/telegramBot.py deleted file mode 100644 index 8001d14..0000000 --- a/telegram/telegramBot.py +++ /dev/null @@ -1,13 +0,0 @@ -from telegram.ext import Updater, CommandHandler - - -def hello(bot, update): - update.message.reply_text("Hello {}".format(update.message.from_user.first_name)) - - -updater = Updater("TOKEN") - -updater.dispatcher.add_handler(CommandHandler("hello", hello)) - -updater.start_polling() -updater.idle() diff --git a/telegramBot.py b/telegramBot.py new file mode 100644 index 0000000..404fc6a --- /dev/null +++ b/telegramBot.py @@ -0,0 +1,64 @@ +# Works with Python 3.7 +import logging +import os + +import telegram +from functions import nextLaunch +from telegram.ext import CommandHandler, Filters, MessageHandler, Updater + +TELEGRAM_TOKEN = os.environ["TELEGRAM"] + +# Enable logging +logging.basicConfig( + format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO +) + +logger = logging.getLogger(__name__) +print("Bot Online") + + +# Define a few command handlers. These usually take the two arguments bot and +# update. Error handlers also receive the raised TelegramError object in error. +def start(bot, update): + """Send a message when the command /start is issued.""" + update.message.reply_text("I am started and ready to go!") + + +def nextRocketLaunch(): + nextLaunch() + + + + + +def error(bot, update, error): + """Log Errors caused by Updates.""" + logger.warning('Update "%s" caused error "%s"', update, error) + + +def main(): + """Start the bot.""" + # Create the EventHandler and pass it your bot's token. + updater = Updater(TELEGRAM_TOKEN) + + # Get the dispatcher to register handlers + dp = updater.dispatcher + + # on different commands - answer in Telegram + dp.add_handler(CommandHandler("start", start)) + dp.add_handler(CommandHandler("Launch", nextRocketLaunch)) + + # log all errors + dp.add_error_handler(error) + + # Start the Bot + updater.start_polling() + + # Run the bot until you press Ctrl-C or the process receives SIGINT, + # SIGTERM or SIGABRT. This should be used most of the time, since + # start_polling() is non-blocking and will stop the bot gracefully. + updater.idle() + + +if __name__ == "__main__": + main()