def add(self, ctx, name, url):
"""Allows you to add emotes to the emote list
[p]emotes add pan http://i.imgur.com/FFRjKBW.gifv"""
server = ctx.message.server
name = name.lower()
option = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 '
'(KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36'}
if server.id not in self.servers:
# default off
self.servers[server.id] = dict({"status": False})
if "emotes" not in self.servers[server.id]:
self.servers[server.id]["emotes"] = dict()
dataIO.save_json(self.data_path, self.servers)
if not url.endswith((".gif", ".gifv", ".png")):
await self.bot.say("Links ending in .gif, .png, and .gifv are the only ones accepted."
"Please try again with a valid emote link, thanks.")
return
if name in self.servers[server.id]["emotes"]:
await self.bot.say("This keyword already exists, please use another keyword.")
return
if url.endswith(".gifv"):
url = url.replace(".gifv", ".gif")
try:
await self.bot.say("Downloading {}.".format(name))
async with aiohttp.request("GET", url, headers=option) as r:
emote = await r.read()
with open(self.emote+"{}.{}".format(name, url[-3:]), 'wb') as f:
f.write(emote)
await self.bot.say("Adding {} to the list.".format(name))
self.servers[server.id]["emotes"][name] = "{}.{}".format(name, url[-3:])
self.servers[server.id]["emotes"]
dataIO.save_json(self.data_path, self.servers)
await self.bot.say("{} has been added to the list".format(name))
except Exception as e:
print(e)
await self.bot.say("It seems your url is not valid,"
" please make sure you are not typing names with spaces as they are and then the url."
" If so, do [p]emotes add name_with_spaces url")
评论列表
文章目录