|
1 | 1 | import logging
|
2 | 2 | from datetime import datetime
|
3 | 3 |
|
| 4 | +import pandas as pd |
4 | 5 | import telegram
|
5 | 6 | from telegram import Update
|
6 | 7 | from telegram.ext import ContextTypes
|
|
10 | 11 | from src.models.bot_state import BotState
|
11 | 12 | from src.models.command_args import CommandArgs
|
12 | 13 | from definitions import ozjasz_phrases, bartosiak_phrases, tvp_headlines, tvp_latest_headlines, commands, bible_df, ArgType, shopping_sundays, USERS_PATH, arguments_help, europejskafirma_phrases, \
|
13 |
| - boczek_phrases |
| 14 | + boczek_phrases, kiepscy_df |
14 | 15 | import src.core.utils as core_utils
|
15 | 16 | import src.stats.utils as stats_utils
|
16 | 17 |
|
@@ -246,3 +247,47 @@ async def cmd_remind_me(self, update: Update, context: ContextTypes.DEFAULT_TYPE
|
246 | 247 | self.job_persistance.save_job(job_queue=context.job_queue, dt=dt, func=core_utils.send_response_message, args=[update.effective_chat.id, update.message.message_id, command_args.string])
|
247 | 248 | response = f"You're gonna get pinged at {core_utils.dt_to_pretty_str(dt)}."
|
248 | 249 | await context.bot.send_message(chat_id=update.effective_chat.id, text=response)
|
| 250 | + |
| 251 | + async def cmd_kiepscy(self, update: Update, context: ContextTypes.DEFAULT_TYPE): |
| 252 | + command_args = CommandArgs(args=context.args, expected_args=[ArgType.TEXT_MULTISPACED], min_string_length=1, max_string_length=1000) |
| 253 | + command_args = core_utils.parse_args(self.users_df, command_args) |
| 254 | + if command_args.error != '': |
| 255 | + await context.bot.send_message(chat_id=update.effective_chat.id, text=command_args.error) |
| 256 | + return |
| 257 | + |
| 258 | + search_phrase = command_args.string |
| 259 | + search_phrases = command_args.strings |
| 260 | + |
| 261 | + if search_phrases: # use & operator to match multiple words |
| 262 | + regex = core_utils.regexify_multiword_filter(search_phrases) |
| 263 | + matching_by_title_df = kiepscy_df[kiepscy_df['title'].str.contains(regex, case=False)] |
| 264 | + matching_by_description_df = kiepscy_df[kiepscy_df['description'].str.contains(regex, case=False)] |
| 265 | + else: |
| 266 | + matching_by_title_df = kiepscy_df[kiepscy_df['title'].str.contains(search_phrase, case=False)] |
| 267 | + matching_by_description_df = kiepscy_df[kiepscy_df['description'].str.contains(search_phrase, case=False)] |
| 268 | + merged_df = pd.concat([matching_by_title_df, matching_by_description_df], ignore_index=True) |
| 269 | + |
| 270 | + text = f"Kiepscy episodes that match [{search_phrase}]:\n" |
| 271 | + for i, (index, row) in enumerate(merged_df.iterrows()): |
| 272 | + description = f"{row['description'][:100]}.." if len(row['description']) > 100 else row['description'] |
| 273 | + text += f"- *{row['nr']}: {row['title']}* - {description}\n" |
| 274 | + text = stats_utils.escape_special_characters(text) |
| 275 | + await context.bot.send_message(chat_id=update.effective_chat.id, text=text, parse_mode=telegram.constants.ParseMode.MARKDOWN_V2) |
| 276 | + |
| 277 | + async def cmd_kiepscyurl(self, update: Update, context: ContextTypes.DEFAULT_TYPE): |
| 278 | + command_args = CommandArgs(args=context.args, expected_args=[ArgType.POSITIVE_INT], number_limit=1000) |
| 279 | + command_args = core_utils.parse_args(self.users_df, command_args) |
| 280 | + if command_args.error != '': |
| 281 | + await context.bot.send_message(chat_id=update.effective_chat.id, text=command_args.error) |
| 282 | + return |
| 283 | + |
| 284 | + episode_nr = str(command_args.number) |
| 285 | + matching_episode_df = kiepscy_df[kiepscy_df['nr'] == episode_nr] |
| 286 | + if matching_episode_df.empty: |
| 287 | + await context.bot.send_message(chat_id=update.effective_chat.id, text=f"Nie ma takiego epizodu :(") |
| 288 | + return |
| 289 | + row = matching_episode_df.iloc[0] |
| 290 | + text = f"*{episode_nr}: {row['title']}* - {row['url']}" |
| 291 | + |
| 292 | + text = stats_utils.escape_special_characters(text) |
| 293 | + await context.bot.send_message(chat_id=update.effective_chat.id, text=text, parse_mode=telegram.constants.ParseMode.MARKDOWN_V2) |
0 commit comments