/
weave.py
57 lines (49 loc) · 1.65 KB
/
weave.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
from redbot.core import commands
BaseCog = getattr(commands, "Cog", object)
class Weave(BaseCog):
def __init__(self, bot):
self.bot = bot
@commands.command()
async def weave(self, ctx, e1, e2, width: int = 5, length: int = 3):
"""
Weaves provided emojis in a grid of specified dimensions. Will error if too large.
"""
# <a:name:id>
guilds = await self.bot.fetch_guilds(limit=150).flatten()
all_emoji = dict()
for guild in guilds:
actual_guild = await self.bot.fetch_guild(guild.id)
for e in actual_guild.emojis:
all_emoji[e.id] = e
e1 = await self.check_emoji(ctx, e1, all_emoji)
if e1 is None:
return
e2 = await self.check_emoji(ctx, e2, all_emoji)
if e2 is None:
return
lines = []
pair = [e1, e2]
for _ in range(length):
line = ""
index = 0
for _ in range(width):
line += str(pair[index % 2])
index += 1
pair = pair[::-1]
lines.append(line)
msg = "\n".join(lines)
try:
await ctx.send(msg)
await ctx.message.delete()
except:
await ctx.send("Message too long!")
async def check_emoji(self, ctx, emoji, all_emoji):
if ":" in emoji:
emoji_id = int(emoji[1:-1].split(":")[-1])
if emoji_id not in all_emoji:
await ctx.send("Emoji not from any server I'm in!")
return None
else:
return all_emoji[emoji_id]
else:
return emoji