• Login
  • Register
  • Zoek
This Thread
  • Everywhere
  • This Thread
  • This Forum
  • Articles
  • Pages
  • Forum
  • Filebase Entry
  • More Options

ICTscripters

Dé plek voor IT

Dé plek voor IT

Login

Geavanceerde opties
  1. Home
  2. Forum
    1. Alle berichten
    2. Recente activiteiten
  3. ICT Nieuws
  4. Blog
  5. Marktplaats
    1. Werk
    2. Advertenties
    3. Domeinnamen
    4. Websites
    5. Design & lay-outs
    6. Scripts
    7. Overige
  6. Design
  7. Leden
    1. Actieve bezoekers
    2. Team
    3. Leden zoeken
  8. Downloads
  9. Goedkope domeinnamen
  1. Home
  2. Forum
    1. Alle berichten
    2. Recente activiteiten
  3. ICT Nieuws
  4. Blog
  5. Marktplaats
    1. Werk
    2. Advertenties
    3. Domeinnamen
    4. Websites
    5. Design & lay-outs
    6. Scripts
    7. Overige
  6. Design
  7. Leden
    1. Actieve bezoekers
    2. Team
    3. Leden zoeken
  8. Downloads
  9. Goedkope domeinnamen
  1. Home
  2. Forum
    1. Alle berichten
    2. Recente activiteiten
  3. ICT Nieuws
  4. Blog
  5. Marktplaats
    1. Werk
    2. Advertenties
    3. Domeinnamen
    4. Websites
    5. Design & lay-outs
    6. Scripts
    7. Overige
  6. Design
  7. Leden
    1. Actieve bezoekers
    2. Team
    3. Leden zoeken
  8. Downloads
  9. Goedkope domeinnamen
  1. Dé plek voor IT - ICTscripters
  2. Forum
  3. Scripting & programmeren
  4. PHP + SQL

Forum

  • RPG game gebouwd met AI

    Frenzo.Webservice 11 juni 2026 om 19:44
  • Het Grote Vibe Code Topic

    Syntax 1 juni 2026 om 20:05
  • PWYL source gezocht

    Syntax 29 mei 2026 om 14:03
  • Ictscripters Chat

    AarClay 21 april 2026 om 11:34
  • Help testers nodig voor android app Urgent

    Servertjee 20 februari 2026 om 12:07
  • Partner Gezocht om meerdere NFT Collecties op Open Sea te Plaatsen

    Servertjee 20 februari 2026 om 12:06
  • Afspraken systeem met planbeperking

    Jeffrey.Hoekman 20 februari 2026 om 11:52
  • Developer Gezocht

    Servertjee 19 februari 2026 om 17:31

Marktplaats

  • 359 Nieuwe Domeinnamen Mei 2026

    shiga 1 juni 2026 om 12:45
  • Sicarras.com - Moderne Mafia Text-Based RPG

    Jeffrey.Hoekman 27 mei 2026 om 17:40
  • 370 Nieuwe Domeinnamen April 2026

    shiga 1 mei 2026 om 12:06

Voor wie een php irc bot wou beginnen

  • Patrick
  • 9 maart 2014 om 17:57
  • Patrick
    Back in the game
    Ontvangen Reacties
    52
    Berichten
    1.417
    • 9 maart 2014 om 17:57
    • #1

    Zie hieronder :-):

    PHP
    <?php
    ini_set('max_execution_time', -1);
    
    
    class configuration {
    	
    	public $botConfig;
    	
    	public function __construct() {
    		$this->botConfig = array();
    	}
    	
    	public function createNewBot($hostname, $identity, $server, $realname, $nickname, $port, $domain) {
    		if (count($this->botConfig) == 0) {
    			$botConfigID = 0;
    		} else {
    			$botConfigID = count($this->botConfig);
    		}
    		$this->botConfig[$botConfigID]['hostname'] = $hostname;
    		$this->botConfig[$botConfigID]['identity'] = $identity;
    		$this->botConfig[$botConfigID]['server'] = $server;
    		$this->botConfig[$botConfigID]['realname'] = $realname;
    		$this->botConfig[$botConfigID]['nickname'] = $nickname;
    		$this->botConfig[$botConfigID]['port'] = $port;
    		$this->botConfig[$botConfigID]['domain'] = $domain;
    		
    		return $botConfigID;
    	}
    }
    
    
    class socket {
    	
    	public $sockets;
    	public $socketError;
    	
    	public function __construct() {
    		$this->sockets = array();
    		$this->socketError = array();
    	}
    	
    	public function create_socket($domain = 'ipv4') {
    		if ($domain == 'ipv6') { 
    			$this->sockets[] = socket_create(AF_INET6, SOCK_STREAM, SOL_TCP); 
    		} else { 
    			$this->sockets[] = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
    		}
    		
    		$insertedArrayID = (count($this->sockets) - 1); 
    		if ($this->sockets[$insertedArrayID] == false) {
    			$this->$socketError[$insertedArrayID]['errorCode'] = socket_last_error($this->sockets[$insertedArrayID]);
    			$this->$socketError[$insertedArrayID]['errorMessage'] = socket_strerror($errorCode);
    			
    			socket_clear_error($this->sockets[$insertedArrayID]);
    			
    			return $socketError;
    		} else {
    			return $insertedArrayID;
    		}
    	}
    	
    	public function bind_socket($socketID = 0, $hostname) {
    		if (is_int($socketID)) {
    			
    			/* We can not make any more sockets until SO_REUSEPORT comes available on linux */
    			socket_set_option($this->sockets[$socketID], SOL_SOCKET, SO_REUSEADDR, 1);
    			
    			if (socket_bind($this->sockets[$socketID], $hostname, $this->configurationClass->botConfig[$socketID]['port']) == false) {
    				$this->$socketError[$socketID]['errorCode'] = socket_last_error($this->sockets[$socketID]);
    				$this->$socketError[$socketID]['errorMessage'] = socket_strerror($errorCode);
    			
    				socket_clear_error($this->sockets[$socketID]);
    			
    				return $socketError;
    			} else {
    				return true;
    			}
    		} else {
    			return false;
    		}
    	}
    	
    	public function connect_socket($socketID = 0, $ip, $port) {
    		if (is_int($socketID)) {
    			socket_connect($this->sockets[$socketID], $ip, $port);
    			
    			if ($this->sockets[$socketID] == false) {
    				$this-$socketError[$socketID]['errorCode'] = socket_last_error($this-$sockets[$socketID]);
    				$this-$socketError[$socketID]['errorMessage'] = socket_strerror($errorCode);
    			
    				socket_clear_error($this-$socket[$socketID]);
    			
    				return $socketError;
    			} else {
    				return true;
    			}
    		} else {
    			return false;
    		}
    	}
    	
    	public function write_socket($socketID = 0, $bufferData) {
    		if (is_int($socketID)) {
    			socket_write($this->sockets[$socketID], $bufferData . "\r\n");
    		} else {
    			return false;
    		}
    	}
    	
    	public function read_socket($socketID = 0) {
    		if (is_int($socketID)) {
    			$buffer = socket_read($this->sockets[$socketID], 65000, PHP_NORMAL_READ);
    			if ($buffer == '\n' OR $buffer == '\r') {
    				continue;
    			}
    			
    			return $buffer;
    		} else {
    			return false;
    		}	
    	}
    	
    	public function shutdown_socket($socketID = 0) {
    		if (is_int($socketID)) {
    			socket_shutdown($this->sockets[$socketID], 2);
    			
    			$this->close_socket[$socketID];
    		} else {
    			return false;
    		}
    	}
    	
    	protected function close_socket($socketID = 0) {
    		if (is_int($socketID)) {
    				socket_close($this->sockets[$socketID]);
    			return;
    		} else {
    			return false;
    		}	
    	}
    }
    
    
    class irc extends socket {
    	
    	private $configurationClass;
    	
    	public function setconfigrationClass($class) {
    		$this->configurationClass = $class;
    	}
    	
    	public function connectIRC($botID) {
    		$this->create_socket($this->configurationClass->botConfig[$botID]['domain']);
    		
    		$this->bind_socket($botID, $this->configurationClass->botConfig[$botID]['hostname'] . $botID);
    		$this->connect_socket($botID, $this->configurationClass->botConfig[$botID]['server'], $this->configurationClass->botConfig[$botID]['port']);
    		
    		$this->initIRCConnection($botID);
    		return true;
    	}
    	
    	protected function initIRCConnection($socketID = 0) {
    		$this->write_socket($socketID, 'USER ' . $this->configurationClass->botConfig[$socketID]['identity'] . ' ' .
    												   $this->configurationClass->botConfig[$socketID]['hostname'] . ' ' .
    												   $this->configurationClass->botConfig[$socketID]['server'] . ' :' .
    												   $this->configurationClass->botConfig[$socketID]['realname']);
    										
    		$this->write_socket($socketID, 'NICK ' . $this->configurationClass->botConfig[$socketID]['nickname']);
    		return true;
    	}
    	
    	public function playPingPong($socketID = 0, $pingID) {
    		$this->write_socket($socketID, 'PONG ' . $pingID);
    		return true;
    	}
    }
    
    
    $configurationClass = new configuration();
    $ircClass = new irc();
    
    
    $configurationClass->createNewBot(0, 'viibot', 'irc.onlinegamesnet.net', 'vii realname', 'viibot', 6667, 'ipv4');
    
    
    $ircClass->setconfigrationClass($configurationClass);
    foreach ($configurationClass->botConfig AS $bot => $botData) {
    	$ircClass->connectIRC($bot);
    }
    
    
    $i = 0;
    while (1) {
    	foreach ($configurationClass->botConfig AS $botID => $botData) {
    		
    		$usableID = intval($botID);
    		$bufferData = $ircClass->read_socket($usableID);
    		$splitBuffer = split(' ', $bufferData);
    		
    		if ($splitBuffer[0] = 'PING') {
    			$ircClass->playPingPong($usableID, $splitBuffer[1]);
    		}
    	}
    }
    ?>
    Toon Meer

    Ik ga hem zelf rebuilden met het gebruik met pcntl_fork :-).
    Enige wat de bot nu kan is connecten naar een irc server en idle'en :-).

    in de while (1) { } loop zal je het een en ander nog wel zelf moeten defineren aan commands :).
    Let op: ondanks dat er wel de functionaliteit in zit dat er meerdere sockets te gelijk kunnen opereren binnen script kan het nu niet dat 2 bots over de zelfde port luisteren (Standaard 6667).

  • Guest, wil je besparen op je domeinnamen? (ad)
  • Frenzo.Webservice
    Web Developer
    Ontvangen Reacties
    36
    Berichten
    541
    • 10 maart 2014 om 11:18
    • #2

    Zou je ook misschien kunnen uitleggen voor de mensen zoals ik die niet weten wat het is?

    Gr,
    Frenzo

    Helpt bedrijven met groeien :)

  • L. Velthuis
    Vato Gonzalez
    Ontvangen Reacties
    32
    Berichten
    682
    • 10 maart 2014 om 11:49
    • #3

    Ook ik zou graag weten wat het is. en wat je er mee zou kunnen doen.

    Beginnend DJ! Volg mij op MixCloud!

    Lars Velthuis | Mixcloud

  • Patrick
    Back in the game
    Ontvangen Reacties
    52
    Berichten
    1.417
    • 10 maart 2014 om 17:32
    • #4

    IRC is een chat protocol waarmee je in verschillende kanalen kan chatten deze kan je ook beheren etc.
    Doormiddel van een automatisering bot kan je bepaalde kanaal handeling makkelijker doen of kan in de chat bijv:

    !imdb the hobbit

    doen en krijg je informatie over die film. (voorbeeld uiteraard zit niet hierin)
    Het script is basis programmering om een "geautomatiseerde user" te beginnen waarmee je zulke dingen kan bereiken.

Participate now!

Heb je nog geen account? Registreer je nu en word deel van onze community!

Maak een account aan Login

ICT Nieuws

  • Quanscient ontvangt €10M om AI- en kwantum-native hardware engineering te bevorderen - Tech.eu

    ICTscripters 27 mei 2026 om 12:03
  • Datalek bij leverancier Canvas - Universiteit van Amsterdam

    ICTscripters 10 mei 2026 om 12:03
  • Data privacy in 2026: Hoe de naleving van GDPR verandert

    ICTscripters 8 mei 2026 om 12:16

Blogs

  • Functioneel ontwerp

    Dees 28 december 2014 om 12:38
  • Access Control List implementatie in PHP/MySQL - deel 1/2

    FangorN 28 december 2018 om 12:35
  • Access Control List implementatie in PHP/MySQL - deel 2/2

    FangorN 29 december 2018 om 12:37
  1. Marktplaats
  2. Design
  3. Voorwaarden
  4. Ons team
  5. Leden
  6. Geschiedenis
  7. Regels
  8. Links
  9. Privacy Policy
ICTscripters ©2005 - 2026 , goedkope hosting door DiMoWeb.com, BE0558.915.582
Sponsors: Beste kattenhotel provincie Antwerpen | Beste Zetes eid kaartlezer webshop
Style: Nexus by cls-design
Stylename
Nexus
Manufacturer
cls-design
Licence
Commercial styles
Help
Supportforum
Visit cls-design