-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathembeds.py
124 lines (105 loc) · 3.75 KB
/
embeds.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
'''
Author: k1rk and charge
Copyright: Zeus Selfbot (c) inc.
'''
# -- standard libraries -- #
import datetime
# -- 3rd party libararies -- #
import discord
class Embeds:
def __init__(self, config):
'''custom embeds class that each cog get's accsess to'''
self.config = config.embeds
self.url = self.config.link
self.author = self.config.author
self.author_url = self.config.author_url
self.footer = self.config.footer
self.footer_url = self.config.footer_url
self.image_url = self.config.image_url
self.color = self.config.color
self.title = self.config.title
self.description = self.config.description
self.thumbnail = self.config.thumbnail
def new_default_embed(self, title='', description='',
timestamp='', fields=()):
'''function to create an embed using the defualt config'''
# -- create a new embeds instance -- #s
embed = discord.Embed(
title=(title if title != '' else self.title),
description=(description if description != '' else self.description),
timestamp=(timestamp if timestamp != '' else datetime.datetime.now()),
color=self.color,
url=self.url
)
# -- set author -- #
if self.author_url is not None:
embed.set_author(name=self.author, icon_url=self.author_url)
else:
embed.set_author(name=self.author)
# -- set footer -- #
if self.footer_url is not None:
embed.set_footer(text=self.footer, icon_url=self.footer_url)
else:
embed.set_footer(text=self.footer)
# -- set image -- #
if self.image_url is not None:
embed.set_image(url=self.image_url)
# -- set thumbnail -- #
if self.thumbnail is not None:
embed.set_thumbnail(url=self.thumbnail)
# -- add fields -- #
if len(fields) > 0:
for f in fields:
embed.add_field(name=f[0], value=f[1], inline=f[2])
return embed
def new_raw_embed(self, title='', description='', timestamp='', fields=(),
thumbnail=None, footer=None, footer_url=None,
author=None, author_url=None, url=None, image_url=None):
'''function to create an embed from scratch'''
# -- create a new embed instance and check if the values are not nil -- #
embed = discord.Embed(
title=(title if title != '' else self.title),
description=(description if description != '' else self.description),
timestamp=(timestamp if timestamp != '' else datetime.datetime.now()),
color=self.color,
url=(url if url is not None else self.url)
)
# -- set thumbnail -- #
if thumbnail is None:
if self.thumbnail is not None:
embed.set_thumbnail(url=self.thumbnail)
else:
embed.set_thumbnail(url=thumbnail)
# -- set image -- #
if image_url is None:
if self.image_url is not None:
embed.set_image(url=self.image_url)
else:
embed.set_image(url=image_url)
# -- set footer -- #
if footer is None and footer_url is None:
if self.footer_url is None:
embed.set_footer(text=self.footer)
else:
embed.set_footer(text=self.footer, icon_url=self.footer_url)
else:
if footer_url is None:
embed.set_footer(text=footer)
else:
embed.set_footer(text=footer, icon_url=footer_url)
# -- set author -- #
if author is None and author_url is None:
if self.author_url is None:
embed.set_author(name=self.author)
else:
embed.set_author(name=self.author, icon_url=self.author_url)
else:
if author_url is None:
embed.set_author(name=author)
else:
embed.set_author(name=author, icon_url=self.author_url)
# -- add the fields -- #
if len(fields) > 0:
for f in fields:
embed.add_field(name=f[0], value=f[1], inline=f[2])
return embed