Discord.js databases to use - discord.js

I'm coding my first discord bot and I need some help in knowing which database would fit for this job so far I have tried saving my needed data in a json file but encountered some issues and heard some say that it's a bad practice my bot is a virtual food delivery bot which I used to store data like this in the json file
{
"001": {
"guildID": "some data here",
"customer": "some data here",
"order details": "some data here"
}
}
usually these data get deleted after an "order" is delivered so I don't think I would need a big database?
any suggestions for better ways to store these data?

Yes, JSON is a poor choice for a database. According to the Discord.JS maintainers:
"JSON files are prone to corruption when written to and read from a lot, which is why they should not be used as a form of database"
The Discord.JS guide includes 2 tutorials on setting up databases using Keyv or Sequalize.

Related

Converting CSV to JSON to send POST From React to Flask API

I am attempting to send a POST request to my API from my React app and am figuring out how to change a CSV from input to JSON format so no downloading needs to take place. I have seen people use Papaparse but from what I saw was that it hadn't been updated in a while so I am looking for other options.
const handleSubmit = async (event) => {
event.preventDefault();// from elements property
console.log(event.target.returns.value)
console.log(await axios.post('http://127.0.0.1:5000/ratios', event.target.returns.value))
setShow(true)
};
If I just send like this I get a 500 error and the first line of my POST function on Flask is
df = request.get_json()
maybe there's an easier way but let me know if you have any insight or advice. Thank you in advance
Your question is somewhat confusing and I think it's due to your understanding of how csv and json would interact. CSV is essentially a way to send tables of data, it doesn't have an inherent key pair structure so you need to do a little work to convert it. I'm not familiar with flask specifically but it looks like df = request.get_json() is trying to parse what it expects to be json but is instead csv. You are right that you need to convert that. Papaparse seems like an excellent option and is still under active development. However I don't think that really matters since csv and json are formats that haven't changed in a long time so the task of converting them hasn't changed. So whether or not there has been recent development doesn't matter.
If you decided to roll your own you could probably get close by taking each row and turning that into an object then matching each row entry with a first row key label or just with saved constants. Depend on how your csvs are structured.

send all messages to a specific channel in discord js

I started coding my discord bot, and have just tried adding a feature that logs specific raw events to a specific channel. I looked countless times on Reddit and this site to try and find a way that isn't deprecated, but no luck. I was hoping that I would answer on this website. To summarize, I need to send messages to a specific channel. Another thing is pulling information from things inside JSON files that look like this:
info.json: {t: 'PRESCENCE_UPDATE,
{other_thing_i_want_to_get: 'blah blah blah'}}
how do I get the other thing with a format of info.t.other_thing_i_want_to_get, or something like that?
i would recommend creating a json file and importing it.
using the npm module fs you can create WriteFileStreams to change the values stored in the file
const info = require('./path_to_json/info.json');
your json will have to look like:
{t: 'PRESCENCE_UPDATE', other_thing_i_want_to_get: 'blah blah blah'}
with this code you can get it using info.other_thing_i_want_to_get

Is there a way to live copy a channel chat from one server to another?

I am trying to create a spreadsheet for a World of Warcraft community, based on certain posts/events happening where we #tag the involved people. We would then normally go to our excel sheet and enter manually the names of the participants and all the rest of the details.
I have been trying to do it with Zapier, and i managed to fix all my rules/steps, but the moment i #tag anyone, the text sent/parsed is " !185020918530048000> " instead of "Loco-Silvermoon" for example.
Please help, any insight would be most welcome.
Anyone got an idea about that? or any Bot/Platform that would work around that? My thought process took me two solutions. Either get a bot to replicate all the chat happening on that channel to another private channel that only i can see and where tagging is not allowed (no idea if that exists or work). OR, get a Bot with a plaintext option that would just send me the text instead of the tagtext.

How do identify why certain documents are returned in SOLR response that may not be relevant for given keyword search?

We see certain documents in WCS SOLR response that are not relevant for given search keyword, but are part of the current customer/site catalog and categories. I do see SOLR debugging information, parser queries, filters, etc.. but trying to know if it's possible to know why a document was included in the response. I do see explain string and haven't spent time understanding whole algorithm behind it, would like to see if there is a quick way of knowing why the document was in the result/response list. This may help identifying catalog/categories data structure issue or any bugs in our SOLR implementation.
Is it possible to see the debug information at each returned document level in the response, if that helps understanding how SOLR is configured and working in the environment?
Thanks,
When you pass debugQuery=true in the request you can see in the debug/explain node of the response the reason for the score of each document. The information will look more or less like this:
...
"debug": {
...
"explain": {
"id:1": "info about the score for document 1",
"id:2": "info about the score for document 2",
"id:3": "info about the score for document 2",
"id:4": "info about the score for document 4",
...
}
}
The information is not exactly easy to parse and decipher but it might be a good place to start.
I explain in this blog post more about how to read the information in the explain section: https://library.brown.edu/DigitalTechnologies/understanding-scoring-of-documents-in-solr/

Google Structured Data Testing Tool not validating on first load

I'm using Google's Structured Data Testing Tool to investigate why Google isn't finding any structured data on my page.
On first loading the URL (https://www.languagesunited.co.uk), I get an "Uncategorised Error":
JSON-LD Missing '}' or object member name.
Within the test tool source windows, I can making a small change to the page (add a space somewhere) and re-run the validation, and it validates (except for the url needing to be www.example.com for the tool to work).
I'd be grateful for any advice if anyone has had a similar problem.
After some experimenting with different options and getting different results with the test tool, the answer was very simple. There were some invalid whitespace characters in my structured data. Switching on the "show invisibles" option in my editor allowed me to replace these with spaces, and the data validated successfully.
Both are, most likely, bugs in the SDTT.
If you paste the markup (instead of letting it fetch the URL), the SDTT detects the structured data immediately (letting it fetch first and then editing something in the detected markup is the same idea). So there’s probably something wrong with their URL fetching.
For the issue with the example domain, see these questions:
Google structured data error: “All values provided for http://www.example.com/ must have the same domain.”
Google SDTT error: “All values provided for http://www.example.com/ must have the same domain.”
Schema.org and ContactPoint use with validation failure: “All values provided for http://www.example.com/ must have the same domain.” (on Webmasters SE)
I've just realized that Google Structured Data Validation Tool requires you (or us) to include context, In example:
'#context': 'https://schema.org',
(schema.org includes it in all their examples, i.e.:
Example encoded as JSON-LD in a HTML script tag.
<script type="application/ld+json">
{
"#context": "https://schema.org/",
"#type": "Person",
"name": "Christopher Froome",
"sponsor":
{
"#type": "Organization",
"name": "Sky",
"url": "http://www.skysports.com/"
}
}
</script>
If you do so you will start getting results again.

Resources