Created
January 25, 2020 14:39
-
-
Save AndrioCelos/1b82b8da8fbf55211eb64571cab5965e to your computer and use it in GitHub Desktop.
Clone detector script for KVIrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
event(OnJoin,CloneDetector) | |
{ | |
if ($isempty(%CloneData{$context.networkName})) | |
%CloneData{$context.networkName} = $new(CloneData); | |
%clones = %CloneData{$context.networkName}->$check($0, $2); | |
if ($length(%clones) == 0) { | |
echo -i=$msgtype(Join) "$k(12)$b\r!nc\r$0\r$b draws near! ($1@\r!h\r$2\r)"; | |
} else { | |
%clonesString = $link(%clones[0], nick); %cloneCount = 1; | |
for (%i = 1; %i < $length(%clones) && %i < 10; %i++) | |
%clonesString .= ", $link(%clones[%i], nick)"; | |
if ($length(%clones) > 10) | |
%clonesString .= ", $($length(%clones) - 10) more"; | |
echo -i=$msgtype(Join) "$k(12)$b\r!nc\r$0\r$b draws near! ($1@\r!h\r$2\r – $k(6)clone of %clonesString$k(12))"; | |
} | |
halt; | |
} | |
class("CloneData","object") | |
{ | |
function constructor() | |
{ | |
$$->%index = 0; | |
} | |
function check($0 = nickname, $1 = host) | |
{ | |
if ($channel && $chan.usercount <= 256) | |
%result1 = $chan.users($window, "*!*@$1"); | |
else | |
%result1 = $array(); | |
%result2 = $$->%table{$1}; | |
%result = $array(); | |
foreach (%n, %result1, %result2) { | |
if (%n != $0) %result[$length(%result)] = %n; | |
} | |
return %result; | |
} | |
function add($0 = nickname, $1 = host) | |
{ | |
if ($isempty($1)) return; | |
if ($isset($$->%table{$1})) { | |
%list = $$->%table{$1}; | |
foreach (%nickname, %list) { | |
if (%nickname == $0) return; | |
} | |
%list[$length(%list)] = $0; | |
} else { | |
// Are we at the size limit already? | |
if ($length($$->%list) == 256) { | |
if ($isempty($$->%list[$$->%index])) echo -d $$->%index; | |
$$->%table{$$->%list[$$->%index]} = $null; | |
} | |
$$->%list[$$->%index] = $1; | |
$$->%table{$1} = $array($0); | |
$$->%index = $(($$->%index + 1) % 256); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment