javascript – Discord.js removes permission from certain roles to send messages in a channel

discussionChannel.rolePermissions (& # 39; 590449138093522955 & # 39;). add (& # 39; SEND_MESSAGES: true & # 39;)
AND
discussionChannel.rolePermissions (& # 39; 590449138093522955 & # 39;). remove (& # 39; SEND_MESSAGES: true & # 39;)

send error: RangeError: invalid string or authorization number.

discussionChannel is a valid text channel. It's literally all that I know. For some reason, getting permissions for a role and then trying to change whether or not it can send messages does not work.

javascript – Use a setTimeout to jump

I'm trying to create a jump function.

I am doing a html5 canvas game with Javascript. I forced the player to move. When creating the jump function, I decided to use an expiration time to reverse the original coordinates after a while.

The error occurs after the character has risen, he does not return to the original position, he remains there, then, by clicking on the jump (arrow key), the player moves again, for example (below);

class character {

class character {
Constructor () {
this.x = 50;
this.y = 400;
this.posX = 0;
this.posY = 0;
this.width;
this height;
this.hitPoints = 1;
this.directionFace = "right";
this.jump = false;
this.jumpHeight = 23;
}

move (e) {

this.x + = this.posX;
this.y + = this.posY;

if (e.keyCode == 37) {
console.log (& # 39; left & # 39;);
this.posX - = 10;
}

otherwise if (e.keyCode == 38) {

console.log ("UP");

if (! this.jumping) {

this.posY - = this.jumpHeight;
this.jumping = true;

setTimeout (function () {
this.posY = this.jumpHeight;
this.jumping = false;
}, 500);
}
}

if not (e.keyCode == 39) {

console.log ("right");
this.posX + = 10;
}

e.preventDefault ();
}

html – JavaScript `localStorage` with the alternative` document.cookie` for static websites

The code

Until now, things have worked as desired and I hope that new eyes will be able to report any error or item that can be improved, a live demo is hosted and updated on GitHub Pages , and the source code is only one file. fork or clone a way….

BrowserStorage.js

BrowserStorage class {
/ **
* @this BrowserStorage
* /
constructor () {
this.supports_local_storage = this.supportsLocalStorage ();
this.supports_cookies = this.supportsCookies ();
this.storage_available = (this.supports_cookies || this.supports_local_storage)? right wrong;
}

/ **
* Note, use `this.supports_local_storage` instead in the tests.
* @returns {boolean}
* /
supportsLocalStorage () {
try {
let key = & # 39; test & # 39;
let value = true;
localStorage.setItem (key, value);
localStorage.getItem (key);
localStorage.removeItem (key);
} catch (e) {
returns false;
}
return true;
}

/ **
* Note, use `this.supports_cookies` instead in the tests.
* @returns {boolean}
* /
supportsCookies () {
if (navigator.cookieEnabled) returns true;

try {
document.cookie = & # 39; testcookie & # 39 ;;
} catch (e) {
returns false;
} finally {
if (document.cookie.indexOf (& # 39; testcookie & # 39;)! = -1) {
this.remove (& # 39; testcookie & # 39;);
return true;
}
returns false;
}
}

/ **
* Copy of the `constructor` method which should not come from a type error
* /
constructorRefresh () {
this.supports_local_storage = this.supportsLocalStorage ();
this.supports_cookies = this.supportsCookies ();
this.storage_available = (this.supports_cookies || this.supports_local_storage)? right wrong;
}

/ **
* Gets the specified value of browser storage and URI components when returning
* @returns {? boolean |? number |? string}
* @this BrowserStorage
* /
Get the key) {
let value = null;
if (this.supports_local_storage) {
value = localStorage.getItem (key);
} else if (this.supports_cookies) {
leave cookie_data = document.cookie.match (& # 39; (^ |;)? + key + & # 39; = ([^;]*) (; | $) & # 39;)
value = cookie_data? cookie_data[2] : no;
}
returns encodeURIComponent (value);
}

/ **
* Removes the value selected by key from the browser storage; note for cookies, _full whipe_ will be displayed when loading the next page
* @returns {boolean}
* @this BrowserStorage
* /
remove (key) {
if (this.supports_local_storage) {
localStorage.removeItem (key)
return true;
} else if (this.supports_cookies) {
// Note, how to disable and expire in the past
// to delete a cookie the next time the page loads.
this.set (key, -7);
return true;
}
returns false;
}

/ **
* Stores the client settings in the browser, _serverless_ in the real sense
* key @peram {string | number} - _name variable_to store the value under
* value @peram {boolean | number | string} - stored under localStorage or as a cookie
* @peram {number} days_to_live - how long is a browser suggested to keep cookies
* @returns {boolean}
* @this BrowserStorage
* /
set (key, value, days_to_live = false) {
if (this.supports_local_storage) {
localStorage.setItem (key, value);
return true;
} else if (this.supports_cookies) {
let expire = & # 39 ;;

if (days_to_live) {
let date = new Date ();
if (days_to_live == 0) {
date.setTime (date.getTime ());
} other {
date.setTime (date.getTime () + (days_to_live * 24 * 60 * 60 * 1000));
}
expires = & # 39 ;; expires = + date.toGMTString ();
}

document.cookie = name + & # 39; = & # 39; + value + expires + & # 39 ;; path = / & # 39 ;;
return true;
}
returns false;
}

/ **
* Clear ** all ** LocalStorage client or cookie settings
* @returns {boolean}
* @this BrowserStorage
* /
clear () {
if (this.supports_local_storage) {
localStorage.clear ();
return true;
} else if (this.supports_cookies) {
leave the cookies = document.cookie.split (& # 39 ;;);
for (ie i = 0; i <cookies.length; i ++) {
leave cookie = cookies[i];
let key = encodeURIComponent (cookie.split (& # 39; = & # 39;)[0].replace (/ (^  s + |  s + $) / g, & # 39;));
if (typeof (key) == <string> || typeof (key) == # number;) {
this.remove (key);
} other {
returns false;
}
}
return true;
}
returns false;
}

}

main.css

/ **
* 1. Central element
* 2. Re-justify the text
* /
body {
text-align: center; / * 1 * /
}

.container__main_content {
maximum width: 80%;
maximum width: 80vw;
display: inline-block; / * 1 * /
text-align: left; / * 2 * /
}

/ **
* Note on confidentiality
* /
.container__privacy_notice {
position: fixed;
bottom: 5px;
maximum width: 80%;
maximum width: 80vw;
background color: light gray;
text-align: left; / * 2 * /
}

.privacy_notice__label {
background color: black;
White color;
font size: 1.5rem;
upholstery: 5px 10px;
Float on the right;
}

.privacy_notice__label: hover {
color: light gray;
}

/ * Status of the label when the check box is unchecked * /
.privacy_notice__label :: after {
content: attr (value);
}


/ **
* Tweaks
* /
.hidden__input {
display: none;
visibility: hidden;
opacity: 0;
filter: alpha (opacity = 0);
}


/ * Status updates when the check box is checked * /
.privacy_notice__checkbox: verified ~ .container__privacy_notice {
box-shadow: not defined;
max-width: 1.5rem;
maximum height: 1.5rem;
}

.privacy_notice__checkbox: checked ~ .container__privacy_notice * {
visibility: hidden;
opacity: 0;
filter: alpha (opacity = 0);
}

.privacy_notice__checkbox: verified ~ .container__privacy_notice .privacy_notice__label :: after {
content: attr (verified);
}

/ * Status of the label when the checkbox is checked * /
.privacy_notice__checkbox: verified ~ .container__privacy_notice :: after {
content: & # 39;  1F56D & # 39;
position: absolute;
bottom: 5px;
left: 5px;
}

/ * List of verified and hovering updates * /
.privacy_notice__checkbox: verified ~ .container__privacy_notice: hover {
maximum width: 80%;
maximum width: 80vw;
maximum height: not defined;
}

.privacy_notice__checkbox: checked ~ .container__privacy_notice: hover * {
visibility: visible;
opacity: 1;
filter: alpha (opacity = 100);
}

index.html



  
    Example of BrowserStorage
    
    

    
    

    
  

  
    

It is a static site that gives the illusion of remembering a customer. Test by accepting privacy notice then refreshing or close and reopen a tab pointing to the current URL.

Ctrl R or Ctrl shift R will refresh most desktop browsers.

Then reject the privacy statement by clicking the Acceptable button again to reverse the behavior of this site.

use Ctrl shift I open the debugger on a desktop browser, and then go to the tab / pane Storage to observe JavaScript does things for the actions mentioned above.

This site uses JavaScript, and local storage or cookies from your browser, to improve your experience here, however, this site is currently doing do not store data about your server-side activity.

Review the Privacy and security notice concerning the BrowserStorage.js , for more details on using storage and client-side scripts.

Note, I have tried using the Web Code option when writing this question, but this has caused various errors.

Questions

My goal is to have 100% coverage for browsers using JavaScript and local storage or document.cookie storage options;

  • in this day n age is it useful to use cookies for local backup storage?

  • is it useful to use the old syntax to get the OO behavior of JavaScript or use the class and a function keywords are enough?

if there are good arguments for not using class, please include feature detection examples to load another version.

  • I keep running through nper but it seems to be more focused on node-related JavaScript, should I consider issuing npm init. or would it be pollute their parcel management system?

If such projects are a good candidate for nper, then some tips on agnostic publishing methods of the operating systems Git the orders would be excellent.

  • I am currently using encodeURIComponent when returning values ​​stored in the browser, however, this leads to unpredictable behavior with Boolean and numeric values ​​(sometimes a string, sometimes not), better way to recover values?

At this point, it seems almost necessary to do a pre-check before returning to get some consistency in behavior.

  • Where did I go wrong and / or how can I improve code execution without sacrificing readability?

  • One thing I find annoying to use checkbox hacks is accessibility, are there any well ways to get Tongue and Space/Enter support?


Thank you, and I hope that even though the above is me being a bad influence that we can all learn why together.

javascript – Propagation date in React

I'm learning to react recently, but I've had some problems with respect to propagating data from one component to the other. My general situation is: I have a textarea for entry, a shipment button and one textarea for the output – essentially a discussion interface. So I would like the user to enter the data in the first textarea then spread to the next textarea when the button is in a hurry. I got the result using four components:

//chatbox.js
import React to "react";
import {TextBubble} from "./TextBubble";

const = {
border: "2px solid gray",
width: "400px",
height: "300px",
marginTop: "50px",
hidden overflow ",
whiteSpace: "pre"
}

the Chatbox export class expands to React.Component {
render () {
return (
      

{} This.props.text

) } }
//InputBar.js
import React to "react";
import {TextEnter} from "./TextEnter.js";
import {SendButton} from "./SendButton.js";

The InputBar export class expands React.Component {
constructor (accessories) {
super (accessories);
this.state = {text: & # 39;
this.setTextInput = this.setTextInput.bind (this)
this.clickButton = this.clickButton.bind (this)
}
setTextInput (text) {
this.state.text = text
}
clickButton () {
this.props.setTextInput (this.state.text)
}
render () {
var inline = {
display: "flex"
}
return (
      
) } }
//SendButton.js
import React to "react";

The SendButton export class expands React.Component {
constructor (accessories) {
super (accessories);
this.handleClick = this.handleClick.bind (this);
}

handleClick () {
this.props.clickButton ()
}
render () {
var style = {
"background color": "marine",
"border": "none",
"White color",
"width": "50px",
"padding": "8px 0px",
"height": "40px",
"text-align": "center",
"text-decoration": "none",
"display": "inline-block",
"font-size": "16px",
}
return (
      
    )
}
}
//TextEnter.js
import React to "react";

const = {
border: "2px solid gray",
width: "350px",
height: "40px",
resize: "none"
}

The TextEnter export class expands to React.Component {
constructor (accessories) {
super (accessories);
this.state = {value: & # 39;
this.handleChange = this.handleChange.bind (this)
}
handleChange () {
this.setState ({value: event.target.value});
this.props.setTextInput (event.target.value)
}
render () {
return (
      
) } }

And in app.js, I've

import React to 'react';
import & # 39; ./ App.css & # 39 ;;

import {Chatbox} from "./components/Chatbox";
import {InputBar} from "./components/InputBar";

Export class App expands React.Component {
constructor (accessories) {
super (accessories);
this.state = {text: & # 39;
this.setTextInput = this.setTextInput.bind (this)
}
setTextInput (text) {
var currentText = this.state.text
if (currentText == & # 39;) {
var newText = text
} other {
var newText = currentText + & # 39;  n & # 39; + text
}
this.setState ({text: newText})
}
render () {
return (
      
) } }

The general strategy here, which I found in some blog posts, is to get the child-to-parent data by passing the child a function he calls each time an update is updated. , either the text of the changing zone or the push-button. This data can then be transmitted from the parent to the child via the accessories. My problem with this is that it seems to take a bunch of boiler plate code that I think can be somehow reduced, although I'm not sure how to do that.

javascript – Node js filter array with responsive form values

I have a problem with filtering array of form values.

I use angular 7 and express js

export function getItems (req: Request, res: Response) {
const itemCriteria: ItemCriteria = req.body.itemCriteria;
name const = (itemCriteria.name)? itemCriteria.name: & # 39 ;;
const description = (itemCriteria.description)?
itemCriteria.description: & # 39;
const category = itemCriteria.category;

const filterItems: Item[] = articles
.filter (item => item.category.id === category &&
item.name .includes (firstName) &&
item.description.includes (lastName)
)

res.status (200) .json (filterItems);
}

When I fill all the fields, filterItems is correct, but when I fill only one or two fields, the error message "Unable to read the property undefined". This field is reactive but only one is required, otherwise it is optional. My question is, how can I filter this correct table?

Javascript Memory Issues – Stack Exchange Webmasters

I am currently experiencing memory problems with my website. Once the page is open, Chrome uses approximately 270 MB of memory. After a while, it slips and starts generating bugs at about 450 MB. However, when I look at the performance section of Chrome's development tools, my JS Heap never exceeds 10 MB. It's highly likely that I misunderstood what is JS Heap.

When the web page begins to mess up, the "raster" section stays green and the CPU section displays green lines diagonally. In addition, the situation worsens when I scroll down and the FPS increases. Does anyone have an idea of ​​what's going on? What could take all this memory? How can I fix it?

javascript – Notice: Undefined variable: from_time1 in C: xampp htdocs cronometro02 response.php online 6 00:00:00 Aviso: Indefinite variable: from_time1

query ("SELECT * FROM timer");
while ($ row = mysqli_fetch_array ($ res)) {
$ duration = $ row["duration"];
}
$ _SESSION["duration"] = $ duration;
$ _SESSION["start_time"] = date ("Y-m-d H: i: s");

$ end_time = $ end_time = date (Y-m-d, strtotime (+ $ + $ 39.["duration"]. Minutes, strtotime ($ _SESSION["start_time"])));
$ _SESSION["end_time"] = $ end_time;


$ from_time1 = date (Y-m-d H: i: s & # 39;);
$ to_time1 = $ _SESSION["end_time"];

$ timefirst = strtotime ($ from_time1);
$ timesecond = strtotime ($ to_time1);

$ differenceinseconds = $ timesecond = $ timefirst;

echo gmdate ("H: i: s", $ differenceinseconds);
?>

obg: a comment on the bench of music fans !!

Retrieves the last element of a javascript array

I want to get the last element of a table that retrieves data from a query in mysql, I take the last element to pass it to a string, and then I pass this data (which only represent a few coordinates) to a map fragment of Google Maps. My question is this: know how to make the table and what they recommend for Google, I do not have much experience in this ajax and js, and I've tried several things for the fix, because i found that with an array.length i could work, but not, or maybe i'm doing it badly. Here I leave my code.

function Load () {
var xmlhttp = new XMLHttpRequest ();
var url = "query.php";
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var array = JSON.parse (xmlhttp.responseText);
var i;
var out = "";



** THE NETWORK THAT I WANT TO GET -> ** var titulo = array[a]description
var a = array.lenght
document.write (title);





out + = "
"; document.getElementById ("result"). innerHTML = out; } } xmlhttp.open ("GET", url, true); xmlhttp.send (); }

javascript – Communication between nodejs and python

I wish that a classless method be executed at each call of the static class method. This static class method will be called from another program present in another directory, every 10 seconds. The non-class method will call the python script by spawn.

I did this by calling a non-class method from a static class method. I want to know if what I'm doing is right or wrong. Or is there another good way?

home / sampath / file1 / program1.js

Class A {
constructor (name, age) {
this.name = name;
this.age = age;
}

static updateDate (name, age) {
be obj = new A (name, age);
callFunc (obj);
}
}

callFunc function (obj) {
// call a python script with the given object in the form of an argument;
// argument obj.name, obj.age
}

module.exports = A;

home / sampath / file2 / program2.js

const A = require (& # 39; ../ file1 / program1 & # 39;);

// This statement is executed every 10 seconds.
A.updateData (& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;)

Is the good coding practice that I have done better?

Journey Planner – Javascript – Stack Exchange Review Code

Here is my Javascript solution to the following problem

Since an unordered list of flights performed by a person calculates the itinerary of this person, considering the airport of departure.

If no valid itinerary, return none.

If multiple trips are valid, print any valid solution.

Examples

Board: [['SFO', 'HKO'], ['YYZ', 'SFO'], ['YUL', 'YYZ'], ['HKO', 'ORD']]From: • YUL & # 39;
Return: ['YUL', 'YYZ', 'SFO', 'HKO', 'ORD'].
Board: [['SFO', 'COM'], ['COM', 'YYZ']]Airport departure 'COM & # 39;
Back None
Board: [['A', 'B'], ['A', 'C'], ['B', 'C'], ['C', 'A']]From & # 39; A & # 39;
Return ['A', 'B', 'C', 'A', 'C']

Please, anybody can comment on the readability and efficiency of the code

Thank you

function plan_journey (location, route, route, route) {
if (voyages.length == 0) {
route.push (route + location)
}
let's stop = []
    for (i = 0; i <journeys.length; i ++) {
if (traveling[i][0]    == place) {
stops.push (i)
}
}
if (stop == []) {
return
}

for (i = 0; i <stops.length; i ++) {
let slice_index = stop[i]
        let going_journeys = journeys.slice (0, slice_index) .concat (journeys.slice (slice_index + 1))
let new_route = route + place + "-"
leave next_place = trips[stopped[stops[arrête[stops[i]][1]
        plan_journey (next_place, traveling_journeys, new_route, route)
return itinerary
}
}

let first_stop = "YUL"
let the trips = [['SFO', 'HKO'], ['YYZ', 'SFO'], ['YUL', 'YYZ'], ['HKO', 'ORD']]route = plan_dayney (first_stop, trips, "", [])
if (route.length! = 0) {
console.log (directions[0])
}other{
console.log ("None")
}