How do I create an optional list of choices in a discord slash command? - discord

I am creating a game using a discord bot and am in the process of switching to slash commands. I am trying to create a command to inspect an item (as in an in-game item e.g. "iron ore") and I want the player to be able to choose from a list of all items in the game while using the inspect command. I'd imagine it would look like this: /inspect iron_ore, where the iron_ore is an item select from a list. I have successfully implemented selecting from a list of members in a command, but I do not know how to get a selectable list from other sources.
In the snippet below, I have a database query that gets all of the items in the game and returns them in a list. Additionally, how can I make this optional? I would like the /inspect command to work even if the player doesn't input an item.
db_query = get_all_items_in_db()
#tree.command(name = "inspect", description = "Examine an item in more detail")
#app_commands.describe(item = "Select an item to inspect")
async def self(interaction: discord.Interaction, item: str):
await interaction.response.send_message(f"You inspect {item}!")
I've tried passing the database query into #app_commands.choices, but it does not accept lists as a datatype.

To make an argument optional, you can type annotate it as - very unsurprisingly - Optional. Alternatively, giving it a default value will work as well.
To dynamically populate the suggestions shown to a user (I think this is what you want) you can use an autocomplete. There's an example in the docs: https://discordpy.readthedocs.io/en/stable/interactions/api.html?highlight=autocomplete#discord.app_commands.autocomplete
Note that when using an autocomplete the user can only select one item, and they aren't forced to choose anything. These are only suggestions, and they can type in whatever they want.
If you don't want that, then there's also an official example for how to create select menus ("dropdowns"): https://github.com/Rapptz/discord.py/blob/master/examples/views/dropdown.py

Related

Is it possible with an ADF ComboBox component to type in values not present in the given LOV?

I am working on an input form using ADF. I have an input field in which I want to show a list from which the user can select the value and also require a type option in case the value user want is not in the list.
I use the JDeveloper 12.2.1.3 for development. I have tried using ADF ComboBox component based on a static list. The component gives a list a expected. But I cannot type in a new value in case the value I wanted is not in the list. I can only type whatever is in the list already.
I am looking for something similar to the HTML input-datalist combination which gives a list and allows type if the intended value is not in the list.
The InputListOfValues and other LOV components only allow you to enter data which is present in the list. That is the way these components are designed. It would not make sense to allow other input as you normally use such components in places where you want to make sure the user can only input reference data defined in other data.
Anyway, it's easy to create some kind of component which allows you exactly what you want. I wrote a blog n this here https://tompeez.wordpress.com/2013/02/03/jdeveloper-11-1-1-6-0-afinputtext-with-self-made-look-up-not-using-lov/
From this page you can download and run the ADF Faces Rich Client Demo, which shows all components and what they do.

React/Redux: Loading/merging all options and selected values

Using React and Redux...
I have an endpoint that returns the following model:
Name (String), and
Colors (Array)
And another endpoint that lists all the color options the user can choose from.
Now I want to make a multi-select that lists all the color options, which the appropriate ones selected based on what the first endpoint returns.
My questions are around how to best handle this.
1) Should I just instead create one endpoint that returns the model along with all the color options already included?
2) Or should I call both endpoints from one action creator, wait for both responses somewhere, then merge the data added a 'selected' property to those that should be selected?
3) Or something else?
Any help in how to design this would be much appreciated. Or a link to an example..I've searched and surprisingly can't find one.

show next prompt based on answering the current prompt in ODK

I am new to ODK and I am trying to create an XForm in ODK and the following is the issue i am stuck in.
PROBLEM:
The user selects Gravel, Drainage or Unimproved from the first prompt. The next prompt is about the rating for the item selected in the previous prompt. Now I need to set rates 1 to 5 if Gravel is selected and 1 to 4 if any other is selected in the previous prompt.
What I have done:
I have set two prompts (Paser_Rates and Paser_Rates2), each has its own binding that the correct one is displayed based on the selected prompt.
<bind nodeset="/widgets/main_repeat/PaserRates" relevant="not(selected(../RoadType, 'gravel'))" type="select1" required="true()" saveIncomplete="true()" />
<bind nodeset="/widgets/main_repeat/PaserRates2" relevant="selected(../RoadType, 'gravel')" type="select1" required="true()" saveIncomplete="true()" />
This does not solve my problem because I am not supposed to have two prompts and I need to save the rating values in one column (Paser_Rates).
Please let me know what solution you have for this.
XForm terminology:
The way to do this is to use itemsets with a secondary instance that contains your choice lists. Instead of relevants use an XPath predicate to determine which choices to show.
XLSForm terminology
This (and any other form) will be much easier if you use XLSForm to create your XForm. You need to create a cascading select and use a choice filter instead of a relevant to determine which choices to show.

Can I set a parameter using ngRoute?

I am making an app that shows a list of items, and that list can then be refined by multiple filters. If I were to fetch a list of those options from the URL string, then that would allow visitors to share (or bookmark) a link that takes you to a filtered list of data. But my questions is how would I write those options to the URL string?
So the idea is that once a select element has been changed, to refine the results. Let's say for example that it's just the order of the items.
<select ng-model="order" ng-change="changeOrder()">
<option ng-repeat="['date', 'amplitude', 'name'] as option">{{ option }}</option>
</select>
I would want to write that option into the URL string, so that it now contains (if you've selected amplitude) ?order=amplitude. Now, if you refresh the page, the data can easily be sorted by amplitude again.
But when there is a lot of those filters and sorting options, and they can be both set or reset to default, it becomes rather difficult to put those options all together, to check if an option is already in the string so as to not have it twice, and whether to add it behind a ? if there are no other options, or a & if there are other options already defined.
So in other words, what I want to know is does ngRoute provide methods to set parameters; not just read them? So I could do something like $routeParams.set("order", "amplitude").
If you want to change the URL, you should do this through the $location service.
Specifically the $location.search(search, paramValue) will allow you to change the query string values.
I made a plunk that demonstrates both using HTML5 mode and changing the $location using these functions. It can be found here. In order to see the URL change, click the pop-out button .
You don't have to do the string parsing yourself. AngularJS will also allow you (with the same function) to query the currently set parameters. So it's a matter of querying all the URL values, changing the one for which filter you're changing, and then setting the values back.
This is what the second button in the example demonstrates. Even though the first button will only set its own value (and remove the others), the second button will keep all other items as well.
The relevant code:
var values = $location.search();
values.orderThatsUpdating = newOrderValue;
$location.search(values);

aws DynamoDb Boto adding a new item to a table

I am working to add items to a dynamodb database using python (boto api). I saw examples of people creating items and storing them using the table.new_item method.
Ex:
dynamoConn = boto.connect_dynamodb(aws_access_key_id, aws_secret_access_key)
dTable = dynamoConn.get_table(aws_dynamo_table)
....
item_data = {}
....
dTable.new_item(loc, theNewKey, item_data)
The code runs, I do not find any errors and when tracing through using debugger I do not see any reason why my item, a hash of keys and text values can't be stored.
I read: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithTables.html
However I think I may be missing an "update table" function. I'm not seeing one nor can I find an example of one online.
Any ideas?
The new_item method returns an Item object that is ready to be saved to DynamoDB but it doesn't actually save it for you. Once you are ready to save the item, you need to call the save (UpdateItem) or put (PutItem) method of the Item object.

Resources