Skip to content

Commit

Permalink
Update ampremover.py
Browse files Browse the repository at this point in the history
  • Loading branch information
BenCos17 committed Dec 6, 2024
1 parent 57cae9b commit 7da51b1
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions ampremover/ampremover.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,15 @@ async def opt_out(self, ctx):
@amputator.command(name='convert')
async def convert_amp(self, ctx, *, message: str):
"""Converts AMP URLs to canonical URLs using AmputatorBot API"""
if ctx.guild is None: # DM context
if ctx.author.id not in self.opted_in_users:
await ctx.send(f"{ctx.author.mention}, you need to opt-in to use this service in DMs. Use the `[p]amputator optin` command.")
return
else: # Server context
if ctx.guild.id not in self.opted_in_servers:
await ctx.send(f"Server {ctx.guild.name} needs to opt-in to use this service. Use the `[p]amputator optin` command.")
return

urls = re.findall(r'(https?://\S+)', message)
if not urls:
await ctx.send("No URLs found in the message.")
return

if ctx.guild is not None and ctx.guild.id not in self.opted_in_servers:
# If the server hasn't opted in, do not respond
return

canonical_links = []
for url in urls:
api_url = f"https://www.amputatorbot.com/api/v1/convert?gac=true&md=3&q={url}"
Expand Down

0 comments on commit 7da51b1

Please sign in to comment.