I want to make some "Join To Create" bot, with a random voice channel name. and it's only showing "name 2", and the other name is not shown... please help me
const name = [
'name 1',
'name 2',
'name 3',
'name 4',
'name 5'
];
const rand = Math.floor(Math.random() * name.length);
await user.guild.channels.create(name[rand] {
type: 'voice',
parent: "804342854432194591"
});
If you want to randomize something, you may use:
const rand = name[Math.floor(Math.random() * options.length)];
Related
I use Yup for my Formik form validation.
I have the following contact form :
const contactForm =
{
title: undefined,
firstName: '',
lastName: props.contact?.name,
contactGroup: {
phone: props.contact?.phone || '',
email: props.contact?.email || '',
},
};
when I fill in the fields I would like the lastName field to go to error only when one of the other fields is filled in.
Here is the validation scheme I use to handle form errors
const schema = yup
.object()
.shape<any>({
firstName: yup.string().max(256, 'max-length'),
lastName: yup.string().when(['email', 'phone', 'firstName'], {
is: (email: any, phone: any, firstName: any) =>
email && phone && firstName,
then: yup.string().required('empty').max(256, 'max-length'),
}),
contactGroup: yup.object().shape<any>(
{
phone: yup.string().when('email', {
is: (email: any) => !email || email === '',
then: yup.string().max(256, 'max-length'),
}),
email: yup
.string()
.nullable(true)
.when('phone', {
is: (phone: any) => !phone || phone === '',
then: yup.string().email('invalid').max(256, 'max-length'),
}),
},
[
['phone', 'email'],
['email', 'phone'],
]
),
})
.required();
I modified the yup in the following way:
lastName: yup.string().when(['email', 'phone', 'firstName'], {
is: (email: any, phone: any, firstName: any) =>
email && phone && firstName,
then: yup.string().required('empty').max(256, 'max-length'),
}),
here I ask if the fields email, phone and firstName are filled in the field lastName is set in error.
It works if I do it only on firstName, but if I add email and phone it doesn't work anymore.
I think it comes from the fact that phone and email are in a contactGroup subobject
Is there a solution for this problem ?
lastName should only go into error when one of the fields phone, email or firstName is filled in.
I am trying to create an update user detail system inside wp-admin, request is getting send properly with all data as I checked inside developers tools (network), but response is getting received 500 in red color
public function edit_employee_data()
{
global $wpdb;
$wpdb->update($wpdb->prefix . 'employee', array(
'name' => $_POST['name'],
'dob' => $_POST['dob'],
'email' => $_POST['email'],
'joining_date' => $_POST['joining_date'],
'address' => $_POST['address'],
'salary_package' => $_POST['salary_package'],
'gender' => $_POST['gender'],
'marital_status' => $_POST['marital_status'],
'department' => $_POST['department'],
'designation' => $_POST['designation']
));
}
add_action('wp_ajax_update_employee', array($this, 'edit_employee_data'));
Javascript used for Ajax call:
<script>
jQuery(document).ready(function($) {
$('form.edit_employee').on('submit', function(e) {
e.preventDefault();
var name = $('#name').val();
var email = $('#email').val();
var dob = $('#dob').val();
var joining_date = $('#joining_date').val();
var address = $('#address').val();
var salary_package = $('#salary_package').val();
var gender = $('#gender').val();
var marital_status = $('#marital_status').val();
var department = $('#department').val();
var designation = $('#designation').val();
var message = $('.message').val();
$.ajax({
url: ajaxurl,
type: "POST",
data: {
action: 'update_employee',
name: name,
email: email,
message: message,
dob: dob,
joining_date: joining_date,
address: address,
salary_package: salary_package,
gender: gender,
marital_status: marital_status,
department: department,
designation: designation,
message: message,
},
success: function(response) {
$(".success_msg").css("display", "block");
},
error: function(data) {
$(".error_msg").css("display", "block");
}
});
});
});
</script>
values are getting send properly with the action name but I don't understand why it's not working.
UPDATE operations need WHERE clauses unless you really intend to update all the rows in the table (unlikely in your example). $wpdb->update() has a third argument giving the WHERE filter, but you omitted it.
Figure out how you identify the row--the employee--you want to update. It might be by employee_id, for example.
Then provide something like this as the third arg.
[employee_id => $_POST[employee_id]]
I am first time integrating the event calendar and I have successfully integrated everything, only one point where I am trapped is event background color is not changing. It is default set to yellow. I just want to change the background color of it.
Here is my code from where I am showing the data on event calendar.
showEvent(arg) {
this.addingMode = false;
const { id, title, start, end, desc } = this.events.find(
event => event.id === +arg.event.id
);
this.indexToUpdate = id;
this.newEvent = {
event_name: title,
start_date: start,
end_date: end,
description: desc,
};
},
And data is coming in it from,
public function toArray($request)
{
return [
'id' => $this->id,
'title' => $this->status,
'start' => $this->start_date,
'end' => $this->end_date,
'desc' => $this->description,
];
}
event_name: title is showing the status 0 or 1 on calender, I just want that where it is 0, it will show me yellow and where it is 1, it will show red.
Please help me out, I am poorly trapped in it,
I have following code that takes 3 lists of objects (Location, Machine, Sensor). They are then mapped based on parent ids (Location has machines and machine has sensors) to object with children
The resulting observable return object that is Location (that has list of Machines, where each has list of Sensors).
It works fine. However I'd like to get a single list of Locations, but when I use toArray() on the observable, the original array that is returned is duplicated with each subscription.
function getLocations() {
return [
{id: 'loc1', name: 'Some location'},
{id: 'loc2', name: 'Other location'},
{id: 'loc3', name: 'New location'},
];
}
function getMachines() {
return [
{id: '1', name: 'Machine 1', location: 'loc1'},
{id: '2', name: 'Machine 2', location: 'loc1'},
{id: '3', name: 'Machine 3', location: 'loc2'},
{id: '4', name: 'Machine 4', location: 'loc3'},
];
}
function getSensors() {
return [
{id: 's1', name: 'Sensor 1', machine: '1'},
{id: 's2', name: 'Sensor 2', machine: '3'},
{id: 's3', name: 'Sensor 3', machine: '1'},
{id: 's5', name: 'Sensor 5', machine: '4'},
{id: 's4', name: 'Sensor 4', machine: '2'},
];
}
const sensors$ = Rx.Observable.from(getSensors());
const machinesWithSensors$ = Rx.Observable.from(getMachines())
.flatMap(machine => sensors$.filter(sensor => sensor.machine === machine.id).toArray().map(sensors => {
return {...machine, sensors: sensors}
}));
const allData$ = Rx.Observable.from(getLocations())
.flatMap(location => machinesWithSensors$
.filter(machine => machine.location === location.id)
.toArray().map(machines => {
return {...location, machines: machines};
}));
const allDataArr$ = allData$.toArray();
allData$.subscribe(s => console.log('allData1', s))
allData$.subscribe(s => console.log('allData2', s))
allData$.subscribe(s => console.log('allData3', s))
allDataArr$.subscribe(s => console.log('allDataArr1', s))
allDataArr$.subscribe(s => console.log('allDataArr2', s))
allDataArr$.subscribe(s => console.log('allDataArr3', s))
Example on codepen:
https://codepen.io/anon/pen/ooaBdj
Why is that? How do I 'reset' the observable before each subscription?
I create a telegram bot keaboard with laravel. There is a part of code.
$available_buttons =ReportToAbonent::select("report_id")
->join("telegram.reports", "report_to_abonent.report_id", "=", "reports.id")
->where("abonent_id", "=", $abonent[0]->id)
->where("active","=","1")
->get();
$keyboard = array();
foreach ($available_buttons as $value)
{
$keyboard[] = array($value->report_id);
}
$reply_markup = \Telegram::replyKeyboardMarkup([
'keyboard' => $keyboard,
'resize_keyboard' => true,
'one_time_keyboard' => false
]);
If I print
$keyboard`, its structure looks like if `$keyboard = [
['7', '8', '9'],
['4', '5', '6'],
['1', '2', '3'],
['0']
];
But in first case no keyboard in telegram client. In the second case it is present. What can I do wrong.
You have wrong format in inline keyboard, please check out API reference.
And you can refer to this sample request:
Contains only one button: (Parameters and Response)
Contains 2x3 buttons:
This is Two examples of each keyboard:
Normal Keboard:
const opts = {
reply_markup: JSON.stringify({
keyboard: [
['Normal'],
],
resize_keyboard: true,
one_time_keyboard: true,
}),
};
Inline Keboard:
const inlineopts = {
reply_markup: {
inline_keyboard: [
[{
text: 'Yahoo',
url: 'www.yahoo.com',
}],
[{
text: 'Google',
url: 'www.google.com',
}],
],
},
};