async def command__slash__demonstrator_tools(self, ctx: SlashContext) -> None: if await is_authorised_demonstrator(ctx, 'NEW') is False: return select = create_select( options=[ create_select_option('Next', value='Next', emoji="👩"), create_select_option('Display Queue', value='Display Queue', emoji="📟"), create_select_option('Clear Queue', value='Clear Queue', emoji="🧹"), create_select_option('Clear Role', value='Clear Role', emoji="🧹"), create_select_option('Purge Channel', value='Purge Channel', emoji="🧹") ], placeholder="Utility selection", min_values=1, max_values=1 ) await ctx.send("Please select a utility.", components=[create_actionrow(select)], hidden=True) button_ctx: ComponentContext = await wait_for_component(self.bot, components=[create_actionrow(select)]) if button_ctx.values[0] == 'Next': await button_ctx.edit_origin(content=await next_student(ctx), components=[]) elif button_ctx.values[0] == 'Display Queue': await display_queue(ctx, button_ctx) elif button_ctx.values[0] == 'Clear Role': await clear_role(ctx, button_ctx) elif button_ctx.values[0] == 'Clear Queue': await clear_queue(ctx, button_ctx) elif button_ctx.values[0] == 'Purge Channel': await purge_channel(ctx, button_ctx)
async def on_database_area_selected(self, ctx: ComponentContext, game: RandovaniaGame, split_world: SplitWorld, world_id: int): option_selected = ctx.selected_options[0] valid_items = [ area for i, area in enumerate(split_world.areas) if f"area_{i}" == option_selected ] if not valid_items: return await ctx.edit_origin( components=[], embeds=[], content= f"Invalid selected option, unable to find given area '{option_selected}'." ) area = valid_items[0] db = default_database.game_description_for(game) title = "{}: {}".format(game.long_name, db.world_list.area_name(area)) valid_nodes = [ node for node in sorted(area.nodes, key=lambda it: it.name) if not node.is_derived_node ] select = manage_components.create_select( options=[ manage_components.create_select_option(node.name, value=node.name) for node in valid_nodes ], max_values=min(10, len(valid_nodes)), custom_id=f"{game.value}_world_{world_id}_{option_selected}", placeholder="Choose the room", ) action_row = manage_components.create_actionrow(select) files = [] area_image = render_area_with_pillow(area, game.data_path) if area_image is not None: files.append( discord.File(area_image, filename=f"{area.name}_image.png")) area_graph = render_area_with_graphviz(area) if area_graph is not None: files.append( discord.File(area_graph, filename=f"{area.name}_graph.png")) logging.info("Responding to area for %s with %d attachments.", area.name, len(files)) await ctx.send( content=f"**{title}**\nRequested by {ctx.author.display_name}.", files=files, components=[ action_row, ], )
async def send_files_as_message(self, ctx: SlashContext, files: List[Dict]): """ Send files as a message to ctx. Args: ctx: The originating context. files: The files to send to the context. """ files = files[:25] # TODO: Display all of the files in the embed if file count <= 5 if len(files) <= 5: buttons = [ create_button(style=ButtonStyle.URL, label=f['filename'], url=f['jump_url']) for f in files ] action_row = create_actionrow(*buttons) else: # TODO: Sort the files in the select options = [] for file in files: option = create_select_option( label=file['filename'], value=','.join( map(str, [ file['channel_id'], file['message_id'], file['objectID'] ]))) options.append(option) select = create_select(options=options, placeholder="Choose your files here!", min_values=1, max_values=1) action_row = create_actionrow(select) embed = discord.Embed( title=f"Found {len(files)} file{'s' if len(files) > 1 else ''}", color=discord.Colour.teal()) embed.set_footer( text= f"Delivered by {self.bot.user.name}, a better file manager for discord.", icon_url=self.bot.user.avatar_url) filename = files[0].get('filename') mediaUrl = files[0].get('jump_url') if not mediaUrl: file_id = files[0]['objectID'] res = await self.db_client.get_file(file_id) mediaUrl = res['url'] embed.insert_field_at(index=0, name=filename, value=mediaUrl, inline=False) if 'image' in files[0]['content_type']: embed.set_image(url=files[0]['url']) await ctx.send( f"Found {files[0]['filename']} {'and more...' if len(files) > 1 else ''}", embed=embed, components=[action_row])
async def on_database_world_selected(self, ctx: ComponentContext, game: RandovaniaGame): option_selected = ctx.selected_options[0] valid_items = [ it for i, it in enumerate(self._split_worlds[game]) if f"{game.value}_world_{i}" == option_selected ] if not valid_items: return await ctx.edit_origin( components=[], embeds=[], content= f"Invalid selected option, unable to find given world subset '{option_selected}'." ) index = self._split_worlds[game].index(valid_items[0]) world, world_name, areas = valid_items[0] select = manage_components.create_select( options=[ manage_components.create_select_option(area.name, value=f"area_{i}") for i, area in sorted(enumerate(areas), key=lambda it: it[1].name) ], custom_id=f"{game.value}_world_{index}", placeholder="Choose the room", ) action_row = manage_components.create_actionrow(select) back_row = manage_components.create_actionrow( manage_components.create_button( style=ButtonStyle.secondary, label="Back", custom_id=f"back_to_{game.value}", )) embed = Embed( title=f"{game.long_name} Database", description=f"Choose the room in {world_name} to visualize.") logging.info( "Responding to area selection for section %s with %d options.", world_name, len(areas)) await ctx.edit_origin( embed=embed, components=[ action_row, back_row, ], )
def _message_components_for_game(self, game: RandovaniaGame): options = [] for i, (world, world_name, areas) in enumerate(self._split_worlds[game]): custom_id = f"{game.value}_world_{i}" options.append( manage_components.create_select_option(world_name, value=custom_id)) action_row = manage_components.create_actionrow( manage_components.create_select( options=options, custom_id=f"{game.value}_world", placeholder="Choose your region", )) embed = Embed(title=f"{game.long_name} Database", description="Choose the world subset to visualize.") logging.info("Responding requesting list of worlds for game %s.", game.long_name) return embed, [action_row],
] gm_roles = [ "740528491367497781", #1. mc "796695732740554764", #2. csgo "796695564024283156", #3. lol "796696220286058516", #4. r6 "796696319640993812", #5. amogus "894182437897244683", #6. rocket league "894183010759507978", #7. overwatch "894181680875712572" #8. apex ] choice_ev = create_select( options=[ create_select_option(label="Évfolyam: 2021", value="881250917113020488", emoji="🥼"), create_select_option(label="Évfolyam: 2020", value="881250853950996531", emoji="🧪"), create_select_option(label="Évfolyam: 2019", value="881250749521223680", emoji="🧫"), create_select_option(label="Évfolyam: 2018", value="882334562095607868", emoji="🦠"), ], custom_id="ev_select", placeholder="Évfolyamválasztó", min_values=1, max_values=1 ) choice_ga = create_select( options=[ create_select_option(label="Gárda: Fekete", value="744645865825632296", emoji="🖤"), create_select_option(label="Gárda: Fehér", value="744644982396289219", emoji="🤍"), create_select_option(label="Gárda: Kék", value="744644137499885629", emoji="💙"),
async def fight(ctx, target): # Checks if they are already fighting: if ctx.author.id in client.current_fighters: await ctx.send("You can't fight two people at once.") return try: if target.id in client.current_fighters: await ctx.send(target.name + " is already in a fight.") return except Exception as exception: await ctx.send( f"An error has occured: `{exception}`. \nThis might be because you are in a dm but I'm not sure. If something is wrong, please notify Melumi#5395 in chat or in the official support server (!help)" ) return if ctx.author.id == target.id: await ctx.send("You can't fight yourself.") return # checking to see both players' lucky numbers are registered try: client.luckies[ctx.author.id] except KeyError: await ctx.send( f"Uh oh, {ctx.author.name}'s lucky number is not in my database. \nYou can use `/setlucky` to temporarily set your lucky number to fight, and `/setstats` to set your stats permanently, including lucky number." ) return try: client.luckies[target.id] except KeyError: await ctx.send( f"Uh oh, {target.name}'s lucky number is not in my database. \nYou can use `/setlucky` to temporarily set your lucky number to fight, and `/setstats` to set your stats permanently, including lucky number." ) return # Create an instance of the FightClass # str(ctx.author.id) = FightClass(ctx.author, target) # Add them to the list of fighters client.current_fighters.append(ctx.author.id) client.current_fighters.append(target.id) client.current_fights.append( FightClass(ctx.author, target, client, PLAYERHP, ctx.channel.id)) embedVar = discord.Embed( title= (f"**{ctx.author.name}** challenges **{target.name}** to a battle!" ), description="The first player to lose all their health loses.", color=0x00ff00) embedVar.add_field( name= (f"**{ctx.author.name}**'s lucky number is {client.luckies[ctx.author.id]} and **{target.name}**'s is {client.luckies[target.id]}." ), value=("Type `roll` to attack and `!quit` to stop fighting."), inline=False) embedVar.set_thumbnail(url=(ctx.author.avatar_url)) await ctx.send(embed=embedVar) select = create_select( options=[ # the options in your dropdown create_select_option("Casual Fight", value="casual", emoji={ 'name': 'SofiaUwU', 'id': 837785194751721532 }), create_select_option("Official Fight", value="official", emoji={ 'name': 'sofiagun', 'id': 809882437508399144 }), ], placeholder="Choose your fight type", min_values=1, # the minimum number of options a user must select max_values=1, # the maximum number of options a user can select ) await ctx.send( "Please choose your fight type. You can do this at any time, and this will override whatever has been selected previously.", components=[create_actionrow(select)] ) # like action row with buttons but without * in front of the variable
async def cmd_start_game(message: discord.Message, args: str, isDM: bool): if not args: await message.channel.send( ":x: Please give the name of the deck you would like to play with!" ) return callingBGuild = botState.guildsDB.getGuild(message.guild.id) if args not in callingBGuild.decks: await message.channel.send(":x: Unknown deck: " + args) return if message.channel in callingBGuild.runningGames: await message.reply( ":x: A game is already being played in this channel!") return if callingBGuild.decks[args]["updating"]: await message.channel.send(":x: This deck is currently being updated!") return if args in callingBGuild.activeDecks: gameDeck = callingBGuild.activeDecks[args] else: try: gameDeck = sdbDeck.SDBDeck(callingBGuild.decks[args]["meta_path"]) except RuntimeError as e: gameDeck = None await message.reply( "An unexpected error occurred when building the deck, the error has been logged.\nPlease try playing with a different deck!" ) botState.logger.log( "usr_deck", "cmd_start_game", "Exception occured when trying to build a deck before starting a game", eventType=type(e).__name__, trace=traceback.format_exception(type(e), e, e.__traceback__)) if gameDeck is not None: reservation = sdbGame.GameChannelReservation(gameDeck, callingBGuild) callingBGuild.runningGames[message.channel] = reservation emojiForRoundNum = lambda x: cfg.defaultEmojis.menuOptions[ x].sendable if 0 <= x < len( cfg.defaultEmojis.numbers ) else cfg.defaultEmojis.highNumber.sendable select = create_select( options=[create_select_option(f"Best of {numRounds}", value=str(numRounds), emoji=emojiForRoundNum(numRounds)) for numRounds in cfg.roundsPickerOptions] \ + [create_select_option("Free play", value="-1", emoji=cfg.defaultEmojis.spiral.sendable), create_select_option("Cancel", value="cancel", emoji=cfg.defaultEmojis.cancel.sendable)], placeholder="Click to select game length...", # the placeholder text to show when no options have been chosen min_values=1, # the minimum number of options a user must select max_values=1, # the maximum number of options a user can select ) waitComps = create_actionrow(select) selectorMsg = await message.channel.send( "How many rounds would you like to play?", components=[waitComps]) # note: this will only catch one button press, if you want more, put this in a loop button_ctx: ComponentContext = await wait_for_component( botState.client, components=[waitComps], check=lambda x: x.author_id == message.author.id) if button_ctx.selected_options[0] == "cancel": # Remove channel reservation del callingBGuild.runningGames[message.channel] await button_ctx.edit_origin( content=cfg.defaultEmojis.submit.sendable + " Game cancelled.", embed=None, components=[]) elif reservation.shutdownOverride: shutdownReason = reservation.shutdownOverrideReason or "The game was forcibly ended, likely due to an error. Please try again." await button_ctx.edit_origin( content= f"{selectorMsg.content}\n\n{cfg.defaultEmojis.cancel.sendable} {shutdownReason}" ) else: try: await button_ctx.defer(edit_origin=True) except discord.NotFound: pass rounds = int(button_ctx.selected_options[0]) expansionPickerMsg = selectorMsg expansionsData = callingBGuild.decks[args]["expansions"] expansionsPicker = buttonMenus.SDBExpansionPicker( selectorMsg, expansionsData, args, rounds, message.author.id, selectControlsUseEmoji=False, controlsUseEmoji=True) await expansionsPicker.updateMessage( content= f"Please select at least 1 black card and {cfg.minPlayerCount * cfg.cardsPerHand} white cards." )