aboutsummaryrefslogtreecommitdiff
path: root/bot.py
diff options
context:
space:
mode:
Diffstat (limited to 'bot.py')
-rw-r--r--bot.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/bot.py b/bot.py
index 517f810..e010516 100644
--- a/bot.py
+++ b/bot.py
@@ -22,7 +22,11 @@ if __version_info__ < (20, 0, 0, "alpha", 1):
22 f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html" 22 f"visit https://docs.python-telegram-bot.org/en/v{TG_VER}/examples.html"
23 ) 23 )
24from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update 24from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
25from telegram.ext import Application, CallbackQueryHandler, CommandHandler, ContextTypes 25from telegram.ext import Application, CallbackQueryHandler, CommandHandler, ContextTypes, MessageHandler, filters
26
27from config import BOT_TOKEN
28from foursquare.query_poi import query_poi
29
26 30
27# Enable logging 31# Enable logging
28logging.basicConfig( 32logging.basicConfig(
@@ -46,6 +50,13 @@ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
46 await update.message.reply_text("Please choose:", reply_markup=reply_markup) 50 await update.message.reply_text("Please choose:", reply_markup=reply_markup)
47 51
48 52
53async def checkin(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
54 print(update.message.location.latitude)
55 print(update.message.location.longitude)
56 poi = query_poi(update.message.location.latitude, update.message.location.longitude)
57 await update.message.reply_text("Your location received: {}".format(poi))
58
59
49async def button(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: 60async def button(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
50 """Parses the CallbackQuery and updates the message text.""" 61 """Parses the CallbackQuery and updates the message text."""
51 query = update.callback_query 62 query = update.callback_query
@@ -65,10 +76,13 @@ async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
65def main() -> None: 76def main() -> None:
66 """Run the bot.""" 77 """Run the bot."""
67 # Create the Application and pass it your bot's token. 78 # Create the Application and pass it your bot's token.
68 application = Application.builder().token("TOKEN").build() 79 application = Application.builder().token(BOT_TOKEN).build()
69 80
70 application.add_handler(CommandHandler("start", start)) 81 application.add_handler(CommandHandler("start", start))
82 application.add_handler(CommandHandler("checkin", checkin))
71 application.add_handler(CallbackQueryHandler(button)) 83 application.add_handler(CallbackQueryHandler(button))
84 # on non command i.e message - echo the message on Telegram
85 application.add_handler(MessageHandler(filters.LOCATION & ~filters.COMMAND, checkin))
72 application.add_handler(CommandHandler("help", help_command)) 86 application.add_handler(CommandHandler("help", help_command))
73 87
74 # Run the bot until the user presses Ctrl-C 88 # Run the bot until the user presses Ctrl-C
Powered by cgit v1.2.3 (git 2.41.0)