Convert files to the new discord.File format
This commit is contained in:
parent
74d22f2d8d
commit
79994c6cf4
|
@ -263,7 +263,8 @@ class Core:
|
||||||
|
|
||||||
image = await utils.download_image(filename)
|
image = await utils.download_image(filename)
|
||||||
filename = re.search('.*\/i\/(.*)', filename).group(1)
|
filename = re.search('.*\/i\/(.*)', filename).group(1)
|
||||||
await ctx.send(file=image, filename=filename)
|
f = discord.File(image, filename=filename)
|
||||||
|
await ctx.send(file=f)
|
||||||
|
|
||||||
|
|
||||||
@commands.command(aliases=['dog', 'rd'])
|
@commands.command(aliases=['dog', 'rd'])
|
||||||
|
@ -282,7 +283,8 @@ class Core:
|
||||||
return
|
return
|
||||||
|
|
||||||
image = await utils.download_image("http://random.dog/{}".format(filename))
|
image = await utils.download_image("http://random.dog/{}".format(filename))
|
||||||
await ctx.send(file=image, filename=filename)
|
f = discord.File(image, filename=filename)
|
||||||
|
await ctx.send(file=f)
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@utils.custom_perms(send_messages=True)
|
@utils.custom_perms(send_messages=True)
|
||||||
|
@ -294,7 +296,7 @@ class Core:
|
||||||
# Find a random image based on how many we currently have
|
# Find a random image based on how many we currently have
|
||||||
f = random.SystemRandom().choice(glob.glob('images/snek*'))
|
f = random.SystemRandom().choice(glob.glob('images/snek*'))
|
||||||
with open(f, 'rb') as f:
|
with open(f, 'rb') as f:
|
||||||
await ctx.send(file=f)
|
await ctx.send(file=discord.File(f))
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@utils.custom_perms(send_messages=True)
|
@utils.custom_perms(send_messages=True)
|
||||||
|
|
|
@ -137,16 +137,17 @@ class Interaction:
|
||||||
|
|
||||||
url = member.avatar_url
|
url = member.avatar_url
|
||||||
if ctx.message.guild.me.permissions_in(ctx.message.channel).attach_files:
|
if ctx.message.guild.me.permissions_in(ctx.message.channel).attach_files:
|
||||||
file = await utils.download_image(url)
|
filedata = await utils.download_image(url)
|
||||||
if file is None:
|
if filedata is None:
|
||||||
await ctx.send(url)
|
await ctx.send(url)
|
||||||
else:
|
else:
|
||||||
if '.gif' in url:
|
if '.gif' in url:
|
||||||
filename = 'avatar.gif'
|
filename = 'avatar.gif'
|
||||||
else:
|
else:
|
||||||
filename = 'avatar.jpg'
|
filename = 'avatar.jpg'
|
||||||
file = utils.convert_to_jpeg(file)
|
filedata = utils.convert_to_jpeg(filedata)
|
||||||
await ctx.send(file=file, filename=filename)
|
f = discord.File(filedata, filename=filename)
|
||||||
|
await ctx.send(file=f)
|
||||||
else:
|
else:
|
||||||
await ctx.send(url)
|
await ctx.send(url)
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ class Overwatch:
|
||||||
output_data.append((k.title().replace("_", " "), r))
|
output_data.append((k.title().replace("_", " "), r))
|
||||||
try:
|
try:
|
||||||
banner = await utils.create_banner(user, "Overwatch", output_data)
|
banner = await utils.create_banner(user, "Overwatch", output_data)
|
||||||
await ctx.send(file=banner)
|
await ctx.send(file=discord.File(banner))
|
||||||
except (FileNotFoundError, discord.Forbidden):
|
except (FileNotFoundError, discord.Forbidden):
|
||||||
fmt = "\n".join("{}: {}".format(k, r) for k, r in output_data)
|
fmt = "\n".join("{}: {}".format(k, r) for k, r in output_data)
|
||||||
await ctx.send("Overwatch stats for {}: ```py\n{}```".format(user.name, fmt))
|
await ctx.send("Overwatch stats for {}: ```py\n{}```".format(user.name, fmt))
|
||||||
|
|
|
@ -80,7 +80,7 @@ class Stats:
|
||||||
("Your Usage", member_usage),
|
("Your Usage", member_usage),
|
||||||
("This Server's Usage", server_usage)]
|
("This Server's Usage", server_usage)]
|
||||||
banner = await utils.create_banner(ctx.message.author, "Command Stats", data)
|
banner = await utils.create_banner(ctx.message.author, "Command Stats", data)
|
||||||
await ctx.send(file=banner)
|
await ctx.send(file=discord.File(banner))
|
||||||
except (FileNotFoundError, discord.Forbidden):
|
except (FileNotFoundError, discord.Forbidden):
|
||||||
fmt = "The command {} has been used a total of {} times\n" \
|
fmt = "The command {} has been used a total of {} times\n" \
|
||||||
"{} times on this server\n" \
|
"{} times on this server\n" \
|
||||||
|
@ -117,7 +117,7 @@ class Stats:
|
||||||
try:
|
try:
|
||||||
top_5 = [(data[0], data[1]) for data in sorted_stats[:5]]
|
top_5 = [(data[0], data[1]) for data in sorted_stats[:5]]
|
||||||
banner = await utils.create_banner(ctx.message.author, "Your command usage", top_5)
|
banner = await utils.create_banner(ctx.message.author, "Your command usage", top_5)
|
||||||
await ctx.send(file=banner)
|
await ctx.send(file=discord.File(banner))
|
||||||
except (FileNotFoundError, discord.Forbidden):
|
except (FileNotFoundError, discord.Forbidden):
|
||||||
top_5 = "\n".join("{}: {}".format(data[0], data[1]) for data in sorted_stats[:5])
|
top_5 = "\n".join("{}: {}".format(data[0], data[1]) for data in sorted_stats[:5])
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
|
@ -132,7 +132,7 @@ class Stats:
|
||||||
try:
|
try:
|
||||||
top_5 = [(data[0], data[1]) for data in sorted_stats[:5]]
|
top_5 = [(data[0], data[1]) for data in sorted_stats[:5]]
|
||||||
banner = await utils.create_banner(ctx.message.author, "Server command usage", top_5)
|
banner = await utils.create_banner(ctx.message.author, "Server command usage", top_5)
|
||||||
await ctx.send(file=banner)
|
await ctx.send(file=discord.File(banner))
|
||||||
except (FileNotFoundError, discord.Forbidden):
|
except (FileNotFoundError, discord.Forbidden):
|
||||||
top_5 = "\n".join("{}: {}".format(data[0], data[1]) for data in sorted_stats[:5])
|
top_5 = "\n".join("{}: {}".format(data[0], data[1]) for data in sorted_stats[:5])
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
|
@ -201,7 +201,7 @@ class Stats:
|
||||||
output = [("{0.display_name}".format(ctx.message.guild.get_member(m_id)), amt)
|
output = [("{0.display_name}".format(ctx.message.guild.get_member(m_id)), amt)
|
||||||
for m_id, amt in sorted_booped_members]
|
for m_id, amt in sorted_booped_members]
|
||||||
banner = await utils.create_banner(ctx.message.author, "Your booped victims", output)
|
banner = await utils.create_banner(ctx.message.author, "Your booped victims", output)
|
||||||
await ctx.send(file=banner)
|
await ctx.send(file=discord.File(banner))
|
||||||
except (FileNotFoundError, discord.Forbidden):
|
except (FileNotFoundError, discord.Forbidden):
|
||||||
output = "\n".join(
|
output = "\n".join(
|
||||||
"{0.display_name}: {1} times".format(ctx.message.guild.get_member(m_id), amt) for
|
"{0.display_name}: {1} times".format(ctx.message.guild.get_member(m_id), amt) for
|
||||||
|
@ -285,7 +285,7 @@ class Stats:
|
||||||
fmt = [('Record', record), ('Server Rank', '{}/{}'.format(server_rank, len(server_members))),
|
fmt = [('Record', record), ('Server Rank', '{}/{}'.format(server_rank, len(server_members))),
|
||||||
('Overall Rank', '{}/{}'.format(total_rank, len(all_members))), ('Rating', rating)]
|
('Overall Rank', '{}/{}'.format(total_rank, len(all_members))), ('Rating', rating)]
|
||||||
banner = await utils.create_banner(member, title, fmt)
|
banner = await utils.create_banner(member, title, fmt)
|
||||||
await ctx.send(file=banner)
|
await ctx.send(file=discord.File(banner))
|
||||||
except (FileNotFoundError, discord.Forbidden):
|
except (FileNotFoundError, discord.Forbidden):
|
||||||
fmt = 'Stats for {}:\n\tRecord: {}\n\tServer Rank: {}/{}\n\tOverall Rank: {}/{}\n\tRating: {}'
|
fmt = 'Stats for {}:\n\tRecord: {}\n\tServer Rank: {}/{}\n\tOverall Rank: {}/{}\n\tRating: {}'
|
||||||
fmt = fmt.format(member.display_name, record, server_rank, len(server_members), total_rank,
|
fmt = fmt.format(member.display_name, record, server_rank, len(server_members), total_rank,
|
||||||
|
|
Loading…
Reference in a new issue