NECROBOT IRC AI
Bot IRC con AI multi-provider e fallback automatico.
Overview
NECROBOT utilizza API esterne per generare risposte intelligenti direttamente su IRC. Non richiede modifiche al server IRC.
Features
✔ Fallback automatico
✔ Nessuna dipendenza da mIRC
✔ Compatibile con qualsiasi server IRC
✔ Architettura distribuita
Source Code
Inserisci le tue API key e configura il server IRC prima dell'uso.
<?php /* ========================================================== NECROBOT IRC AI BOT — FULL VERSION ---------------------------------------------------------- Features: - Multi-provider AI fallback - Auto reconnect - Nick fallback - Per-user memory - Rate limiting (per user) - Personality modes - Multi-channel ready - IRC-safe message splitting - Command system ========================================================== */ /* ========================= IRC CONFIG ========================= */ $server = "YOUR_IRC_SERVER"; $port = 6667; $nick = "YOUR_BOT_NICK"; $user = "necrobot"; $real = "Necrobot AI"; $channels = ["#YOUR_CHANNEL"]; // multi-channel support /* ========================= AI PROVIDERS ========================= */ $providers = [ "groq" => [ "key" => "YOUR_GROQ_KEY", "model" => "llama3-8b-8192" ], "openrouter" => [ "key" => "YOUR_OPENROUTER_KEY", "model" => "deepseek/deepseek-r1:free" ] ]; /* ========================= RUNTIME STATE ========================= */ $userMemory = []; // per-user memory $userRate = []; // rate limit $userMode = []; // personality /* ========================= PERSONALITY SYSTEM ========================= */ function getSystemPrompt($mode) { switch ($mode) { case "dark": return "You are NECROBOT, dark, sarcastic and slightly aggressive IRC AI."; case "friendly": return "You are NECROBOT, friendly and helpful."; default: return "You are NECROBOT, an IRC-style AI."; } } /* ========================= AI CORE ========================= */ function askAI($user, $prompt) { global $providers, $userMemory, $userMode; $mode = $userMode[$user] ?? "default"; $system = getSystemPrompt($mode); // build conversation memory (last 5 messages) $history = $userMemory[$user] ?? []; $messages = [ ["role" => "system", "content" => $system] ]; foreach ($history as $msg) { $messages[] = $msg; } $messages[] = ["role" => "user", "content" => $prompt]; $order = array_keys($providers); shuffle($order); foreach ($order as $name) { $cfg = $providers[$name]; $reply = callProvider($name, $cfg, $messages); if ($reply) { // store memory $userMemory[$user][] = ["role"=>"user","content"=>$prompt]; $userMemory[$user][] = ["role"=>"assistant","content"=>$reply]; // keep memory short $userMemory[$user] = array_slice($userMemory[$user], -6); return "[$name] " . trim($reply); } } return "NECROBOT: all providers failed 💀"; } /* ========================= PROVIDER ROUTER ========================= */ function callProvider($name, $cfg, $messages) { switch ($name) { case "groq": return curlJSON( "https://api.groq.com/openai/v1/chat/completions", $cfg['key'], ["model"=>$cfg['model'], "messages"=>$messages] ); case "openrouter": return curlJSON( "https://openrouter.ai/api/v1/chat/completions", $cfg['key'], ["model"=>$cfg['model'], "messages"=>$messages] ); default: return null; } } /* ========================= CURL HELPER ========================= */ function curlJSON($url, $key, $data) { $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_TIMEOUT => 8, CURLOPT_HTTPHEADER => [ "Authorization: Bearer $key", "Content-Type: application/json" ], CURLOPT_POSTFIELDS => json_encode($data) ]); $res = curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($code !== 200 || !$res) return null; $json = json_decode($res, true); return $json['choices'][0]['message']['content'] ?? null; } /* ========================= IRC MESSAGE SPLIT ========================= */ function sendIRC($fp, $chan, $text) { $chunks = str_split($text, 350); foreach ($chunks as $chunk) { fwrite($fp, "PRIVMSG $chan :[NECROBOT] $chunk\r\n"); usleep(200000); } } /* ========================= COMMAND HANDLER ========================= */ function handleCommand($fp, $user, $chan, $cmd, $args) { global $userRate, $userMode, $userMemory; // rate limit per user if (!isset($userRate[$user])) $userRate[$user] = 0; if (time() - $userRate[$user] < 2) { sendIRC($fp, $chan, "slow down 😈"); return; } $userRate[$user] = time(); switch ($cmd) { case "ai": $reply = askAI($user, $args); sendIRC($fp, $chan, $reply); break; case "mode": $userMode[$user] = $args ?: "default"; sendIRC($fp, $chan, "mode set to ".$userMode[$user]); break; case "reset": unset($userMemory[$user]); sendIRC($fp, $chan, "memory cleared"); break; case "help": sendIRC($fp, $chan, "!ai !mode !reset !help"); break; } } /* ========================= MAIN LOOP ========================= */ while (true) { $fp = @fsockopen($server, $port); if (!$fp) { sleep(5); continue; } fwrite($fp, "NICK $nick\r\n"); fwrite($fp, "USER $user 0 * :$real\r\n"); while (!feof($fp)) { $data = fgets($fp, 512); if (!$data) continue; echo $data; // PING if (strpos($data, "PING") === 0) { fwrite($fp, "PONG ".substr($data, 5)); continue; } // nick in use if (strpos($data, "433") !== false) { $nick .= rand(0,9); fwrite($fp, "NICK $nick\r\n"); continue; } // join if (strpos($data, "001") !== false) { foreach ($channels as $c) { fwrite($fp, "JOIN $c\r\n"); } continue; } // parse commands if (preg_match('/^:([^!]+)!.* PRIVMSG (#\S+) :!(\w+)\s*(.*)$/', $data, $m)) { $user = $m[1]; $chan = $m[2]; $cmd = strtolower($m[3]); $args = trim($m[4]); handleCommand($fp, $user, $chan, $cmd, $args); } } fclose($fp); sleep(3); }
Usage
2. Configura server IRC
3. Avvia: php necrobot.php
Comandi disponibili:
!ai testo
!calc 2+2
!weather città
!time
!rand 100
!ping
!about
!help
Admin Commands
!mute nick
!unmute nick
!ban nick
!unban nick
!reload