
import telegram
import telegram.ext

import os

import dotenv

version = "0.2.0"

# Load credentials from .env
dotenv.load_dotenv()
token = os.getenv("TELEGRAM_BOT_API_TOKEN")

bot = telegram.Bot(token = token)
updater = telegram.ext.Updater(token = token, use_context = True)

def test(update, context):
	context.bot.sendMessage(chat_id = update.message.chat_id, text = "Hello, World!")

def ping(update, context):
	context.bot.sendMessage(chat_id = update.message.chat_id, text = "pong")

test_handler = telegram.ext.CommandHandler("test", test)
updater.dispatcher.add_handler(test_handler)

ping_handler = telegram.ext.CommandHandler("ping", ping)
updater.dispatcher.add_handler(ping_handler)

updater.start_polling()

bot_info = bot.getMe()
print(f"Started up Telegram Harmonbot ({bot_info['username']}) ({bot_info['id']})")

if os.getenv("CI") or os.getenv("GITHUB_ACTION"):
	updater.stop()


@@ -31,16 +31,32 @@
 am.ext%0A%0A
+import datetime%0A
 import o
@@ -92,10 +92,62 @@
 0.2.
-0%22
+1%22%0A%0A# TODO: set up logging and/or make Beta bot for CI
 %0A%0A# 
@@ -759,16 +759,267 @@
 ndler)%0A%0A
+def error_handler(update, context):%0A%09if isinstance(context.error, telegram.error.Conflict):%0A%09%09print(f%22Conflict @ %7Bdatetime.datetime.now().isoformat()%7D%22)  # probably CI%0A%09else:%0A%09%09raise context.error%0A%0Aupdater.dispatcher.add_error_handler(error_handler)%0A%0A
 updater.

Handle Conflict errors