PGamerX-Legacy / muser

Muser: A powerful Discord music bot made in DJs v13 managed by PGamerX, Peiprjs, and Luckie.
https://muser.pgamerx.com
GNU Affero General Public License v3.0
63 stars 12 forks source link

v4 Improvements #22

Closed sachin-sankar closed 3 years ago

sachin-sankar commented 3 years ago

RSA is a great API but it can be better. Here are a few in depth suggestions from a fellow user to improve it a lot. These mainly focus on the response of endpoints.

Jokes Endpoint

The jokes endpoint is a literal joke. Here are a few changes.

Suggestion:

The current endpoint v3/joke/:type does not allow the user to define what type of joke they need(Two part,single) Therefore user should be able to define to the endpoint as a header value. Here is a example

Getting a non nsfw single joke

headers = {"type":"single","nsfw":"False"}
Two part type
{'error':  False,
'category':  'Misc',
'type':  'twopart',
'setup':  'I won the lottery today!',
'delivery':  'Well, I only got the first two numbers, but my lawyers are working on having them stop the count.',
'flags':  {'nsfw':  False,
           'religious':  False,
           'political':  True,
           'racist':  False,
           'sexist':  False,
           'explicit':  False},
'id':  258,
'safe':  False,
'lang':  'en'}
Single
{'error':  False,
'category':  'Pun',
'type':  'single',
'joke':  'A horse walks into a bar.\n"Hey", the Bartender says.\n"Sure", the horse replies.',
'flags':  {'nsfw':  False,
           'religious':  False,
           'political':  False,
           'racist':  False,
           'sexist':  False,
           'explicit':  False}
           'id':  74,
           'safe':  True,
'lang':  'en'}

The thing about the response is that it contains data that are not necessary. The current response that you saw above is around 310 bytes for the single type. The solution is to remove them from the response.

Data to remove and why:

The flags provide information about the joke but it has nothing to do with the client as the user has already specified his needs and dose not needs to verify them assuming the API returns the correct type. Even if needed the tag nsfw can be retained and safe tag removed as both mean the same thus allowing the user to use the data to verify or else display the data in front end.

Response after all removals and improvments:

['category':  'Pun',
'joke':  'A horse walks into a bar.\n"Hey", the Bartender says.\n"Sure", the horse replies.',
'nsfw':'true',
'lang':  'en'}]

This brings the size of the response down to 142 bytes. This greatly improves the api's response time and its CPU and ram usage.

AI response

The current endpoint returns the following response,

[{
"success": True,
"message": "message",
"api_key": "your_key"
}]

Response after change:

['message']

The AI response endpoint is the most used one these changes allow it to use less CPU and ram preventing outages and quota issues.

izxxr commented 3 years ago

I strongly disagree with the removal of ID. ID is a very useful thing. Every joke has an unique ID which if could be added, can be used to get a certain joke. I do agree with the customisation of the joke endpoint but don't remove ID.

izxxr commented 3 years ago

...even though you suggest the addition of custom flags which of course would be great, I don't think so the flags should be removed from response. Also, instead of headers custom jokes attributes can be passed as JSON (or dictionary) in paramaters.

sachin-sankar commented 3 years ago

...even though you suggest the addition of custom flags which of course would be great, I don't think so the flags should be removed from response. Also, instead of headers custom jokes attributes can be passed as JSON (or dictionary) in paramaters.

It is indeed sent as that. @nerdguyahmad

sachin-sankar commented 3 years ago

I strongly disagree with the removal of ID. ID is a very useful thing. Every joke has an unique ID which if could be added, can be used to get a certain joke. I do agree with the customization of the joke endpoint but don't remove ID.

Currently you can't get a joke by id and if it was then it would be consuming more resources @nerdguyahmad

sachin-sankar commented 3 years ago

...even though you suggest the addition of custom flags which of course would be great, I don't think so the flags should be removed from response. Also, instead of headers custom jokes attributes can be passed as JSON (or dictionary) in paramaters.

There is no use for flags. So it is redundant @nerdguyahmad

izxxr commented 3 years ago

I strongly disagree with the removal of ID. ID is a very useful thing. Every joke has an unique ID which if could be added, can be used to get a certain joke. I do agree with the customization of the joke endpoint but don't remove ID.

Currently you can't get a joke by id and if it was then it would be consuming more resources @nerdguyahmad

Personal preference: I don't think so, It is very useful to get a certain joke (I know you cannot get certain joke at the moment but this can be added) and this'd be very useful.

izxxr commented 3 years ago

...even though you suggest the addition of custom flags which of course would be great, I don't think so the flags should be removed from response. Also, instead of headers custom jokes attributes can be passed as JSON (or dictionary) in paramaters.

There is no use for flags. So it is redundant @nerdguyahmad

Though customisation can be added, The ability to get the completely random joke shouldn't be removed. So, flags can be helpful in that case.

sachin-sankar commented 3 years ago

...even though you suggest the addition of custom flags which of course would be great, I don't think so the flags should be removed from response. Also, instead of headers custom jokes attributes can be passed as JSON (or dictionary) in paramaters.

There is no use for flags. So it is redundant @nerdguyahmad

Though customisation can be added, The ability to get the completely random joke shouldn't be removed. So, flags can be helpful in that case.

What is the use of them? @nerdguyahmad

izxxr commented 3 years ago

...even though you suggest the addition of custom flags which of course would be great, I don't think so the flags should be removed from response. Also, instead of headers custom jokes attributes can be passed as JSON (or dictionary) in paramaters.

There is no use for flags. So it is redundant @nerdguyahmad

Though customisation can be added, The ability to get the completely random joke shouldn't be removed. So, flags can be helpful in that case.

What is the use of them? @nerdguyahmad

To of course tell the user that what type of joke they got (in random joke).

pgamerx commented 3 years ago

Hey @nerdguyahmad and @Creepy-Creeper3625
Kindly see https://github.com/pgamerxdev/projects/issues/23

sachin-sankar commented 3 years ago

@nerdguyahmad if #23 comes to action then flags might be irrelevant as the user will set what he needs using flags filter

sachin-sankar commented 3 years ago

Hey @nerdguyahmad and @Creepy-Creeper3625 Kindly see #23

Great also add our suggestions about responses. @pgamerxdev

pgamerx commented 3 years ago

Hey @nerdguyahmad and @Creepy-Creeper3625 Kindly see #23

Great also add our suggestions about responses. @pgamerxdev

Which suggestion?

sachin-sankar commented 3 years ago

Hey @nerdguyahmad and @Creepy-Creeper3625 Kindly see #23

Great also add our suggestions about responses. @pgamerxdev

Which suggestion?

about the ai responce and joke responce

pgamerx commented 3 years ago

Hey @nerdguyahmad and @Creepy-Creeper3625 Kindly see #23

Great also add our suggestions about responses. @pgamerxdev

Which suggestion?

about the ai responce and joke responce

I don't see any suggestions for AI response tho

sachin-sankar commented 3 years ago

@pgamerxdev It is under Ai Response

pgamerx commented 3 years ago

@pgamerxdev It is under Ai Response

Check version 4

sachin-sankar commented 3 years ago

@pgamerxdev I don’t see anything related to api response there in #23

pgamerx commented 3 years ago

@pgamerxdev I don’t see anything related to api response there in #23

What was your suggestion? I removed the api key from the response

sachin-sankar commented 3 years ago

Good then