Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apollo.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"cogs.commands.xkcd",
"cogs.commands.market",
"cogs.commands.auction",
"cogs.commands.unpaywall",
"cogs.channel_checker",
"cogs.database",
"cogs.irc",
Expand Down
37 changes: 37 additions & 0 deletions cogs/commands/unpaywall.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import discord
from discord.ext import commands
from discord.ext.commands import Bot, Context

LONG_HELP_TEXT = """
Generate a non-paywalled link from an existing URL using 12ft.io and web.archive.org
"""

SHORT_HELP_TEXT = """Generate non-paywalled link"""

class UnpaywallCog(commands.Cog):
def __init__(self, bot: Bot):
self.bot = bot

def get_unpaywalled_link(self, url):
"""Generate alternative links for bypassing paywalls."""
services = {
"🔓 12ft.io": f"https://12ft.io/{url}",
"📅 Web Archive": f"https://web.archive.org/web/{url}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add archive.is here too http://archive.is/newest/{url}

}
return services

@commands.hybrid_command(help=LONG_HELP_TEXT, brief=SHORT_HELP_TEXT)
async def unpaywall(self, ctx: Context, url: str):
if not url.startswith("http") and not url.startswith("https"):
await ctx.send("Please provide a valid URL.")

services = self.get_unpaywalled_link(url)

embed = discord.Embed(title="Non-Paywalled Links", color=0x3498db)
for name, link in services.items():
embed.add_field(name=name, value=f"[Click Here]({link})", inline=False)

await ctx.reply(embed=embed)

async def setup(bot: Bot):
await bot.add_cog(UnpaywallCog(bot))