Open hamburgstaller opened 3 years ago
// the message to test against
const messageToTest = `!pd11`;
const regex = /^!pd(\d)(\d)$/i;
const result = regex.exec(messageToTest);
if(result) {
const [,a,b] = result;
room.sendAnnouncement(`PD = ${a} - ${b}`, undefined);
}
// the message to test against const messageToTest = `!pd11`; const regex = /^!pd(\d)(\d)$/i; const result = regex.exec(messageToTest); if(result) { const [,a,b] = result; room.sendAnnouncement(`PD = ${a} - ${b}`, undefined); }
not working :(
const room = HBInit({});
const regex = /^!pd(\d)(\d)$/i;
room.onPlayerChat = (player, msg) => {
const result = regex.exec(msg);
if(result) {
const [,a,b] = result;
room.sendAnnouncement(`PD = ${a} - ${b}`, undefined);
return false;
}
}
I tested it and it works, just run this little bot and type in the chat !pd51
const room = HBInit({}); const regex = /^!pd(\d)(\d)$/i; room.onPlayerChat = (player, msg) => { const result = regex.exec(msg); if(result) { const [,a,b] = result; room.sendAnnouncement(`PD = ${a} - ${b}`, undefined); return false; } }
I tested it and it works, just run this little bot and type in the chat
!pd51
The code is working.
But
Only admins will be able to use it.
and
! pd xxxx
can you
For example;
PD 11-11
let regex2 = /\d+/g;
let res2 = "!pd 22 33".match(regex2);
if(res2.length < 2 || !res2){
console.log( "Error");
}
else{
let [a,b] = res2;
console.log("a: " + a +" b: "+ b);
}
Configure this code as you want.
let regex2 = /\d+/g; let res2 = "!pd 22 33".match(regex2); if(res2.length < 2 || !res2){ console.log( "Error"); } else{ let [a,b] = res2; console.log("a: " + a +" b: "+ b); }
Configure this code as you want.
only admin can this
and
sendAnnouncement
const room = HBInit({}); const regex = /^!pd(\d)(\d)$/i; room.onPlayerChat = (player, msg) => { const result = regex.exec(msg); if(result) { const [,a,b] = result; room.sendAnnouncement(`PD = ${a} - ${b}`, undefined); return false; } }
I tested it and it works, just run this little bot and type in the chat
!pd51
only this work but i want
only can admin work this
and
!pd xxxx argument
@augus99 are u here?
const room = HBInit({});
const regex = /^!pd(\d{1,2})(\d{1,2})$/i;
room.onPlayerChat = (player, msg) => {
const result = regex.exec(msg);
if(result && player.admin) {
const [,a,b] = result;
room.sendAnnouncement(`PD = ${a} - ${b}`, undefined);
return false;
}
}
I recommend you to first learn basic javascript, and then continue with the bot, good luck!
q