haxball / haxball-issues

114 stars 42 forks source link

Spam #1516

Open Crenvade opened 2 years ago

Crenvade commented 2 years ago

İnsanlar çok fazla mesaj gönderdiğinde botun oyuncuya mute atmasını istiyorum. Yardım eder misiniz?

ghost commented 2 years ago

İnsanlar çok fazla mesaj gönderdiğinde botun oyuncuya mute atmasını istiyorum. Yardım eder misiniz?

@Crenvade Merhaba, #1290 daki kod üzerinde biraz değişiklik yaparak mute atacak hale getirebilirsiniz. Eğer yapamazsanız dönün ben yapıp atayım. Sorunlarınızın hızlı hallolması için İngilizce kullanırsanız daha hızlı dönüş alırsınız.

thenorthstar commented 2 years ago

İnsanlar çok fazla mesaj gönderdiğinde botun oyuncuya mute atmasını istiyorum. Yardım eder misiniz?

@Crenvade Aşağıdaki kodu kullanabilirsin:

var playerList = {};
var bound = 3; //You can either decrease or increase this, min = 2;
var spamBanLimit = 3;
var spamTimer = 3000; //In milliseconds
var removal = 60000; //In milliseconds

var room = HBInit({roomName:"TEST",noPlayer:true,public:true,maxPlayers:12});

room.onPlayerChat = function(player,message){
    playerList[player.name].messageDates.push(Date.now());
    var administrators = room.getPlayerList(p => p.admin == true);

    if(playerList[player.name].messageDates.length == bound){
    playerList[player.name].messageDates.shift();
    }
    if(playerList[player.name].messageDates.length <= bound-1 && playerList[player.name].messageDates[playerList[player.name].messageDates.length-1] - playerList[player.name].messageDates[0] < spamTimer){
    if(playerList[player.name].muted == false){
        var name = player.name;
        room.sendAnnouncement(`${player.name} was muted by the reason of spamming!`,null,0x00FF00,"bold",1);
        playerList[player.name].muted = true;

        setTimeout(function(){
        if(playerList[name].muted == true){
            playerList[name].muted = false;
            room.sendAnnouncement(`${player.name} is now unmuted!`,null,0x00FF00,"bold",1);
        }
        },removal);
    }
    else{
        room.sendAnnouncement(`You will be banned if continuing to spam in muted mode!`,player.id,0xFF8000,"bold",2);

        if(playerList[player.name].spamInMute < spamBanLimit){
        playerList[player.name].spamInMute++;
        }
        else{
        room.kickPlayer(player.id,"Spam",true);
        }

        return false;
    }
    }
    if(playerList[player.name].muted == true){
    room.sendAnnouncement(`You are muted. Only the administration can see your messages. (${message})`,player.id,0xFFFF00,"bold",2);
    administrators.forEach(p => {
        room.sendAnnouncement(`${player.name}: ${message}`,p.id,0xFFFF00,"bold",1);
    });
    return false;
    }
}

room.onPlayerJoin = function(player){
    if(playerList[player.name] == undefined){
    playerList[player.name] = {name: player.name, messageDates: [], muted: false, spamInMute: 0};
    }
}

Bu kod ise mesaj gönderen oyuncuları belirli bir süre boyunca susturacak, o süre bittiğinde ise oyuncuya sohbet otomatik olarak açılacak.

var playerList = {};
var removal = 3000; //In milliseconds

var room = HBInit({roomName:"TEST",noPlayer:true,public:true,maxPlayers:12});

room.onPlayerChat = function(player,message){
    var administrators = room.getPlayerList(p => p.admin == true);

    if(playerList[player.name].slowMode == false){
    playerList[player.name].slowMode = true;
    var name = player.name;

    setTimeout(function(){
        if(playerList[player.name].slowMode == true){
        playerList[name].slowMode = false;
        }
    },removal);
    }
    else{
    room.sendAnnouncement(`Slow mode is active. Only the administration can see your messages. (${message})`,player.id,0xFFFF00,"bold",2);
    administrators.forEach(p => {
        room.sendAnnouncement(`${player.name}: ${message}`,p.id,0xFFFF00,"bold",1);
    });
    return false;
    }
}

room.onPlayerJoin = function(player){
    if(playerList[player.name] == undefined){
    playerList[player.name] = {name: player.name, slowMode: false};
    }
}

Edit: The second code has been added.

ghost commented 2 years ago

I used this code, but it mutes me even when I write a single message. How do i set the number of messages? I changed the numbers but it had no effect

thenorthstar commented 2 years ago

I used this code, but it mutes me even when I write a single message. How do i set the number of messages? I changed the numbers but it had no effect

@mydestiny185 It's now working, here's the output. image

ghost commented 2 years ago

Thanks a lot for ur help, but I failed again. Where do you think is my mistake? Sorry for my inexperience. fail

thenorthstar commented 2 years ago

Thanks a lot for ur help, but I failed again. Where do you think is my mistake? Sorry for my inexperience. fail

@mydestiny185 You can try increasing the bound to a greater number. For example 5.

byoxygen commented 2 years ago

Why gives mutes of players after a first message even that's greater or less than bound?

thenorthstar commented 2 years ago

Why gives mutes of players after a first message even that's greater or less than bound?

@byoxygen In my room it doesn't. You can see on my comment on the following link: https://github.com/haxball/haxball-issues/issues/1516#issuecomment-1063901884

byoxygen commented 2 years ago

@thenorthstar I saw it, yes. Can you tell which platform you are using to run? Maybe related browser differences.