I would like to format the text in my discord bot's message, but unfortunately it doesn't work:
var string = "```Questionnaire\n${topic}```";
${topic} - can't topic, but only it works:
var string = Questionnaire\n${topic};
My problem is that i can't enter the text into the table, i want to get topic in box (```)
var string = "```Questionnaire\n${topic}```"; // this don't work
This should do it:
var topic = "in the box";
var string = `\`\`\`
Questionnaire
${topic}
\`\`\``;
Related
I am trying to create a function that takes form response data and applies it to a template to create a 'completion certificate' with their total scores, then emails them a link to it.
On the certificate, their answers are split into four groups, but I am having trouble creating totals for the each of the answer arrays.
Here is my current code:
function autoFillGoogleDocFromForm(e) {
var timestamp = e.values[0];
var firstName = e.values[1];
var lastName = e.values[2];
var emailAddress = e.values[3];
var disbeliefScore = e.values[4,5,6,7,8].reduce((a, b) => a + b, 0);
var discomfortScore = e.values[9,10,11,12,13].reduce((a, b) => a + b, 0);
var explorationScore = e.values[14,15,16,17,18].reduce((a, b) => a + b, 0);
var acceptanceScore = e.values[19,20,21,22,23].reduce((a, b) => a + b, 0);
var file = DriveApp.getFileById("fileIdGoesHere");
var folder = DriveApp.getFolderById("FolderIdGoesHere")
var copy = file.makeCopy(lastName + ',' + firstName, folder);
var doc = DocumentApp.openById(copy.getId());
var body = doc.getBody();
body.replaceText("{{disbeliefscore}}", disbeliefScore);
body.replaceText("{{discomfortscore}}", discomfortScore);
body.replaceText("{{explorationscore}}", explorationScore);
body.replaceText("{{acceptancescore}}", acceptanceScore);
doc.saveAndClose();
var url = doc.getUrl();
MailApp.sendEmail(emailAddress, "Your Leading Change Questionnaire Results Link",{from:"alternative email address to go here", name:"Alternative Name to go here"},url)
}
The code mostly works (replacing text and sending the email), but the replaced text only seems to be the first value of the group, rather than the total.
For example this section:
var disbeliefScore = e.values[4,5,6,7,8].reduce((a, b) => a + b, 0);
is essentially behaving as:
var disbeliefScore = e.values[4];
and ignores the other values and the 'reduce' script.
As a side note, although the emails are being sent, the subject line of the email is coming out as [object Object].
Any help on either of these issues would be appreciated.
Thanks
Issue:
The syntax Array[index] can be used to access a single element in the array. You cannot select multiple indexes from an array by using:
e.values[4,5,6,7,8]
Solution:
In order to retrieve a chunk of the array, use slice:
e.values.slice(4,9)
Reference:
Array
How do I get the text from the li tag? I want to find the text "Password is required." only, not the text inside strong tag.
<li><strong>Error:</strong> Password is required.</li>
You need to show your code for somebody to give a complete answer. I guess that you already know how to do something like the following
WebElement something = driver.FindElement(By.CssSelector(?))
string s = something.Text;
The next bit seems to be where you are stuck. There you need to parse the string s. That is nothing to do with Selenium-Webdriver. You could do something like
string[] s2 = s.split(new string[] {">","<"});
were the last element in s2 would be your answer here. This would be totally non generic though. Is this a situation in which you always want to purge html?
Here is the method developed in python.
def get_text_exclude_children(element):
return driver.execute_script(
"""
var parent = arguments[0];
var child = parent.firstChild;
var textValue = "";
while(child) {
if (child.nodeType === Node.TEXT_NODE)
textValue += child.textContent;
child = child.nextSibling;
}
return textValue;""",
element).strip()
How to use in this:
liElement = driver.find_element_by_xpath("//li")
liOnlyText = get_text_exclude_children(liElement)
print(liOnlyText)
Please use your possible strategy to get the element, this method need an element from which you need the text (without children text).
I have a strange error occurring in an Apps Script function attached to a Google Form.
I call the responses, then list them in an array. The log shows that there are 6 items in the array, which matches the six form questions:
[18-05-08 00:13:31:900 AEST] [ItemResponse, ItemResponse, ItemResponse, ItemResponse, ItemResponse, ItemResponse]
When I call the first two, it works just fine. Any more and it bugs out and says undefined.
// Open a form by ID and log the responses to each question.
var form = FormApp.getActiveForm();
var formResponses = form.getResponses();
for (var i = 0; i < formResponses.length; i++) {
var formResponse = formResponses[i];
var editUrl = String(formResponse.getEditResponseUrl());
var theResponseId = formResponses.indexOf(form);
var itemResponses = formResponse.getItemResponses();
var timestamp = formResponse.getTimestamp();
var firstName = itemResponses[0].getResponse();
var lastName = itemResponses[1].getResponse();
Logger.log(itemResponses); // Log shows there are 6 objects in the array. Matching the amount of Form Questions.
// If I try to use these variables below, it doesn't work and the script 'breaks' at this point.
//var number = itemResponses[2].getResponse();
//var email = itemResponses[3].getResponse();
//var firstName2 = itemResponses[4].getResponse();
//var comments = itemResponses[5].getResponse();
}
Note: I have tried FormApp.openById('id'); to see if maybe getting the active form was a problem. This didn't help.
This is because some answers were submitted to a 2 question form. If you submitted some responses prior to updating the form, the answers to these new questions will be "undefined".
How do I get the full message and not just the metadata using gmail api?
I have a service account and I am able to retrieve a message but only in the metadata, raw and minimal formats. How do I retrieve the full message in the full format? The following code works fine
var request = service.Users.Messages.Get(userId, messageId);
request.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Metadata;
Message message = request.Execute();
However, when I omit the format (hence I use the default format which is FULL) or I change the format to UsersResource.MessagesResource.GetRequest.FormatEnum.Full
I get the error: Metadata scope doesn't allow format FULL
I have included the following scopes:
https://www.googleapis.com/auth/gmail.readonly,
https://www.googleapis.com/auth/gmail.metadata,
https://www.googleapis.com/auth/gmail.modify,
https://mail.google.com/
How do I get the full message?
I had to remove the scope for the metadata to be able to get the full message format.
The user from the SO post have the same error.
Try this out first.
Go to https://security.google.com/settings/security/permissions
Choose the app you are working with.
Click Remove > OK
Next time, just request exactly which permissions you need.
Another thing, try to use gmailMessage.payload.parts[0].body.dataand to decode it into readable text, do the following from the SO post:
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.StringUtils;
System.out.println(StringUtils.newStringUtf8(Base64.decodeBase64(gmailMessage.payload.parts[0].body.data)));
You can also check this for further reference.
try something like this
public String getMessage(string user_id, string message_id)
{
Message temp =service.Users.Messages.Get(user_id,message_id).Execute();
var parts = temp.Payload.Parts;
string s = "";
foreach (var part in parts) {
byte[] data = FromBase64ForUrlString(part.Body.Data);
s += Encoding.UTF8.GetString(data);
}
return s
}
public static byte[] FromBase64ForUrlString(string base64ForUrlInput)
{
int padChars = (base64ForUrlInput.Length % 4) == 0 ? 0 : (4 - (base64ForUrlInput.Length % 4));
StringBuilder result = new StringBuilder(base64ForUrlInput, base64ForUrlInput.Length + padChars);
result.Append(String.Empty.PadRight(padChars, '='));
result.Replace('-', '+');
result.Replace('_', '/');
return Convert.FromBase64String(result.ToString());
}
I'm not overly sure if this is possible, as I am not a frequent programmer, but I have a question.
I've got an array that generates one random word in a text box and then a second array that generates another random word in a different text box. What I want is for when a certain word out of array number one is generated, a certain image appears with it. Here's the code:
var firstChoice:Array = ["Do this", "Do that", "Do something else"];
var secondOption:Array = ["while doing this", "while doing that", "while doing something else"];
generate_btn.addEventListener(MouseEvent.CLICK, getTask);
function getTask(event:MouseEvent):void {
var randomChoice:Number = Math.floor(Math.random() * firstChoice.length);
var randomOption:Number = Math.floor(Math.random() * secondOption.length);
Final_Choice.text = firstChoice[randomChoice];
Final_Option.text = secondOption[randomOption];
}
So for instance, when I click the button and the first array generates "Do this," I want a specific graphic to appear with it.
Hopefully this is possible :/ I'm stumped!
probably you need to use a HashMap, such as:
var map:Object = new Object();
map.first_choice = /*url of your image associated with this choice*/
map.second_choice = /*url of your image associated with this choice*/
//etc
and when a word is generated, you just compare the word with keys of the map, using a foreach, and get the url of your image