How to make insult command(discord.py) - api

i'm making an insult command,its making a JSONDecode Error
any solution...
#client.command(pass_context=True)
async def insult(ctx):
async with aiohttp.ClientSession() as session:
request = await session.get('https://evilinsult.com/generate_insult.php?lang=en&type=json')
insultjson = await request.json(content_type='text/html')
await ctx.send(url=insultjson['insult'])

The problem is most probably the link. Instead of &, just use &.
Plus, they seem to have a plain text option too - replace type=json with type=text in the same link and you should be able to use it without having to deal with JSON at all. Check out evilinsult.com's GitHub repo
Also, please always paste your exact errors - it helps us give you a better answer.

Related

Redis: Cannot perform full-text search operations

I got error saying "ReplyError: Car:index: no such index". I am indexing by "description". As you can see on the terminal part contains all the needed info and I am not sure what is causing the problem. Help is welcome.
I've been trying to follow Fireship tutorial on Redis, copied his code https://fireship.io/lessons/redis-nextjs/
In Redis-om version 0.3.6, you can add following code in your API:
export async function createIndex() {
await connect();
const repository = client.fetchRepository(schema);
await repository.createIndex();
}
And Also ensure you only create index once ONLY.
It will work after you created an index.
As Guy Royse mentioned in the comments - The problem is solved by calling createIndex API.

Looking for a "legit" way to be able to log a Selector's function chain

I find that I often want to be able to log out what a Selector was looking for at various times during execution. I couldn't find a "legit" way to do this so I worked around it by creating the following function:
function printSelector(selector) {
console.log(selector[Object.getOwnPropertySymbols(selector)[0]].options.apiFnChain.join(""));
}
// And with this, if you have something like:
let mySelector = Selector('button').withText('foo').with({ visibilityCheck: true });
// You can run:
printSelector(mySelector);
// and get: Selector('button').withText('foo').with({ visibilityCheck: true })
My question is: is there some better way that doesn't require using the internal apiFnChain to find / log this info?
Thanks
TestCafe does not allow you to log Selectors if there were no Selector errors. However, the approach we use is similar to yours.
You can continue using your approach. However, please note that this is private API and it can be changed in the future.

What is the equivalent for Auth.updateUserAttributes in amplify_auth_cognito

Link 1.
What is the equivalent for
const user = await Auth.currentAuthenticatedUser();
const result = await Auth.updateUserAttributes(user, {
'custom:favorite_flavor': 'Strawberry'
});
in Flutter
amplify_core: '<1.0.0'
amplify_auth_cognito: '<1.0.0'
Took a look and found the simple answer that the exact copy over does not exists as i'm sure you have realized at this point.
The link:
https://docs.amplify.aws/lib/auth/manageusers/q/platform/js/ will fail to give you any comparable Flutter etc... pages & if you try it will return "Flutter is not supported on this page. Please select one of the following: Javascript."
Unfortunately, Javascript is not supported in android/IOS though there was some stuff out there to partially work with it https://medium.com/flutter-community/using-javascript-code-in-flutter-web-903de54a2000.
Hopefully this answer will become obsolete over time as more work is put into the needed functionality.

Problem with Prefix in Discord.js (including .toUpperCase())

Basically, I've been developing a bot for several weeks now using the discord.js library and recently encountered a small but crucial issue. Essentially when I declare my argument, I also made it so that the message content (message.content) would be capitalized using .toUpperCase(). Essentially in doing so regardless of the type of prefix you would enter (symbol wise) it would all be read by the program as valid.
For example only: !help - should work, however if I would enter .help, it would also be read as valid.
In any case, here's the code. I appreciate all the help!
bot.on('message', message =>{
let args = message.content.toUpperCase().substring(PREFIX.length).split(" ");
const sender = message.member;
switch(args[0])
{
case 'HELP':
message.reply("I've sent you some documentation on all the commands that you can use...").then(d_msg => {d_msg.delete(3000); });
message.delete(3000);
const attachment = new Attachment('./UtilityBot_Documentation.txt')
message.author.send('[Education] Bot - Documentation');
message.author.send(attachment);
break;
}
})
The discord.js tutorial covers an extremely similar problem to what you're trying to do. I recommend you check it out. The page I linked in specific is doing a very similar thing to you, but it's worth giving the whole thing a read through if you haven't done so already. In general, I would include the following line just above where you established args.
if (!message.content.startsWith(PREFIX)) return;
What I'm doing here is saying if the message does not start with the prefix, stop running until a new message is sent. I might be missing something, but certainly check out the tutorial. It's really well written.
https://discordjs.guide/creating-your-bot/commands-with-user-input.html#basic-arguments

Sending arrays as query parameters to express does not work

I think that one should be able to send a url like this to express:
/?some_arr[]=1&some_arr[]=2
and get in req.query: {some_arr: ['1','2']}
but I tried it and I get: {some_arr: '2'}
Is this how it is supposed to be? What can be wrong? Is there any config settings to enable the array feature?
This is in an existing, large project. Could this have been turned off in some way?
I found out that the project since earlier had the line app.use(hpp()); which apparently is a package to explicitly remove the array feature...
do something like that-
/?some_arr=1&some_arr=2
and now on your express code-
app.get('/', function(req, res, next) {
console.log(req.query) //
res.send(200)
}