I'm working on a whois slash command for a Discord Bot and I want to display the tag for the user selected within a command block but if I use " or ' for the value of the field on the embed, the variable doesn't work therefore I have to use `. The issue with this is, I can't see a way to show the text outputted by the variable as a code block.
My code:
.addFields(
{ name: '__User Information__', value: `**Name:** ${user.tag}\n <:Spacer:1064084066997129277> • Mention: ${user}`, inline:false},
)
You can escape a backtick like so: \`,
So, if you want to add codeblocks inside your embed you can do:
`Example codeblock: \`\`\`This is a codeblock! ${variable}\`\`\``
Here's an example from my bot, which displays the user id and message id inside a codeblock:
`\`\`\`ini\nUser = ${message.member.id}\nID = ${message.id}\`\`\``
The code above roughly translates to:
```ini
User = ${message.member.id}
ID = ${message.id}
```
You can read more about template literals here
Related
so i have this block of sql query code here for sending user description to db in node js.
const sqlAddDescription = (desc, id) => {return `UPDATE \`Memcon\`.\`users_list\` SET \`description\` = '${desc}' WHERE (\`id\` = '${id}')`}
it's working completely fine, in the client user inputs a text and the db process goes on with no problem.
BUT if the user sends an input with backticks or quotes or even brackets, the process gonna fail because their text head on goes to ${desc} and it replaces it, so it creates an error.
How can i tell js to fully stringify the text, no matter the inputs.
(i also tried JSON.stringify but that serves a different purpose )
I am using library Notify js for showing success or error messages on my php web page.
When I use normal text like
$.notify("Changes are made successfully", "success");
Then it works fine.
But sometimes, I need to show message in unordered list like as follows:
var message = '<p> Please correct following errors and then try again </p><ul><li>value1 is wrong</li><li>value 3 is wrong</li><li>value 5 is wrong</li></ul>';
$.notify(message, "error");
Then message is shown as it is, means whole html is displaying, instead I want to display like
Please correct following errors and then try again
- value1 is wrong
- value3 is wrong
- value5 is wrong
Any suggestion would be highly appreciated!
you can add an own Class with the HTML Content like a Template System.
$.notify.addStyle('saved', {
html:
"<p>Saved blabla...</p>"
});
$.notify(..., {
style: 'saved'
});
Other two ways (beside the utterly noisy addStyle method)
Use \n newline escape character
use \n and expect <br>! Therefore instead of using UL > LI use just some combination of newline escapes \n like:
Store your possible errors inside an Array and than simply use then inside the Notify mesage:
const errors = [ // Or however you can push() errors into this array...
"value 1 is wrong",
"value 2 is wrong",
"value 3 is wrong",
];
// Add dashs "-" to each error and join with newline
const errorsList = errors.map(err => ` - ${err}`).join("\n");
const message = `Please correct following errors and then try again\n\n${errors.join("\n")}`;
$.notify(message, "error");
which will result in:
Please correct following errors and then try again
- value 1 is wrong
- value 2 is wrong
- value 3 is wrong
Modify the plugin source
A simple edit to the source code to allow for HTML is:
at line 205 add to the pluginOptions:
encode: true,
at line 513 change d = encode(d); to be:
if (this.options.encode) {
d = encode(d);
}
Finally, when you use the plugin simply set the new Option encode to false:
// Use like:
$.notify("Lorem<br><b>Ipsum</b>", {encode: false});
Here's my pull request related to this Issue#130
So I'm trying to open a new window by executing a script in Selenium using driver.execute_script("window.open('');")
But I want to open a link given by the user.
So I got the link input from my array and put it to my javascript code just like this:
driver.execute_script("window.open(data[0]);")
Now It's giving an error like this:
selenium.common.exceptions.JavascriptException: Message: javascript error: data is not defined
How to fix this? Thanks for your time.
EDIT: A part of my code is something like that:
from selenium import webdriver
import PySimpleGUI as sg
import time
global data
data = []
layouts = [[[sg.Text("Enter the Wordpress New Post link: "), sg.InputText(key=0)]],
[sg.Button('Start The Process'), [sg.Button('Exit')]]]
window = sg.Window("Title", layouts)
def selenium_process():
# Getting the driver path
driver = webdriver.Chrome(r'Driver\path')
driver.get('https://google.com')
driver.execute_script(f"window.open({data[0]});")
time.sleep(10000)
while True:
event, values = window.read()
if event in (sg.WIN_CLOSED, 'Exit'):
break
data.append(values[0])
selenium_process()
did you try string interpolation ?
Try this:
driver.execute_script(f"window.open({data[0]});")
Your solution does not work since data[0] is a string, not a variable. You instead need to substitute data[0] with its value (must be a value that JS can understand).
Please read the description of Javascript window.open : https://developer.mozilla.org/fr/docs/Web/API/Window/open
If you just need to get to an URL:
driver.get(data[0])
I am making a Tags System on my Discord Bot with Discord.JS. Basically with Tags, you start by adding a tag with the name and content. Once added, running the tag command will return the content of the Tag. Theres other Tag Commands such as Tag Info (To get Tag Info), Tag list, edit tag etc.
I am experiencing issues with my Add Tag Command. Basically, what I am trying to do is add a line of code which is to check if the Tag Name already Exists. However, whenever I run the Add Command 2nd time or more with the same Tag Name, it will just override the name.
I've tried with this line of code:
let tags = await db.fetch(`tags_${message.guild.id}-${name}.name`)
if(!tags) return message.channel.send(`**Tags |** **Tag Exists!**`)
This should return a message response if the same Tag Name exists in the Guild But it is not working as expected.
For other Tag Commands I have, they kept getting Cannot read property 'content' of null error but I've somewhat resolved this with this snippet of code that uses the Try and Catch Statements.
} catch (e){
if (e.message === "Cannot read property 'content' of null")
return message.channel.send(`**Tag Not Found**`)
The Tags System uses Quick.DB for Database storing. It wasn't easy to get this all working right. I have an API Debug JSON Link that i've used to try and diagnose the problems. https://nate-devbot.glitch.me/api/coinslb
Please only look at JSON Formats like this:
The other data entries are old and were resolved earlier.
The full code to AddTag.JS: https://hastebin.com/neqasomisa.js
I'm trying to detect if I get the expect response from a text message. so I need to access the text view of the received text. the problem I'm having is I cant figure out a way to let the driver know I need the received text rather than the sent text.
this first image of the ui selector shows that the sent text is highlighted here it shows the id, class, package, and resourse-id (which is out of frame)
in the second image of the ui selector shows that the received text is highlighted here it shows the id, class(out of frame), package, and resourse-id (which is out of frame)
all the attributes values match expect for the text value. how can i let appium know which one i need to check?
i was thinking something that accessed a element within another element, code id assume would be something like this:
await driver.waitForElementById('com.android.mms:id/msg_list_item_recv', 30000, function (err, data) {})
.elementById('com.android.mms:id/text_view', function (err, data){})
.textPresent('key text value', function (err, data) {});
Any help would be greatly appreciated.
If you can ask developers to update id of send text it will be best to do this, as currently there is same id for sent and received text . If this is not possible you can try this .
#FindBy(id = "com.android.mms:id/text_view")
private List<WebElement> messagelist;
for (int i=0;i<messagelist.size();i++)
{
if(messagelist.get(i).gettext().contentEquals("sendtext"))
{
// then i+1 is your received text
messagelist.get(i+1).gettext().contentEquals("recievedText")
}
}
What you can do to detect if message is received (left) or sent (right) is to compare with their bounds...
For my example I will use these two bounds:
Received message
Sent message
In Xpath with my example could be:
"//android.widget.TextView[#resource-id='com.android.mms:id/msg_list_item_recv' and contains(#bounds, '[163,')]"
If you have an element at [163,100][100,100] everything will be ok. But... The problem with this method is that if you have an element at [100,100][163,100] it will detect it as received when is not... So the next method could be better because there is no option...
Another way to get just left messages could be:
"//android.widget.TextView[#resource-id='com.android.mms:id/msg_list_item_recv' and not(contains(#bounds, '][942,'))]"
In the other hand this will return any textview that NOT contains "][942," so there can not be mistakes
Let me know if worked. I do it this way to know it.