Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Zingzy committed Feb 3, 2024
0 parents commit 8294039
Show file tree
Hide file tree
Showing 22 changed files with 1,079 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MONGODB_URI=mongodb://localhost:27017

TOKEN=

APP_URI=http://127.0.0.1:8000
12 changes: 12 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
on: [push, pull_request]

jobs:
python-black:
name: Python Black
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Python Black
uses: cytopia/docker-black@0.8
with:
path: '.'
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
__pycache__
env
.venv
venv
.env
poetry.lock
.idea
.vscode
Binary file added blinkies/blinkiesCafe-0j.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blinkies/blinkiesCafe-3k.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blinkies/blinkiesCafe-6u.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blinkies/blinkiesCafe-8W.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blinkies/blinkiesCafe-DC.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blinkies/blinkiesCafe-Gv.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blinkies/blinkiesCafe-J2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blinkies/blinkiesCafe-ZY.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blinkies/blinkiesCafe-f5.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blinkies/blinkiesCafe-hy.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blinkies/blinkiesCafe-kU.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blinkies/blinkiesCafe-nh.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blinkies/blinkiesCafe-xO.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
146 changes: 146 additions & 0 deletions cogs/shorten.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
from utils import *
from discord import app_commands, ui
from discord.ext import commands


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

class buttonView(discord.ui.View):
def __init__(self, short_code):
super().__init__(timeout=None)

stats_button = discord.ui.Button(label="View Statistics", url=f"https://spoo.me/stats/{short_code}")
tweet_button = discord.ui.Button(url=f"https://twitter.com/intent/tweet?url=https://spoo.me/{short_code}", emoji="<:twitter:1203389152712724581>")
facebook_button = discord.ui.Button(url=f"https://www.facebook.com/sharer/sharer.php?u=https://spoo.me/{short_code}", emoji="<:facebook:1203389150028369970>")
telegram_button = discord.ui.Button(url=f"https://t.me/share/url?url=https://spoo.me/{short_code}", emoji="<:telegram:1203389144756391966>")
whatsapp_button = discord.ui.Button(url=f"https://wa.me/?text=https://spoo.me/{short_code}", emoji="<:whatsapp:1203389130428518460>")
reddit_button = discord.ui.Button(url=f"https://www.reddit.com/submit?url=https://spoo.me/{short_code}", emoji="<:reddit:1203389126100131910>")
snapchat_button = discord.ui.Button(url=f"https://www.snapchat.com/scan?attachmentUrl=https://spoo.me/{short_code}", emoji="<:snapchat:1203389123784609812>")

self.add_item(stats_button)
self.add_item(tweet_button)
self.add_item(facebook_button)
self.add_item(telegram_button)
self.add_item(whatsapp_button)
self.add_item(reddit_button)
self.add_item(snapchat_button)

@app_commands.command(
name="shorten",
description="Shorten a Long URL ✂️",
)
@app_commands.describe(
url="The URL to shorten",
alias="The custom alias for the URL",
max_clicks="The maximum number of clicks for the URL",
password="The password for the URL",
)
@app_commands.guild_only()
@app_commands.checks.cooldown(1, 30.0)
async def shorten(self, interaction: discord.Interaction, url: str, alias:str = None, max_clicks: int=None, password: str=None ):

await interaction.response.defer()

result = shortener.shorten(url, alias=alias, max_clicks=max_clicks, password=password)

embed = discord.Embed(
title="URL Shortened Successfully!",
description="You can also view the statistics page of the shortened url by clicking the button below or you can also use the command </stats:1202895069628203048> to view the statistics.",
color=discord.Color.blurple(),
timestamp=interaction.created_at,
)

embed.set_thumbnail(url=f"https://qr.spoo.me/gradient?text={result}&gradient1=(117,129,86)&gradient2=(103,175,38)")

embed.add_field(name="Shortened URL", value=f"```{result}```", inline=False)
embed.add_field(name="Original URL", value=f"```{url}```", inline=False)

try:
embed.set_footer(
text=f"Shortened by {interaction.user.name}",
icon_url=interaction.user.avatar,
)
except:
embed.set_footer(
text=f"Shortened by {interaction.user.name}",
icon_url=interaction.user.default_avatar,
)

short_code = result.split("/")[-1]

await interaction.followup.send(embed=embed, view=self.buttonView(short_code))


@app_commands.command(
name="emojify",
description="Convert Long Urls to Emojis 😉"
)
@app_commands.describe(
url="The URL to emojify",
emojies="Custom Emoji Sequence you want your short url to be",
max_clicks="The maximum number of clicks for the URL",
password="The password for the URL",
)
@app_commands.guild_only()
@app_commands.checks.cooldown(1, 30.0)
async def emojify(self, interaction, url: str, emojies: str = None, max_clicks: int = None, password: str = None):

await interaction.response.defer()

result = shortener.emojify(url, emoji_alias=emojies, max_clicks=max_clicks, password=password)

embed = discord.Embed(
title="URL Shortened Successfully!",
description="You can also view the statistics page of the shortened url by clicking the button below or you can also use the command </stats:1202895069628203048> to view the statistics.",
color=discord.Color.blurple(),
timestamp=interaction.created_at,
)

embed.set_thumbnail(url=f"https://qr.spoo.me/gradient?text={result}&gradient1=(117,129,86)&gradient2=(103,175,38)")

embed.add_field(name="Shortened URL", value=f"```{result}```", inline=False)
embed.add_field(name="Original URL", value=f"```{url}```", inline=False)

try:
embed.set_footer(
text=f"Shortened by {interaction.user.name}",
icon_url=interaction.user.avatar,
)
except:
embed.set_footer(
text=f"Shortened by {interaction.user.name}",
icon_url=interaction.user.default_avatar,
)

short_code = result.split("/")[-1]

await interaction.followup.send(embed=embed, view=self.buttonView(short_code))


@shorten.error
async def shorten_error(
self, interaction: discord.Interaction, error: app_commands.AppCommandError
):
if isinstance(error, app_commands.CommandOnCooldown):
embed = await generate_error_message(interaction, error)
await interaction.response.send_message(embed=embed, ephemeral=True)
else:
embed = await generate_command_error_embed(interaction, error, "shorten")
await interaction.followup.send(embed=embed, ephemeral=True)

@emojify.error
async def emoji_error(
self, interaction: discord.Interaction, error: app_commands.AppCommandError
):
if isinstance(error, app_commands.CommandOnCooldown):
embed = await generate_error_message(interaction, error)
await interaction.response.send_message(embed=embed, ephemeral=True)
else:
embed = await generate_command_error_embed(interaction, error, "emojify")
await interaction.followup.send(embed=embed, ephemeral=True)

async def setup(bot):
await bot.add_cog(shortenUrl(bot))
print("Loaded shortenUrl")
Loading

0 comments on commit 8294039

Please sign in to comment.