コード例 #1
0
 def MultiEmojies(self, message: discord.Message, emojies: list):
     for emoji in emojies:
         try:
             awaiter(message.add_reaction(EMOJI_UNICODE[":%s:" % emoji]))
         except KeyError:
             awaiter(
                 message.add_reaction(EMOJI_ALIAS_UNICODE[":%s:" % emoji]))
コード例 #2
0
ファイル: reactor.py プロジェクト: hrmorley34/wowbot
 async def add_reactions(self, message: discord.Message):
     tasks = []
     for b, em in self.reactionmap.keys():
         if b:
             emoji = self.bot.get_emoji(em)
             tasks.append(asyncio.create_task(message.add_reaction(emoji)))
         else:
             tasks.append(asyncio.create_task(message.add_reaction(em)))
     await asyncio.gather(*tasks)
コード例 #3
0
async def get_reaction(msg: discord.Message,
                       user: discord.abc.Snowflake,
                       reactions: Dict[Union[discord.Emoji,
                                             discord.PartialEmoji, str], T],
                       *,
                       timeout: Optional[float] = None,
                       unreact: bool = True) -> Optional[T]:
    assert discord_client.client.user is not None
    reacts = {emoji_key(key): value for key, value in reactions.items()}
    with plugins.reactions.ReactionMonitor(
            channel_id=msg.channel.id,
            message_id=msg.id,
            author_id=user.id,
            event="add",
            filter=lambda _, p: emoji_key(p.emoji) in reacts,
            timeout_each=timeout) as mon:
        try:
            await asyncio.gather(*(msg.add_reaction(key) for key in reactions))
        except (discord.NotFound, discord.Forbidden):
            pass
        try:
            _, payload = await mon
        except asyncio.TimeoutError:
            return None
    if unreact:
        try:
            await asyncio.gather(
                *(msg.remove_reaction(key, discord_client.client.user)
                  for key in reactions
                  if emoji_key(key) != emoji_key(payload.emoji)))
        except (discord.NotFound, discord.Forbidden):
            pass
    return reacts.get(emoji_key(payload.emoji))
コード例 #4
0
ファイル: misc.py プロジェクト: Phxntxm/Tanya
 def check(m: discord.Message) -> bool:
     # Ignore if not in channel we want
     if m.channel != game.chat:
         return False
     # Ignore if not player of game (admins, bots)
     if m.author not in [p.member for p in game.players]:
         return False
     # Ignore if not the right type of message
     if not m.content.startswith(">>nominate "):
         return False
     # Try to get the player
     try:
         content = m.content.split(">>nominate ")[1]
         player = get_mafia_player(game, content)
         nominator = discord.utils.get(game.players, member=m.author)
     except commands.MemberNotFound:
         return False
     else:
         # Don't let them nominate themselves
         if nominator == player:
             return False
         # Check if dead
         if player.dead:
             return False
         # Set their nomination
         nominations[nominator] = player
         game.ctx.create_task(m.add_reaction("\N{THUMBS UP SIGN}"))
         return False
コード例 #5
0
ファイル: message.py プロジェクト: bijij/Ditto
async def bulk_add_reactions(message: discord.Message,
                             *reactions: Emoji) -> None:
    coros = [
        asyncio.ensure_future(message.add_reaction(reaction))
        for reaction in reactions
    ]
    await asyncio.wait(coros)
コード例 #6
0
ファイル: fun.py プロジェクト: BeatButton/Akane
 def check(message: discord.Message) -> bool:
     if (message.channel == ctx.channel and not message.author.bot
             and message.content.lower() == randomized_words
             and message.author not in winners):
         winners[message.author] = time.time() - start
         is_ended.set()
         ctx.bot.loop.create_task(
             message.add_reaction(ctx.bot.emoji[True]))
コード例 #7
0
async def party(botto: MottoBotto, message: Message):
    log.info(f"Party from: {message.author}")
    tasks = []
    for _ in range(5):
        tasks.append(
            message.add_reaction(
                random.choice(botto.config["reactions"]["party"])))
    await asyncio.wait(tasks)
コード例 #8
0
async def get_input(
        msg: discord.Message,
        user: discord.abc.Snowflake,
        reactions: Dict[Union[discord.Emoji, discord.PartialEmoji, str], T],
        *,
        timeout: Optional[float] = None,
        unreact: bool = True) -> Optional[Union[T, discord.Message]]:
    assert discord_client.client.user is not None
    reacts = {emoji_key(key): value for key, value in reactions.items()}
    with plugins.reactions.ReactionMonitor(
            channel_id=msg.channel.id,
            message_id=msg.id,
            author_id=user.id,
            event="add",
            filter=lambda _, p: emoji_key(p.emoji) in reacts,
            timeout_each=timeout) as mon:
        try:
            await asyncio.gather(*(msg.add_reaction(key) for key in reactions))
        except (discord.NotFound, discord.Forbidden):
            pass
        msg_task = asyncio.create_task(
            discord_client.client.wait_for("message",
                                           check=lambda m: m.channel == msg.
                                           channel and m.author.id == user.id))
        reaction_task = asyncio.ensure_future(mon)
        try:
            done, pending = await asyncio.wait(
                (msg_task, reaction_task),
                timeout=timeout,
                return_when=asyncio.FIRST_COMPLETED)
        except asyncio.TimeoutError:
            return None
    if msg_task in done:
        reaction_task.cancel()
        if unreact:
            try:
                await asyncio.gather(
                    *(msg.remove_reaction(key, discord_client.client.user)
                      for key in reactions))
            except (discord.NotFound, discord.Forbidden):
                pass
        return msg_task.result()
    elif reaction_task in done:
        msg_task.cancel()
        _, payload = reaction_task.result()
        if unreact:
            try:
                await asyncio.gather(
                    *(msg.remove_reaction(key, discord_client.client.user)
                      for key in reactions
                      if emoji_key(key) != emoji_key(payload.emoji)))
            except (discord.NotFound, discord.Forbidden):
                pass
        return reacts.get(emoji_key(payload.emoji))
    else:
        return None
コード例 #9
0
ファイル: cookiehunt.py プロジェクト: CashOutCookie/CookieBot
 def predicate(self, message: discord.Message) -> bool:
     if message.author == self.turn.user and message.channel == self.turn.user.dm_channel:
         if message.content.lower() == "surrender":
             self.surrender = True
             return True
         self.match = re.match("([A-E]|[a-e]) ?((5)|[1-4])",
                               message.content.strip())
         if not self.match:
             self.bot.loop.create_task(message.add_reaction(CANCEL))
         return bool(self.match)
コード例 #10
0
 def predicate(self, message: discord.Message) -> bool:
     """Predicate checking the message typed for each turn."""
     if message.author == self.turn.user and message.channel == self.turn.user.dm_channel:
         if message.content.lower() == "surrender":
             self.surrender = True
             return True
         self.match = re.fullmatch("([A-J]|[a-j]) ?((10)|[1-9])", message.content.strip())
         if not self.match:
             self.bot.loop.create_task(message.add_reaction(CROSS_EMOJI))
         return bool(self.match)
コード例 #11
0
async def wait_for_multiple_reactions(ctx: commands.Context,
                                      message: discord.Message,
                                      emojis: List[str]) -> str:
    await asyncio.gather(*[message.add_reaction(emoji) for emoji in emojis])

    def _check(reaction, user):
        return (reaction.message.id == message.id and user == ctx.author
                and str(reaction) in emojis)

    reaction, _ = await ctx.bot.wait_for("reaction_add", check=_check)
    return str(reaction)
コード例 #12
0
ファイル: fun.py プロジェクト: makusu2/makubot
 async def thisify(self, ctx, message: discord.Message):
     this_emojis = [
         emoji for emoji in self.bot.emojis
         if emoji.name.startswith("this") and len(emoji.name) < 8
     ]
     all_emoji_futures = [
         message.add_reaction(this_emoji) for this_emoji in this_emojis
     ]
     all_emoji_futures = asyncio.gather(*all_emoji_futures)
     try:
         await all_emoji_futures
     except discord.errors.Forbidden:
         return
コード例 #13
0
ファイル: util.py プロジェクト: dyc3/discord-pokemon-battles
async def prompt_message(bot: commands.Bot, user: discord.User,
                         msg: discord.Message, emojis: list[str]):
    """Works very similar to prompt_menu except it takes in the message and a list of reactions instead of the specific menu_items."""

    for r in emojis:
        bot.loop.create_task(msg.add_reaction(r))

    def check(payload):
        log.debug(f"checking payload {payload}")
        return payload.message_id == msg.id and payload.user_id == user.id and str(
            payload.emoji) in emojis

    try:
        log.debug("waiting for user's reaction")
        # HACK: reaction_add doesn't work in DMs
        payload = await bot.wait_for("raw_reaction_add", check=check)
    except asyncio.TimeoutError as e:
        log.error("timed out")
        raise e

    reactionId = emojis.index(str(payload.emoji))

    return reactionId
コード例 #14
0
ファイル: amongus.py プロジェクト: konafx/natalia
    async def init_reaction_as_button(self, message: discord.Message):
        task_add_reactions = [message.add_reaction(reaction) for reaction in REACTIONS.values()]

        await asyncio.gather(*task_add_reactions)