Skip to content

Instantly share code, notes, and snippets.

@NotSoSuper
Created November 5, 2016 01:16
Show Gist options
  • Save NotSoSuper/986432374dddafe7a7386084c9ac4b1b to your computer and use it in GitHub Desktop.
Save NotSoSuper/986432374dddafe7a7386084c9ac4b1b to your computer and use it in GitHub Desktop.
react command
@commands.command(pass_context=True)
@commands.cooldown(1, 5)
async def react(self, ctx, *, txt:str):
msg = None
for s in txt.split():
if s.isdigit():
if len(s) > 10:
msg = await self.bot.get_message(ctx.message.channel, s)
txt = txt.replace(s, '')
break
if msg is None:
msg = ctx.message
count = 0
added = []
word_emotes = ['cool', 'ok', 'ng', 'up', 'new', 'ab', 'cl', 'sos', 'id']
for s in txt.lower().split():
if s in word_emotes and s not in added:
await self.bot.add_reaction(msg, self.emojis[s])
added.append(s)
count += 1
txt = txt.replace(s, '')
match = self.emote_regex.match(s)
if match:
em = None
for e in self.bot.get_all_emojis():
if e.id == str(match.group('id')):
em = e
break
if em:
await self.bot.add_reaction(msg, em)
count += 1
txt = re.sub(self.emote_regex, '', txt)
if len(txt) > 20:
txt = txt[:20]
for s in txt.lower():
if s == ' ':
continue
em = None
if s not in added:
if s in self.regional_map:
em = self.regional_map[s]
elif s in self.emojis:
em = self.emojis[s]
else:
for e in self.emojis:
if self.emojis[e] == s:
em = self.emojis[e]
if em is None:
if s == '?':
em = self.emojis['question']
elif s == '!':
em = self.emojis['exclamation']
else:
if s == 'a' or s == 'b' or s == 'x' or s == 'm':
em = self.emojis[s]
elif s == 'c':
em = self.emojis['copyright']
elif s == 'r':
em = self.emojis['registered']
elif s == 'o':
em = self.emojis['o2']
elif s == 'p':
em = self.emojis['parking']
elif s == 'i':
em = self.emojis['information_source']
if em:
await self.bot.add_reaction(msg, em)
added.append(s)
count += 1
await asyncio.sleep(0.21)
if count == 0:
await self.bot.say(':no_entry: Invalid Text.')
else:
x = await self.bot.say(':white_check_mark: Added `{0}` reactions.'.format(count))
await asyncio.sleep(10)
if msg != ctx.message:
await self.bot.delete_messages([x, ctx.message])
else:
await self.bot.delete_message(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment