async def sambungkata(self, ctx): players = [] lobby = await ctx.channel.send(embed=self.lobby_embed(['okok']), components=[ Button(custom_id='join_sk', label='Join', color='blurple', new_line=False), Button(custom_id='start_sk', label='Start', color='green', new_line=False), Button(custom_id='leave_sk', label='Leave', color='red', new_line=False), ]) while True: try: lobby_btn = await lobby.wait_for(self.bot, 'button', timeout=300) if lobby_btn.custom_id == 'join_sk': pass except asyncio.TimeoutError: pass
def generate_embed(self, post, max_index, curr_index, disable_components: bool = False): filename = self.save_image(post) tags = [] for tag in post.tags: if not tag['translated_name'] and not any( map(tag['name'].__contains__, ['bookmark', 'user'])): tags.append(tag['name']) if tag['translated_name'] and not any( map(tag['translated_name'].__contains__, ['bookmark', 'user'])): tags.append(tag['translated_name']) components = [ Button(custom_id='pixiv_first', color='grey', emoji=UI.first_arrow, disabled=curr_index == 1 or disable_components), Button(custom_id='pixiv_prev', color='blurple', emoji=UI.previous_arrow, disabled=curr_index == 1 or disable_components), Button(custom_id='delete', color='red', label='Delete', disabled=False), Button(custom_id='pixiv_next', color='blurple', emoji=UI.next_arrow, disabled=max_index == 1 or (curr_index == max_index) or disable_components), Button(custom_id='pixiv_last', color='grey', emoji=UI.last_arrow, disabled=max_index == 1 or (curr_index == max_index) or disable_components), ] embed = Embed(title=post.title[:255], color=0x0045ff) embed.set_author( name= f'By {post.user.name[:50]} (@{post.user.account[:50]}) on {post.create_date[:10]}', icon_url= 'https://upload.wikimedia.org/wikipedia/commons/thumb/7/7e/Pixiv_Icon.svg/450px-Pixiv_Icon.svg.png', url=f'https://www.pixiv.net/en/users/{post.user.id}') embed.add_field(name='Tags', value=', '.join(tags), inline=False) embed.set_image( url=f'{self.MEDIA_SERVER}/download/{filename}?folder=robi-pixiv') embed.set_footer( text= f'👁🗨{post.total_view} ─── {curr_index} of {max_index} illustration ─── ID: {post.id}' ) return embed, components
def generate_embed(self, post: Submission, max_index: int, curr_index: int, disable_components: bool = False): components = [ Button(custom_id='reddit_first', color='grey', emoji=UI.first_arrow, disabled=curr_index == 1 or disable_components), Button(custom_id='reddit_prev', color='blurple', emoji=UI.previous_arrow, disabled=curr_index == 1 or disable_components), Button(custom_id='delete', color='red', label='Delete', disabled=False), Button(custom_id='reddit_next', color='blurple', emoji=UI.next_arrow, disabled=max_index == 1 or (curr_index == max_index) or disable_components), Button(custom_id='reddit_last', color='grey', emoji=UI.last_arrow, disabled=max_index == 1 or (curr_index == max_index) or disable_components), ] embed = Embed(title=post.title[:255], url=post.url, color=0xff4500) embed.set_author( name= f'Posted by /u/{post.author} on {self.parse_utc(post.created_utc)}', icon_url= "https://cdn2.iconfinder.com/data/icons/metro-ui-icon-set/512/Reddit.png", url=f'https://www.reddit.com/user/{post.author}') if post.link_flair_text: embed.add_field(name='🏷️ Flair', value=post.link_flair_text, inline=True) if post.over_18: embed.add_field(name='🏷️ Marked', value="NSFW", inline=True) if post.thumbnail and self.is_valid_image(post.url): embed.set_image(url=post.url) if post.is_video: embed.add_field(name='Video URL', value=post.url, inline=False) if post.selftext: embed.description = f'{post.selftext[:1024]}\n' embed.set_footer( text=f'👍{post.ups} ─── {curr_index} of {max_index} posts') return embed, components
def generate_embed(self, page=1, disable_components=False): data = self.get_all()['messages'] max_page = get_max_page(len(data), 5) last_index = page * 5 first_index = last_index - 5 components = [ Button(custom_id='rm_prev', color='blurple', emoji=UI.previous_arrow, disabled=page==1 or disable_components), Button(custom_id='rm_next', color='blurple', emoji=UI.next_arrow, disabled=page==max_page or disable_components), ] embed = Embed(title='List Ready Message', color=random.randint(0, 0xffffff)) for message in data[first_index:last_index]: embed.add_field(name=f'ID: {message["id"]}', value=f'<:reply:885797725327745085>{message["message"]}', inline=False) embed.set_footer(text=f'Page {page}/{max_page}') return embed, components
async def negara(self, ctx, page=1): page = page countries = await ctx.channel.send(embed=embed_countries(page), components=[ Button('prev', 'Previous Page', 'blurple'), Button('next', 'Next Page', 'blurple'), ]) try: while True: if page == 1: await countries.edit(components=[ Button( 'prev', 'Previous Page', 'blurple', disabled=True), Button('next', 'Next Page', 'blurple', disabled=False), ]) elif page == 9: await countries.edit(components=[ Button( 'prev', 'Previous Page', 'blurple', disabled=False), Button('next', 'Next Page', 'blurple', disabled=True), ]) else: await countries.edit(components=[ Button( 'prev', 'Previous Page', 'blurple', disabled=False), Button('next', 'Next Page', 'blurple', disabled=False), ]) btn = await countries.wait_for(self.bot, 'button', timeout=60) await btn.respond(ninja_mode=True) if btn.custom_id == 'prev': page = page - 1 if btn.custom_id == 'next': page = page + 1 await countries.edit(embed=embed_countries(page)) except asyncio.TimeoutError: await countries.edit(components=[ Button('prev', 'Previous Page', 'blurple', disabled=True), Button('next', 'Next Page', 'blurple', disabled=True), ])
def generate_lobby_embed(self, players: list): string_players = '' for player in players: string_players += f'<:reply:885797725327745085>{player["player"].mention}\n' components = [ Button(custom_id='sk_start', label='Start', color='green'), Button(custom_id='sk_join', label='Join', color='blurple'), Button(custom_id='sk_hasbi', label='Ajak Hasbi', color='blurple'), Button(custom_id='sk_exit', label='Exit', color='red') ] embed = Embed(title='Hasbi Sambung Kata', color=randint(0, 0xffffff)) embed.add_field(name='Players:', value=string_players or 'Belum Ada Pemain') embed.set_footer( text= f'{len(self.ready)}/{len(self.players)-1 if self.hasbi_playing else len(self.players)} Pemain Sudah Menekan Tombol Start' if len(self.players) >= 2 else '') return embed, components
def generate_embed(self, sauce, max_index: int, curr_index: int, disable_components: bool = False): components = [ Button(custom_id='sauce_first', color='blurple', emoji=UI.first_arrow, disabled=curr_index == 1 or disable_components), Button(custom_id='sauce_prev', color='blurple', emoji=UI.previous_arrow, disabled=curr_index == 1 or disable_components), Button(custom_id='delete', color='red', label='Delete', disabled=False), Button(custom_id='sauce_next', color='blurple', emoji=UI.next_arrow, disabled=max_index == 1 or (curr_index == max_index) or disable_components), Button(custom_id='sauce_last', color='blurple', emoji=UI.last_arrow, disabled=max_index == 1 or (curr_index == max_index) or disable_components), ] embed = Embed(color=randint(0, 0xffffff), title='Hasbi Image Search') embed.add_field(name='Author', value=sauce.author, inline=True) embed.add_field(name='Title', value=sauce.title, inline=True) embed.add_field(name='HD URL', value=sauce.urls[0], inline=False) embed.set_image(url=sauce.thumbnail) embed.set_footer(text=f'Similarity: {sauce.similarity}%') return embed, components
def generate_embed(self, question: str = "", guess=None, guessing: bool = False, disable_components: bool = False): embed = Embed(color=randint(0, 0xffffff), title='Hasbi Menebak Karakter') if guessing: embed.add_field(name=guess['name'], value=guess['description']) embed.set_thumbnail(url=guess['absolute_picture_path']) components = [ Button(custom_id='aki_benar', label='Benar', color='green', disabled=disable_components), Button(custom_id='aki_salah', label='Salah', color='red', disabled=disable_components) ] else: embed.description = question.title() components = [ Button(custom_id='aki_yes', label='Ya', color='green', disabled=disable_components), Button(custom_id='aki_maybe', label='Mungkin', color='blurple', disabled=disable_components), Button(custom_id='aki_idk', label='Gatau', color='blurple', disabled=disable_components), Button(custom_id='aki_no', label='Tidak', color='red', disabled=disable_components), Button(custom_id='aki_stop', label='Stop', color='red', disabled=disable_components), ] return embed, components
async def reddit(self, ctx, subreddit_search, *, submission_search=""): async with ctx.typing(): reddit_client = RedditClient.reddit_client posts = self.get_posts(subreddit_search, submission_search, reddit_client) max_post = len(posts) post, posts = self.choose_random(posts) history = [post] current_index = 1 components = [ Button(custom_id='previous', color='blurple', emoji='⬅️', disabled=True), Button(custom_id='delete', label='Delete', color='red'), Button(custom_id='next', color='blurple', emoji='➡️', disabled=max_post <= 1), ] if not post: raise IndexError reddit = await ctx.channel.send( embed=self.embed_post(post, max_post, current_index), components=self.append_pin_button(components, post)) try: while True: btn = await reddit.wait_for(self.bot, 'button', timeout=60) await btn.respond(ninja_mode=True) if btn.custom_id == 'next': current_index += 1 components = [ Button(custom_id='previous', color='blurple', emoji='⬅️', disabled=False), Button('delete', 'Delete', 'red'), Button(custom_id='next', color='blurple', emoji='➡️', disabled=current_index >= max_post), ] research = (max_post != len(history)) and ( current_index == len(history) + 1) if research: post, posts = self.choose_random(posts) await reddit.edit(embed=self.embed_post( post, max_post, current_index), components=self.append_pin_button( components, post)) history.append(post) else: post = history[current_index - 1] await reddit.edit(embed=self.embed_post( post, max_post, current_index), components=self.append_pin_button( components, history[current_index - 1])) if btn.custom_id == 'previous': current_index -= 1 post = history[current_index - 1] components = [ Button(custom_id='previous', color='blurple', emoji='⬅️', disabled=current_index == 1), Button('delete', 'Delete', 'red'), Button(custom_id='next', color='blurple', emoji='➡️', disabled=False), ] await reddit.edit(embed=self.embed_post( post, max_post, current_index), components=self.append_pin_button( components, history[current_index - 1])) except asyncio.TimeoutError: await reddit.edit(components=self.append_pin_button([ Button(custom_id='previous', color='blurple', emoji='⬅️', disabled=True), Button('delete', 'Delete', 'red', disabled=False), Button(custom_id='next', color='blurple', emoji='➡️', disabled=True), ], post))
def append_pin_button(self, component, post): if post.thumbnail and self.is_valid_image(post.url): component.append( Button(custom_id='pin_reddit', color='green', label='Pin')) return component