How to create a command using multiple options in JDA? - discord-jda

I wanted to create a nick command, however, I don't know how to add multiple options. The method addOption() just adds one.
event.getGuild().upsertCommand("nick", "Change the nickname of the specified user").addOption(OptionType.USER,"nicknameuser", "Specified User", true).queue();

How about to call addOption again after using addOption?
event.getGuild().upsertCommand("nick", "Change the nickname of the specified user")
.addOption(OptionType.USER, "nicknameuser", "Specified User", true)
.addOption(OptionType.STRING, "search", "Search the user with a string", true)
.queue();
like this

Related

RASA FormAction ActionExecutionRejection doesn’t re-prompt for missing slot

I am trying to implement a FormAction here, and I’ve overridden validate method.
Here is the code for the same:
def validate(self, dispatcher, tracker, domain):
logger.info("Validate of single entity called")
document_number = tracker.get_slot("document_number")
# Run regex on latest_message
extracted = re.findall(regexp, tracker.latest_message['text'])
document_array = []
for e in extracted:
document_array.append(e[0])
# generate set for needed things and
document_set = set(document_array)
document_array = list(document_set)
logger.info(document_set)
if len(document_set) > 0:
if document_number and len(document_number):
document_array = list(set(document_array + document_number))
return [SlotSet("document_number", document_array)]
else:
if document_number and len(document_number):
document_array = list(set(document_array + document_number))
return [SlotSet("document_number", document_array)]
else:
# Here it doesn't have previously set slot
# So Raise an error
raise ActionExecutionRejection(self.name(),
"Please provide document number")
So, ideally as per the docs, when ActionExecutionRejection occurs, it should utter a template with name utter_ask_{slotname} but it doesn’t trigger that action.
Here is my domain.yml templates
templates:
utter_greet:
- text: "Hi, hope you are having a good day! How can I help?"
utter_ask_document_number:
- text: "Please provide document number"
utter_help:
- text: "To find the document, please say the ID of a single document or multiple documents"
utter_goodbye:
- text: "Talk to you later!"
utter_thanks:
- text: "My pleasure."
The ActionExecutionRejection doesn't by default utter a template with the name utter_ask_{slotname}, but rather leaves the form logic to allow other policies (e.g. FallbackPolicy) to take action. The utter_ask_{slotname} is the default for the happy path in which it's trying to get a required slot for the first time. This default implementation of the action rejection is there in order to handle certain unhappy paths such as if a user decides they want to exit the flow by denying, or take a detour by chatting, etc.
If you want to implement the template to re-ask for the required slot using the utterance, you could replace the ActionExecutionRejection with dispatcher.utter_template(<desired template name>, tracker). However, this will leave you with no way to exit the form action without validation -- I don't know what your intents are, but perhaps you want to also incorporate some logic based on the intent (i.e. if it's something like "deny", let the ActionExecutionRejection happen so it can exit, it it's an "enter data" type of intent make sure it asks again).

Get the user's value of an intent in RASA Core/NLU

I have the same question as in: Get Intent Value in RASA Core/NLU
but I want the value that the user gives for a given intent.
For example:
User: I want to take it (this sentence is an intent called: 'use_it')
Bot: ....
User: .... (Later in the chat I decide to answer with the same phrase of intent 'use it')
Bot: you said previously "I want to take it"
How can I do something like: tracker.get_slot but for intent?
I don't want the name of the last intent I want the text of a user-given intent.
Execute a custom action after the intent in which you store the intent text in a slot:
from rasa_core_sdk import Action
from rasa_core_sdk.events import SlotSet
class ActionStoreIntentMessage(Action):
"""Stores the bot use case in a slot"""
def name(self):
return "action_store_intent_message"
def run(self, dispatcher, tracker, domain):
# we grab the whole user utterance here as there are no real entities
# in the use case
message = tracker.latest_message.get('text')
return [SlotSet('intent_message', message)]
You can then use the value of the set slot within an utter template:
slots:
intent_message:
type: text
templates:
utter_last_intent:
- "you said previously: {intent_message}"
You can use tracker for the task.
text=tracker.latest_message['text']

Calling step in step definitons

I'm trying to call a step that takes an argument in an another step definitions but i'm getting an error like
Cucumber::UndefinedDynamicStep: Undefined dynamic step: "And user
select Electronics as category group from dropdown list"
.feature file
And user fill the create new category form "Electronics"
.rb file
And(/^user fill the create new category form "([^"]*)"$/) do |name|
step "And user type name #{name}"
And(/^user type name "([^"]*)"$/) do |name|
find(:id, 'namePanelGroup').set(name)
end
How can i handle with this situation?
You need to add escaped double quotes because the step you are calling has double quotes around the regex, and you need to remove the "And" like so:
step "user type name \"#{name}\""

How to make an optional strong parameters key but filter nested params?

I have this in my controller:
params.require(:item).permit!
Let's assume this rspec spec, which works as expected:
put :update, id: #item.id, item: { name: "new name" }
However, the following causes ActionController::ParameterMissing:
put :update, id: #item.id, item: nil
It has to do with controller macros that I use for other actions and through which I cannot control the params being sent (the macros checks for user credentials, so I don't really care about actually testing an #update action, rather I just test before_filters for it).
So my question is: How do I make params[:item] optional, yet still filter attributes within it if it's present?
What about:
params.require(:item).permit! if params[:item]
You cannot require an optional parameter. That is contradictory.
Edit: as mtjhax mentioned in his comment, there is advice from here to use fetch instead: params.fetch(:item, {}).permit!

how to create a hyper-link in iReport?

I'm using iReport-3.7.6
I have created a sample_Report1 with one parameter as (Project_name) and
I have created the Sample_Report2 with one parameter as (Employee_No)
Now I want to create a hyper-link in Sample_Report1 to Sample_Report2.
(pass the employee_no as a parameter to Sample_Report2 from Sample_Report1 using hyper-link)
rclick on the text field > link parameter
hyperlink target: Self
hyperlink type: ReportExecution
A. add "link parameter name" = uri (well in my repository setup this is what I use)
then Value Expression is the URL enclosed in " "
B. Click on add again "parameter name" value will be the field parameter
when you click mouse over on the link it should be like this
www.yoursite.com/reports/executeReports.jsp?uri=/path/report/yearend&year=2010
this is your URI = "uri=/path/report/yearend"
this is your parameter = "year=2010"
hope this helps...

Resources