Discord bot sorting - discord

I have limited js knowledge and maybe it is simpler to try and do this through the discord bot?
I want to make a discord bot that would work like a sorting hat from harry potter.
My discord server is having a house/faction system and I need a bot to create a personality quiz so that depending on what they answer, they will gain a role of the house they've been placed in.
Each answer to a question will be weighted towards one of the three houses.
EXAMPLE:
H1 equals House 1, H2 equals House 2, H3 equals House 3
What is the most important in your life?
success +1 H1
friendsandfamily +1 H2
change +1 H3
Once all questions are answered, the most points for a house would be where the user ends up in and gets a role.
How the questions and answers should be displayed would look a little like this, where the question and answers would come up in the little menu while answering them would be to react a discord emoji shown below it.

I can give you a flow of whats supposed to happen, but I don't really want to spoon feed you ok?
First, you send a message embed. You can use something like this to visualize an embed that you are making, then use this guide to create an actual embed & send it. Then, you can use discordjs.guide's guide on reactions, in specific adding ones (ordering them) and awaiting ones.
After receiving a reaction, you can then figure out which one, (reaction.emoji.name), and then based on that add to an object, which would be something like
let UserHouses = {
H1: 0,
H2: 0,
H3: 0
};
//upon receiving a reaction and sorting through it, you simply
UserHouses.H1 += weight

Related

Equivalent of a 'While True' loop in Flask: how to do it?

Spending my evenings hobby coding a topography quiz for my daughter. Leveraging the web and Stack Overflow resources, I got an API running on https://ac1976.pythonanywhere.com/api/wereld Hit it and the server will respond with a JSON object comprised of a random country / capital combination, together with a list of 'wrong' answers for the capital. The wrong answers are based on distance to the (correct) capital and are also randomized. So Tokyo won't show up as an answer for the capital of Belgium, but Paris and London may.
On topic: now building a flask app that fetches a response from the aforementioned API, and creates a multiple choice quiz game asking for the capital of the random country, and giving the user 4 multiple choice options.
My main route to do all of this works, and looks like this:
#app.route('/api/continent/', methods=['GET', 'POST'])
def quiz():
if request.method == "GET":
quiz = Game('wereld')
country = quiz.country
answers = quiz.answers
session['capital'] = quiz.capital
return render_template('quiz.html', a1=answers[0], a2=answers[1], a3=answers[2], a4=answers[3], country=country)
else:
answer = request.form['subject']
if answer == session.get('capital'):
return render_template('antwoord.html', answer="Jaaaaa...")
else:
return render_template('antwoord.html', answer="Neee..")
So on hitting the route initially, the server initializes the class Game, which is essentially a wrapper to catch the response from the API and parcel the response with methods for each of the data points we need: country, answers, and capital. These quiz items are stored in similarly named variables country, answers and capital. Country (in the form of a question) and answers (as 4 separate buttons) are used in the HTML template file, presented on hitting the route.
If the user presses one of the four buttons, the second part of the route logic figures out whether the answer was right, or wrong, and sends back a new html view telling the user the answer was right....or wrong.
Okay. All makes sense, right?
Here's my question. How do I autodirect, after say 1 second, back to the 'top of the if loop' so that the code auto refetches a new response from the API, to play another round? I tried to put a simple "While True:" on top of the if / else loop, which works my original terminal version of this quiz...but Flask is not having it. I understand why (it needs a 'GET') but....how to cause a new one?
thanks for your thoughts / guidance / pointing me in the right direction
Arie
How about a meta refresh tag within the header of the HTML page.
After the defined time has expired, you will be redirected to the specified URL.
It would then look something like this.
<meta http-equiv="refresh" content="1; url={{url_for('quiz', _external=True)}}" />
If you want to use JavaScript, a variant with a timeout would also be possible.
const uri = {{url_for('quiz') | tojson}};
setTimeout(() => window.location.replace(uri), 1000);

Deleting every channel in a specified category in discord.py

I am trying to delete every channel in a specified category in discord.py.
My code so far:
category = client.get_channel(my_id_here)
I was thinking of iterating through each of the channels in that category however I'm not sure how to go about doing so.
I saw a similar post on this however that's in discord.js so I would need the discord.py equivalent.
Figured out the solution, hope it helps someone:
category = client.get_channel(id_here)
for channel in category.voice_channels:
await channel.delete()
If you want to remove text channels, replace voice_channels with text_channels

List in custom Alexa skills

I'm new to Alexa Skills but meanwhile I've read tons of information and tutorials.
Fortunately, I'm currently able to create my own custom skill (based on PHP) on my own server and it already works using different intents, utterances, slots etc..
Now, I want Alexa to read a list of items (I send via JSON) in PlainText but I can't find any information how to do this.
I assume there are two options (please correct me if I'm wrong):
Sending a JSON answer including one item - Alexa reads this item - the user says e.g. "next" - Alexa requests my server for the next item - my server sends the next JSON answer ... and so on.
Sending a JSON answer including all items in an array - Alexa reads each item one after another.
I'm not sure which solution is possible and how it can be solved.
So, can anyone help me on this or point me to some information?
Both ways are possible and which one to choose depends on what you are listing.
Using AMAZON.NextIntent
If a single list item include item name and some details about it, then reading out it in one go won't be a good user experience. In this case you can use AMAZON.NextIntent to handle users "next" request.
When the user asks for the list, give the first item in your response and keep a track of the item index in response sessionAttributes. You can also set a STATE attribute too, so that you can check this state in AMAZON.NextIntent handler before you give the next item.
"sessionAttributes": {
"index": 1,
"STATE": "LIST_ITEMS"
}
When the user say "next"
check whether the state is LIST_ITEMS and based on the index give the next item from your list. And in sessionAttributes increment the index
More on sessionAttributes and Response Parameters here
Now, if your items are just names then you can read it one after the other.
In both these solutions it is always good to use SSML rather than just PlainText. SSML gives you more control on how your response is spoken.
More on SSML here

Extract key content from a conversation response

I'm trying to understand the best approach to extract key content during a conversation. I'll use a simple travel interaction example:
I've created a conversation that supports travel activities, and after greeting the user they are asked how can I be of help?
The user responds: I have a flight to Las Vegas today and I need to make a change to my reservation.
Defining the proper Intents and Entities we conclude they want to change a reservation. I want to understand how can I identify, and extract from the response key words like "Las Vegas" and "Today"?
Is there an approach using Watson APIs or do I need to write custom code to dissect the response based on the matching Intents and Entities?
As an example I'd like to confirm to the user: I understand you have a flight to Las Vegas today and would like to make changes to that reservation. Is that right?
Appreciate any advice you can share.
It sounds like you need a place/destination/airport entity, for places like Las Vegas, and an entity for days. You can then use conditions in your dialog flow based on which entity value was matched, for example #place:(Las Vegas). Or you can just repeat the matched entity back to the user in the response, for example I understand you have a flight to #place.
Have a look at the Dialog reference documentation for more information on using entities.
Also, if it helps, there are some examples of day entities in the conversation-starter project entities.csv file on GitHub, and I'm tempted to add an entity for airport codes there if I get a chance.

Parse - how to add comments to an image?

I'm trying to create an iOS application where users post and image, and then someone can comment on the image. So far I've set up the a message class which contains (among other things) the image file. I want to be able to add comments to the image, so what would be the best way of doings this.
Option A:
I could add an array (or object?) column to the already existing message class, and then store in this array the comment (string) and the id of the poster (string). For this I think I would need a two-dimensional array, but I'm not sure how I would go about doing this.
Option B:
I could make an entire new class of comments which contains the user's comments (string), as well as the image file that he/she linked to (perhaps though a PFRelation)
Basically I'm leaning to Option A, because it seems easier/more efficient to implement, but I don't really know how I would go about creating a two-dimensional/array of objects - so my question is, how would I go about doing this?
The way I did it in my app is option B. I then added a count column to the photo that was incremented/decremented onSave or onDelete. I think this method is better because it keeps the data more symmetric (with option A some data could have thousands of comments while others would have 0). Additionally, it allows you to query the comments cell if you wanted to have a notification view where you showed the user what activity has been done on their photo.

Resources