Example #1
0
 def test_duplicates(self):
     ids = get_tweet_ids(
         'https://twitter.com/TVTOKYO_PR/status/1169955731430227968\n'
         'https://twitter.com/TVTOKYO_PR/status/1169955731430227968')
     self.assertIsNotNone(ids)
     self.assertEqual(len(ids), 1)
     self.assertIn('1169955731430227968', ids)
Example #2
0
    async def quoted(self, ctx, twitter_url: str):
        tweet_id = get_tweet_ids(twitter_url)[0]

        if not tweet_id:
            await ctx.channel.send('Not a valid Twitter URL!')

        tweet = None

        try:
            tweet = get_tweet(tweet_id)
        except TweepError:
            await ctx.channel.send(f'Tweet ID {tweet_id} is not valid!')

        if is_quote(tweet):
            quoted_tweet = get_tweet(tweet.quoted_status.id)

            for embed in get_tweet_embeds(quoted_tweet):
                await ctx.channel.send(embed=embed)

            video = extract_video_url(tweet.quoted_status)

            if video:
                await ctx.channel.send(video)

            logger.info(
                f'{get_tweet_url(tweet)} sent to #{ctx.channel.name} in {ctx.guild.name}'
            )
        else:
            await ctx.channel.send(
                f'This tweet does not quote any other tweet!')
Example #3
0
 def test_multiple_urls(self):
     ids = get_tweet_ids(
         'https://twitter.com/TVTOKYO_PR/status/1169955731430227968\n'
         'https://twitter.com/box_komiyaarisa/status/1169970460521484288')
     self.assertIsNotNone(ids)
     self.assertEqual(len(ids), 2)
     self.assertIn('1169955731430227968', ids)
     self.assertIn('1169970460521484288', ids)
Example #4
0
    async def on_message(self, message):
        if message.content.startswith(self.bot.command_prefix):
            return

        cleaned_message = clean_message(message.content)

        for tweet_id in get_tweet_ids(cleaned_message):
            tweet = get_tweet(int(tweet_id))
            video_url = extract_video_url(tweet)

            if video_url:
                await message.channel.send(video_url)

        await self.bot.process_commands(message)
Example #5
0
    async def embed(self, ctx, twitter_url: str):
        tweet_ids = get_tweet_ids(twitter_url)

        if len(tweet_ids) == 0:
            await ctx.channel.send("Message does not contain a Twitter link!")
            return

        tweet = get_tweet(tweet_ids[0])

        for embed in get_tweet_embeds(tweet):
            await ctx.channel.send(embed=embed)

        logger.info(
            f'{get_tweet_url(tweet)} sent to #{ctx.channel.name} in {ctx.guild.name}'
        )
Example #6
0
    async def video(self, ctx, twitter_url: str):
        tweet_ids = get_tweet_ids(twitter_url)

        if len(tweet_ids) == 0:
            await ctx.channel.send("Message does not contain a Twitter link!")
            return

        tweet = get_tweet(tweet_ids[0])
        video = extract_video_url(tweet)

        if video is None:
            await ctx.channel.send("Tweet does not have a video!")
            return

        logger.info(
            f'{get_tweet_url(tweet)} sent to #{ctx.channel.name} in {ctx.guild.name}'
        )
        await ctx.channel.send(video)
Example #7
0
    async def photos(self, ctx, twitter_url: str):
        tweet_ids = get_tweet_ids(twitter_url)

        if len(tweet_ids) == 0:
            await ctx.channel.send("Message does not contain a Twitter link!")
            return

        tweet = get_tweet(tweet_ids[0])
        photos = extract_photo_urls(tweet)

        if not photos:
            await ctx.channel.send("Tweet does not have any photos!")
            return

        logger.info(
            f'{get_tweet_url(tweet)} sent to #{ctx.channel.name} in {ctx.guild.name}'
        )

        for photo in photos[1:]:
            await ctx.channel.send(photo)
Example #8
0
    async def queue(self, ctx, url: str):
        tweet_id = get_tweet_ids(url)[0]
        tweet = get_tweet(tweet_id)

        self.tweet_queue.put(get_mock_tweet(tweet.user.id, tweet_id))
        await ctx.channel.send(f'Queued tweet {tweet_id}!')
Example #9
0
 def test_single_url_with_question_mark(self):
     ids = get_tweet_ids(
         'https://twitter.com/TVTOKYO_PR/status/1169955731430227968?s=20')
     self.assertIsNotNone(ids)
     self.assertEqual(len(ids), 1)
     self.assertIn('1169955731430227968', ids)