haxball / haxball-issues

114 stars 42 forks source link

simple ?! #1240

Open hamburgstaller opened 3 years ago

hamburgstaller commented 3 years ago

q

augus99 commented 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);
}
hamburgstaller commented 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);
}

not working :(

augus99 commented 3 years ago
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

hamburgstaller commented 3 years ago
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

ghost commented 3 years ago
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.

hamburgstaller commented 3 years ago
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

hamburgstaller commented 3 years ago
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

hamburgstaller commented 3 years ago

@augus99 are u here?

augus99 commented 3 years ago
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!