Skip to content

Commit b14ce3d

Browse files
committed
Modify /include to be more like /remove
Also (re?)adds ability to /include domain1 domain2
1 parent fbda647 commit b14ce3d

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

bot.py

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'''Telegram bot that (primarily) attempts to perform url hacks to get around paywalls'''
22

33

4-
__version__ = '2.5.3'
4+
__version__ = '2.6.0'
55

66

77
import asyncio
@@ -518,31 +518,40 @@ async def translate(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
518518
async def include(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
519519
'''Add domains to the set that gets acted on'''
520520
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)
539521

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'
542525

543-
if domain != 'no domain':
526+
active_set = context.chat_data.get('active domains', set())
544527
active_set.add(domain)
545528
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)
546555

547556
response_id = await say(text, update, context)
548557
if response_id and incoming_text:

0 commit comments

Comments
 (0)