|
1 | 1 | '''Telegram bot that (primarily) attempts to perform url hacks to get around paywalls''' |
2 | 2 |
|
3 | 3 |
|
4 | | -__version__ = '2.5.3' |
| 4 | +__version__ = '2.6.0' |
5 | 5 |
|
6 | 6 |
|
7 | 7 | import asyncio |
@@ -518,31 +518,40 @@ async def translate(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: |
518 | 518 | async def include(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: |
519 | 519 | '''Add domains to the set that gets acted on''' |
520 | 520 | incoming_text = '' |
521 | | - active_set = context.chat_data.get('active domains', set()) |
522 | | - try: |
523 | | - if context.args: # Directly add domain |
524 | | - domain = get_domain(context.args[0]) |
525 | | - text = f'{context.args[0]} added' |
526 | | - |
527 | | - elif update.effective_message.reply_to_message: # Add domain by replying to a message |
528 | | - incoming_text = update.effective_message.reply_to_message.text |
529 | | - incoming_id = update.effective_message.reply_to_message.message_id |
530 | | - url = get_url(incoming_text) |
531 | | - domain = text = get_domain(url) |
532 | | - if url: |
533 | | - text = await add_bypasses(url) |
534 | | - |
535 | | - else: # Add domain from last url |
536 | | - incoming_id, url = context.chat_data.get('last url') |
537 | | - domain = get_domain(url) |
538 | | - text = await add_bypasses(url) |
539 | 521 |
|
540 | | - except TypeError: |
541 | | - domain = text = 'no domain' |
| 522 | + def include_domain(domain: str) -> str: |
| 523 | + if domain == 'no domain': |
| 524 | + return 'No domain found to include' |
542 | 525 |
|
543 | | - if domain != 'no domain': |
| 526 | + active_set = context.chat_data.get('active domains', set()) |
544 | 527 | active_set.add(domain) |
545 | 528 | context.chat_data['active domains'] = active_set |
| 529 | + return f"Added {domain}" |
| 530 | + |
| 531 | + |
| 532 | + if update.effective_message.reply_to_message: # Add domain by replying to a message |
| 533 | + incoming_text = update.effective_message.reply_to_message.text |
| 534 | + incoming_id = update.effective_message.reply_to_message.message_id |
| 535 | + url = get_url(incoming_text) |
| 536 | + domain = get_domain(url) # Returns string 'no domain' if none found |
| 537 | + text = include_domain(domain) |
| 538 | + if url: |
| 539 | + text = await add_bypasses(url) |
| 540 | + |
| 541 | + elif context.args: # Directly add domain |
| 542 | + responses = [] |
| 543 | + for arg in context.args: |
| 544 | + domain = get_domain(arg) |
| 545 | + responses.append(include_domain(domain)) |
| 546 | + |
| 547 | + text = '\n'.join(responses) |
| 548 | + |
| 549 | + else: # Add domain from last url |
| 550 | + incoming_id, url = context.chat_data.get('last url') |
| 551 | + domain = get_domain(url) |
| 552 | + text = include_domain(domain) |
| 553 | + if url: |
| 554 | + text = await add_bypasses(url) |
546 | 555 |
|
547 | 556 | response_id = await say(text, update, context) |
548 | 557 | if response_id and incoming_text: |
|
0 commit comments