diff options
author | clarkzjw <[email protected]> | 2023-02-20 01:55:20 -0800 |
---|---|---|
committer | clarkzjw <[email protected]> | 2023-02-20 01:55:20 -0800 |
commit | 3a230798be1bc63b363cf75b8b1cae3a508cca84 (patch) | |
tree | 6df81aa7028c130726cdf0bcc3abb4f6f106fdf3 /bot.py | |
parent | 48cd0ed8abf0e84fc5d013a126e84c65ef0ed87a (diff) | |
download | swarm2fediverse-3a230798be1bc63b363cf75b8b1cae3a508cca84.tar.gz |
4sq: add query poi example
Diffstat (limited to 'bot.py')
-rw-r--r-- | bot.py | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -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 | ) |
24 | from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update | 24 | from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update |
25 | from telegram.ext import Application, CallbackQueryHandler, CommandHandler, ContextTypes | 25 | from telegram.ext import Application, CallbackQueryHandler, CommandHandler, ContextTypes, MessageHandler, filters |
26 | |||
27 | from config import BOT_TOKEN | ||
28 | from foursquare.query_poi import query_poi | ||
29 | |||
26 | 30 | ||
27 | # Enable logging | 31 | # Enable logging |
28 | logging.basicConfig( | 32 | logging.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 | ||
53 | async 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 | |||
49 | async def button(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: | 60 | async 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 | |||
65 | def main() -> None: | 76 | def 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 |