Exemplo n.º 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,
            ))
Exemplo n.º 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)
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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
Exemplo n.º 5
0
    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"),
        )
Exemplo n.º 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
Exemplo n.º 7
0
def test_sample(case):
    assert _.sample(case) in case
Exemplo n.º 8
0
 def random_item(self) -> ContentItem:
     item = py_.sample(self.manifest)
     return self._content_item_from_manifest_val(item)
Exemplo n.º 9
0
    def sample_or_none(_, possible_values):
        if (len(possible_values) > 0):
            return sample(possible_values)

        return None