Skip to content

Commit

Permalink
fix indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
GauthamramRavichandran committed Oct 29, 2020
1 parent 9cdca4a commit 425e80b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
env/
.idea/
*.session
*.pyc
__pycache__/
Expand Down
47 changes: 24 additions & 23 deletions main_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

from CONFIG import api_hash, api_id, bot_token

logging.basicConfig(format='[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s',
level=logging.INFO)
logging.basicConfig(format = '[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s',
level = logging.INFO)

bot = TelegramClient('bot', api_id, api_hash).start(bot_token=bot_token)
bot = TelegramClient('bot', api_id, api_hash).start(bot_token = bot_token)


@bot.on(events.NewMessage(pattern = r'/start'))
async def start_hndlr(event):
async def start_hndlr( event ) :
await event.reply("""
🧹 I will get you the clear urls without any tracking data using Unalix library.
Expand All @@ -34,46 +34,47 @@ async def start_hndlr(event):


@bot.on(events.NewMessage(incoming = True))
async def clearurl_hndlr(event):
if event.message.via_bot is not None: # Don't handle inline messages
async def clearurl_hndlr( event ) :
if event.message.via_bot is not None : # Don't handle inline messages
return
if event.message.entities:
if event.message.entities :
to_send = []
for entity in event.message.entities:
for entity in event.message.entities :
url = None
if isinstance(entity, MessageEntityTextUrl):
if isinstance(entity, MessageEntityTextUrl) :
url = entity.url
elif isinstance(entity, MessageEntityUrl):
url = event.message.text[entity.offset:entity.offset+entity.length]
elif isinstance(entity, MessageEntityUrl) :
url = event.message.text[entity.offset :entity.offset + entity.length]

if url is not None:
if url is not None :
to_send.append(clear_url(url))
if to_send:
to_send_txt = "\n\n".join(i for i in to_send)
await event.reply(f"🧹 Cleaned URLs: "
f"\n{to_send_txt}", link_preview = False)
else:
if to_send :
to_send_txt = "\n\n".join(i for i in to_send)
await event.reply(f"🧹 Cleaned URLs: "
f"\n{to_send_txt}", link_preview = False)
else :
chat = await event.get_chat()
if isinstance(chat, User): # don't disturb the group, only throw error at private chat
if isinstance(chat, User) : # don't disturb the group, only throw error at private chat
await event.reply("The message did not contain any links for me to clean!")
raise events.StopPropagation


@bot.on(events.InlineQuery)
async def handler(event):
async def handler( event ) :
builder = event.builder
input_urls = []
if '\n' in event.text:
if '\n' in event.text :
input_urls.extend(event.text.split('\n'))
if ' ' in event.text:
if ' ' in event.text :
input_urls.extend(event.text.split(' '))

if input_urls:
if input_urls :
result = "\n".join(clear_url(link) for link in input_urls)
else:
else :
result = "No URLs found"
await event.answer([
builder.article('🧹 Cleaned URLs', text = result, link_preview = False)
])


bot.run_until_disconnected()

0 comments on commit 425e80b

Please sign in to comment.