Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- set_time_limit(0);
- ini_set('display_errors', 'on')
- $config = array(
- 'server' => 'irc.freenode.net',
- 'port' => 6667,
- 'nick' => 'phpircb',
- 'name' => 'anonymous',
- 'pass' => 'meh',
- );
- interface iIRCbot
- {
- protected function login($config)
- private function main();
- protected function parse($data);
- protected function sent_data($cmd, $msg);
- public function join_channel($channel);
- private function op_user($channel, $user, $op);
- private function protect_user($user);
- }
- class IRCbot implements iIRCbot
- {
- var $socket;
- var $ex = array();
- function __construct($config) {
- $this->socket = fsockopen($config['server'], $config['port']);
- $this->login($config);
- $this->main();
- $this->send_data('JOIN', '#bots');
- }
- function login($config)
- {
- $this->send_data('USER', $config['nick'].' lalalalalalala'.$config['nick'].' :'.$config['name']);
- $this->send_data('NICK', $config['nick'])
- }
- function main()
- {
- $data = fgets($this->$socket, 128);
- echo nl2br($data);
- flush();
- $this->ex explode(' ', $data);
- while(true)
- $this->parse($this->ex);
- }
- function parse($data)
- {
- if($data[0] == 'PING')
- $this->send_data('PONG', $data[1]);
- $command = str_replace(array(chr(10), chr(13), '', $data[3]))
- switch($command)
- {
- case ':!join':
- $this->join_channel($data[4]);
- break;
- case ':!quit':
- send_data('QUIT', 'Leaving...');
- break;
- case ':!op':
- $this->op_user();
- break;
- case ':!deop':
- $this->op_user('', '', false);
- break;
- case ':!protect':
- $this->protect_user();
- break;
- }
- }
- function send_data($cmd, $msg = null)
- {
- if($msg == null)
- {
- fputs($this->socket, $cmd."\r\n");
- echo '<strong>'.$cmd.'</strong><br />';
- } else {
- fputs($this->socket, $cmd.' '.$msg."\r\n");
- echo '<strong>'.$cmd.' '.$msg.'</strong><br />';
- }
- }
- function join_channel($channel)
- {
- if(is_array($channel))
- {
- foreach ($channel as $chan) {
- $this->send_data('JOIN', $chan);
- } else {
- $this->send_data('JOIN', $chan);
- }
- }
- }
- function protect_user($user = '')
- {
- if($user == '')
- {
- if(phpversion() >= '5.3.0'){
- $user = strstr($this->ex[0], '!', true);
- } else {
- $length = strstr($this->ex[0], '!');
- $user = substr($this->ex[0], 0, $length);
- }
- }
- $this->send_data('MODE', $this->ex[2] . ' +a ' . $user);
- }
- function op_user($channel = '', $user = '', $op = true)
- {
- if($channel == '')
- {
- $channel = $this->ex[2];
- }
- if($user == '')
- {
- if(phpversion() >= '5.3.0'){
- $user = strstr($this->ex[0], '!', true);
- } else {
- $length = strstr($this->ex[0], '!');
- $user = substr($this->ex[0], 0, $length);
- }
- }
- if($op){
- $this->send_data('MODE', $channel . ' +o ' . $user);
- } else {
- $this->send_data('MODE', $channel . ' -o ' . $user);
- }
- }
- }
- $bot = new IRCbot($config);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement