async def info(self, ctx, *, x=None): """Responds with current version of the bot.""" if x and 'fccchk' in x.lower(): emoji = '👺' notice = f'??? {random.randint(1, 9)}.{random.randint(1, 9)}.{random.randint(1, 9)}' footer = '© ???-??? ???' psi = 2**18 omega = psi * psi server_count = random.randint(0, psi) user_count = server_count * random.randint(0, psi) runtime = human_amount_of_time(random.randint(0, omega)) instance_owner = '???' else: emoji = 'ℹ️' notice = f'Somsiad {__version__}' footer = __copyright__ server_count = self.bot.server_count user_count = self.bot.user_count runtime = human_amount_of_time(dt.datetime.now() - self.bot.run_datetime) application_info = await self.bot.application_info() instance_owner = application_info.owner.mention embed = self.bot.generate_embed(emoji, notice, url=self.bot.WEBSITE_URL) embed.add_field(name='Liczba serwerów', value=f'{server_count:n}') embed.add_field(name='Liczba użytkowników', value=f'{user_count:n}') embed.add_field(name='Czas pracy', value=runtime) embed.add_field(name='Właściciel instancji', value=instance_owner) embed.set_footer(text=footer) await self.bot.send(ctx, embed=embed)
async def info(self, ctx, *, x: str = ''): """Responds with current version of the bot.""" if 'fccchk' in x.lower(): emoji = '👺' notice = f'??? 6.6.6' footer = '© 1963 👺' server_count = 193 user_count = 7_802_385_004 + int( (dt.datetime.now() - dt.datetime(2020, 1, 1)).total_seconds() * 2.5) mau_count = 1_323_519_222 + int( (dt.datetime.now() - dt.datetime(2020, 1, 1)).total_seconds()) sau_count = 194 shard_count = 8 runtime = human_amount_of_time(dt.datetime.now() - dt.datetime(1963, 11, 22)) instance_owner = '👺' invite_url = 'https:///////////////////////////////' else: emoji = 'ℹ️' notice = f'Somsiad {__version__}' footer = __copyright__ server_count = self.bot.server_count user_count = self.bot.user_count with data.session() as session: thirty_days_ago = dt.datetime.now() - dt.timedelta(30) mau_count = (session.query( functions.count(Invocation.user_id.distinct())).filter( Invocation.created_at > thirty_days_ago).scalar()) shard_count = self.bot.shard_count or 1 runtime = ('nieznany' if self.bot.ready_datetime is None else human_amount_of_time(dt.datetime.now() - self.bot.ready_datetime)) application_info = await self.bot.application_info() instance_owner = application_info.owner.mention invite_url = self.bot.invite_url() embed = self.bot.generate_embed(emoji, notice, url=self.bot.WEBSITE_URL) embed.add_field(name='Liczba serwerów', value=f'{server_count:n}') embed.add_field(name='Liczba użytkowników', value=f'{user_count:n}') embed.add_field(name='Liczba aktywnych użytkowników miesięcznie', value=f'{mau_count:n}') embed.add_field(name='Liczba shardów', value=f'{shard_count:n}') embed.add_field(name='Czas pracy', value=runtime) embed.add_field(name='Właściciel instancji', value=instance_owner) embed.add_field(name='Link zaproszeniowy bota', value=invite_url, inline=False) embed.set_footer(text=footer) await self.bot.send(ctx, embed=embed)
def generate_movie_embed(self, result: dict) -> discord.Embed: release_date = dt.date.fromisoformat(result['release_date']) if result['release_date'] else None embed = self.bot.generate_embed( '🎞', f'{result["title"]} ({result["release_date"][:4]})', result.get('tagline'), url=f'https://www.themoviedb.org/movie/{result["id"]}' ) if result.get('original_title') != result['title']: embed.add_field(name='Tytuł oryginalny', value=result['original_title'], inline=False) embed.add_field(name='Średnia ocen', value=f'{result["vote_average"]:n} / 10') embed.add_field(name='Głosów', value=f'{result["vote_count"]:n}') if release_date is not None: embed.add_field(name='Data premiery', value=release_date.strftime('%-d %B %Y')) if result['runtime']: embed.add_field(name='Długość', value=human_amount_of_time(result['runtime'] * 60)) if result['budget']: embed.add_field(name='Budżet', value=f'${result["budget"]:n}') if result['revenue']: embed.add_field(name='Przychody', value=f'${result["revenue"]:n}') if result['genres']: genre_parts = ( f'[{genre["name"]}](https://www.themoviedb.org/genre/{genre["id"]})' for genre in result['genres'] ) embed.add_field(name='Gatunki' if len(result['genres']) > 1 else 'Gatunek', value=' / '.join((genre_parts))) if result['overview']: embed.add_field(name='Opis', value=text_snippet(result['overview'], 500), inline=False) if result.get('poster_path'): embed.set_thumbnail(url=f'https://image.tmdb.org/t/p/w342{result["poster_path"]}') if result.get('backdrop_path'): embed.set_image(url=f'https://image.tmdb.org/t/p/w780{result["backdrop_path"]}') return embed
async def spotify(self, ctx, member: discord.Member = None): member = member or ctx.author spotify_activity = cast( discord.Spotify, discord.utils.find( lambda activity: isinstance(activity, discord.Spotify), member.activities), ) if spotify_activity is None: address = 'nie słuchasz' if member == ctx.author else f'{member.display_name} nie słucha' embed = self.bot.generate_embed( '⏹', f'W tym momencie {address} niczego na Spotify') else: embed = self.bot.generate_embed( '▶️', spotify_activity.title, url= f'https://open.spotify.com/go?uri=spotify:track:{spotify_activity.track_id}', ) embed.set_thumbnail(url=spotify_activity.album_cover_url) embed.add_field(name='W wykonaniu', value=', '.join(spotify_activity.artists)) embed.add_field(name='Z albumu', value=spotify_activity.album) embed.add_field(name='Długość', value=human_amount_of_time( spotify_activity.duration.total_seconds())) # search for the song on YouTube youtube_search_query = f'{spotify_activity.title} {" ".join(spotify_activity.artists)}' try: youtube_search_result = await self.bot.youtube_client.search( youtube_search_query) except: capture_exception() else: # add a link to a YouTube video if a match was found if (youtube_search_result is not None and SequenceMatcher( None, youtube_search_query, youtube_search_result.title).ratio() > 0.25): embed.add_field(name='Posłuchaj na YouTube', value=youtube_search_result.url, inline=False) embed.set_image(url=youtube_search_result.thumbnail_url) embed.set_footer(text=self.FOOTER_TEXT, icon_url=self.FOOTER_ICON_URL) await self.bot.send(ctx, embed=embed)
def generate_embed( self, channel: discord.VoiceChannel, video: pytube.YouTube, status: str, emoji: str, notice: str = None ) -> discord.Embed: try: title = video.title watch_url = video.watch_url except HTTPError: embed = self.bot.generate_embed('⚠️', 'Materiał niedostępny') else: embed = self.bot.generate_embed(emoji, f'{title} – {notice}' if notice else title, url=watch_url) embed.set_author(name=video.author) embed.set_thumbnail(url=video.thumbnail_url) embed.add_field(name='Długość', value=human_amount_of_time(int(video.length))) embed.add_field(name='Kanał', value=channel.name) embed.add_field(name='Głośność', value=f'{int(self.servers[channel.guild.id]["volume"] * 100)}%') embed.add_field(name='Status', value=status) embed.set_footer(icon_url=self.bot.youtube_client.FOOTER_ICON_URL, text=self.bot.youtube_client.FOOTER_TEXT) return embed
def test_zero(self): returned_human_time = human_amount_of_time(0) expected_human_time = '0 s' self.assertEqual(returned_human_time, expected_human_time)
def test_seconds_exactly_one_day(self): returned_human_time = human_amount_of_time(86400) expected_human_time = '1 d' self.assertEqual(returned_human_time, expected_human_time)
def test_seconds(self): returned_human_time = human_amount_of_time(86400 + 3600 + 60 + 1.25) expected_human_time = '1 d 1 h 1 min 1 s' self.assertEqual(returned_human_time, expected_human_time)
def test_timedelta_with_microseconds(self): returned_human_time = human_amount_of_time( dt.timedelta(days=3, hours=9, minutes=3, seconds=1, microseconds=909303) ) expected_human_time = '3 d 9 h 3 min 2 s' self.assertEqual(returned_human_time, expected_human_time)
def test_timedelta(self): returned_human_time = human_amount_of_time(dt.timedelta(days=3, hours=9, minutes=3, seconds=1)) expected_human_time = '3 d 9 h 3 min 1 s' self.assertEqual(returned_human_time, expected_human_time)