-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathembeds.py
More file actions
54 lines (44 loc) · 1.75 KB
/
embeds.py
File metadata and controls
54 lines (44 loc) · 1.75 KB
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
from discord import Embed, utils
from discord.ext import commands
from json import loads as jload
from checks import is_moderator
from datetime import datetime
class Embeds(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command(
help = '''
JSON Embed
Post a embed from a JSON string.
You may use a visualiser such as the one here: https://leovoel.github.io/embed-visualizer/
Do ensure that "Enable webhook mode" is turned off, and then copy and paste the code directly after your command.
Remember to tag the channel!
Examples:
!!jsonembed #bot_torture {
"content": "This is a test!",
"embed": {
"fields": [
{"name": "OwO", "value": "Woah cool an embed"}
]
}
}
''',
brief = 'Posts a custom embed',
usage = '<channel> <json>'
)
async def jsonembed(self, ctx, channel, *, json):
try:
input = jload(json)
if 'content' not in input: input['content'] = ""
emb = input['embed']
if 'timestamp' in emb: emb['timestamp'] = str(datetime.strptime(emb['timestamp'], '%Y-%m-%dT%H:%M:%S.%fZ')) #Parse json time format to python time format
emb_obj = Embed.from_dict(emb)
channel = channel.replace('#', '').replace('<', '').replace('>', '')
channel_ids = list(map(lambda c : str(c.id), ctx.guild.channels))
if channel not in channel_ids:
await ctx.send('```Invalid guild ID.```')
return
channel = utils.find(lambda c: str(c.id) == channel, ctx.guild.channels)
await channel.send(content = input['content'], embed = emb_obj)
except:
await ctx.send('```Unable to parse JSON, invalid format.```')