コード例 #1
0
    async def slap_command(self, ctx: Context, who=None):
        """
        Slap your neighbor or get slapped.
        """

        emoji_map = {e.name: e for e in self.bot.get_all_emojis()}

        template = pydash.sample(SLAPPABLE_STRINGS)
        reaction = pydash.sample(SLAPPABLE_REACTIONS)
        if reaction.startswith(':'):
            reaction = pydash.trim(reaction, ':')
            reaction = emoji_map.get(reaction, 'Umm..')
        item = pydash.sample(SLAPPABLE_ITEMS)
        slappee = who
        slapper = getattr(ctx.message.author, 'display_name', None) or \
                  getattr(ctx.message.author, 'username', 'Zola')

        # If the slappee wasn't specified, the slapper gets slapped
        if not slappee:
            slappee = slapper
            slapper = 'Zola'

        await self.bot.send_message(
            ctx.message.channel,
            template.format(
                slapper=slapper,
                slappee=slappee,
                item=item,
                reaction=reaction,
            ))
コード例 #2
0
def test_sample_list(case):
    collection, n = case
    sample_n = _.sample(*case)

    assert isinstance(sample_n, list)
    assert len(sample_n) == min(n, len(collection))
    assert set(sample_n).issubset(collection)
コード例 #3
0
ファイル: fun.py プロジェクト: jacobbridges/zola-discord.py
async def command_slap(message, client, *args, **kwargs):
    """
    Return a random slap text.
    """
    if message.content.startswith('!slap'):
        logger.info('Running !slap command')
        logger.debug('{}, {}'.format(message.content,
                                     message.author.display_name))

        template = pydash.sample(SLAPPABLE_STRINGS)
        reaction = pydash.sample(SLAPPABLE_REACTIONS)
        if reaction.startswith(':'):
            reaction = pydash.trim(reaction, ':')
            reaction = client.zen['emoji_map'].get(reaction, 'Umm..')
        item = pydash.sample(SLAPPABLE_ITEMS)
        slapper = getattr(message.author, 'display_name', None) or \
                  getattr(message.author, 'username', 'null')

        # Get the slappee
        slappee = pydash.chain(message.content)\
            .replace('!slap', '')\
            .trim()\
            .value()

        # If the slappee wasn't specified, the slapper gets slapped
        if not slappee:
            slappee = slapper
            slapper = 'Zola'

        await client.send_message(
            message.channel,
            template.format(
                slapper=slapper,
                slappee=slappee,
                item=item,
                reaction=reaction,
            ))
        return True
    return False
コード例 #4
0
ファイル: fun.py プロジェクト: jacobbridges/zola-discord.py
async def command_party(message, client, *args, **kwargs):
    """
    Return a random party harder gif.
    """
    if message.content == '!party':
        logger.info('Run command !party')

        # Create an embed for the gif response
        gif_embed = discord.Embed()
        gif_embed.type = 'rich'
        gif_embed.set_image(url=pydash.sample(PARTY_HARDER_GIFS))

        await client.send_message(message.channel, embed=gif_embed)
        return True
    return False
コード例 #5
0
ファイル: handlers.py プロジェクト: turtlesoupy/nohomers
    def _content_item_from_manifest_val(self, item: Dict[str,
                                                         Any]) -> ContentItem:
        transition = py_.sample(item["transitions"])
        next_item_key = transition["dest_name"]
        next_item_url = f"{self.manifest_dir_url}/images/{next_item_key}"
        transition_url = f"{self.manifest_dir_url}/videos/{transition['video_name']}"

        return ContentItem(
            url=f"{self.manifest_dir_url}/images/{item['name']}",
            key=item["name"],
            permalink=
            f"/p/{self.permalink_key}/{urllib.parse.quote(item['permalink'])}",
            next_item_key=next_item_key,
            next_item_url=next_item_url,
            transition_url=transition_url,
            opensea_item_url=item.get("opensea_url"),
        )
コード例 #6
0
def chooseSong(song_data):
    """
    chooses a song to tweet and updates recently choosen songs
    """
    recent = song_data['recentSongIds']
    songs = song_data['songs']

    # filter out recently choosen songs and randomly choose a song
    filtered_song_ids = pydash.filter_(songs.keys(), lambda x: x not in recent)
    song_id = pydash.sample(filtered_song_ids)

    # get chosen song and increment play count
    song = songs[song_id]
    song['playCount'] += 1

    # pop least recently choosen song and push new one
    if len(recent) == 7:
        pydash.shift(recent)
    pydash.push(recent, song_id)

    return song
コード例 #7
0
def test_sample(case):
    assert _.sample(case) in case
コード例 #8
0
ファイル: handlers.py プロジェクト: turtlesoupy/nohomers
 def random_item(self) -> ContentItem:
     item = py_.sample(self.manifest)
     return self._content_item_from_manifest_val(item)
コード例 #9
0
ファイル: sudoku.py プロジェクト: kroneman/sudoku
    def sample_or_none(_, possible_values):
        if (len(possible_values) > 0):
            return sample(possible_values)

        return None