Skip to content

Commit ecbe9bc

Browse files
committed
2 parents 6fd3648 + c0d5f74 commit ecbe9bc

File tree

2 files changed

+81
-12
lines changed

2 files changed

+81
-12
lines changed

discord_self_embed/utils/embed.py

Lines changed: 80 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import urllib.parse
22

33
class Embed:
4-
def __init__(self, title, *, description = "", colour = "000000", url = "") -> None:
4+
def __init__(self, title, **kwargs) -> None:
55
"""
66
Initialize the embed object.
77
@@ -12,16 +12,26 @@ def __init__(self, title, *, description = "", colour = "000000", url = "") -> N
1212
url (str): The url of the embed.
1313
"""
1414

15-
if colour.startswith("#"):
16-
colour = colour[1:]
15+
description = kwargs.get("description", "")
16+
colour = kwargs.get("colour", "") or kwargs.get("color", "") or "000000"
17+
url = kwargs.get("url", "")
18+
19+
if isinstance(colour, int):
20+
colour = str(hex(colour)[2:])
21+
22+
elif isinstance(colour, str):
23+
if colour.startswith("#"):
24+
colour = colour[1:]
25+
elif colour.startswith("0x"):
26+
colour = colour[2:]
1727

1828
self.hide_text = "||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||"
19-
self.base_url = "https://embed.rauf.wtf/?"
29+
self.base_url = "https://embed.benny.fun/?"
2030
self.params = {
2131
"title": title,
2232
"description": description,
23-
"color": colour,
24-
"redirect": url
33+
"colour": colour,
34+
"url": url
2535
}
2636

2737
def __str__(self) -> str:
@@ -34,15 +44,63 @@ def __str__(self) -> str:
3444

3545
return self.generate_url(hide_url=True)
3646

37-
def set_author(self, text) -> None:
47+
def set_title(self, title) -> None:
48+
"""
49+
Set the title of the embed.
50+
51+
Parameters:
52+
title (str): The title of the embed.
53+
"""
54+
55+
self.params["title"] = title
56+
57+
def set_description(self, description) -> None:
58+
"""
59+
Set the description of the embed.
60+
61+
Parameters:
62+
description (str): The description of the embed. (Max 340 characters)
63+
"""
64+
65+
self.params["description"] = description
66+
67+
def set_colour(self, colour) -> None:
68+
"""
69+
Set the colour of the embed.
70+
71+
Parameters:
72+
colour (str): The hex colour of the embed.
73+
"""
74+
75+
self.params["colour"] = colour
76+
77+
def set_author(self, name, *, url) -> None:
3878
"""
3979
Set the author of the embed.
4080
4181
Parameters:
42-
text (str): The text of the author.
82+
name (str): The name of the author.
83+
url (str): The url to redirect to when the author is clicked.
84+
"""
85+
86+
self.params["author_name"] = name
87+
88+
if url:
89+
self.params["author_url"] = url
90+
91+
def set_provider(self, name, *, url) -> None:
92+
"""
93+
Set the provider of the embed.
94+
95+
Parameters:
96+
name (str): The name of the provider.
97+
url (str): The url to redirect to when the provider is clicked.
4398
"""
4499

45-
self.params["author"] = text
100+
self.params["provider_name"] = name
101+
102+
if url:
103+
self.params["provider_url"] = url
46104

47105
def set_image(self, url) -> None:
48106
"""
@@ -54,6 +112,16 @@ def set_image(self, url) -> None:
54112

55113
self.params["image"] = url
56114

115+
def set_video(self, url) -> None:
116+
"""
117+
Set the video of the embed.
118+
119+
Parameters:
120+
url (str): The url of the video.
121+
"""
122+
123+
self.params["video"] = url
124+
57125
def generate_url(self, *, hide_url=False) -> str:
58126
"""
59127
Generate the url of the embed.
@@ -69,4 +137,6 @@ def generate_url(self, *, hide_url=False) -> str:
69137
if hide_url:
70138
return self.hide_text + " " + self.base_url + urllib.parse.urlencode(self.params)
71139
else:
72-
return self.base_url + urllib.parse.urlencode(self.params)
140+
return self.base_url + urllib.parse.urlencode(self.params)
141+
142+
set_color = set_colour

examples/embed_cmd.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from click import command
21
import discord_self_embed
32
from discord.ext import commands
43

@@ -15,4 +14,4 @@ async def embed_cmd(ctx):
1514

1615
await ctx.send(embed.generate_url(hide_url=True)) # You can also send the embed converted to a string which will auto hide the url.
1716

18-
bot.run("TOKEN_HERE")
17+
bot.run("TOKEN_HERE")

0 commit comments

Comments
 (0)