-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.php
126 lines (117 loc) · 3.71 KB
/
bot.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/*
## This file is part of FINOd.
##
## FINOd is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## FINOd is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with FINOd.
## If not, see <http://www.gnu.org/licenses/>.
*/
set_time_limit(0);
date_default_timezone_set("Europe/Berlin");
function cin()
{
$fopen = fopen('php://stdin', 'r');
$input = fgets($fopen, 1024);
$input = trim($input);
fclose($fopen);
return $input;
}
class bot
{
public $host, $port, $channel, $user, $mail, $pass, $socket, $commands, $nickserv;
public static $instance = NULL;
function __construct($host, $port, $user, $channel, $nickserv, $mail, $pass)
{
$this->host = $host;
$this->port = $port;
$this->user = $user;
$this->channel = $channel;
$this->nickserv = $nickserv;
$this->mail = $mail;
$this->pass = $pass;
$this->socket = @fsockopen($this->host, $this->port, $errno, $errstr, 2);
if ($this->socket)
{
$this->log('info', 'CONNECTED!');
fwrite($this->socket, "PASS NOPASS\n\r");
$this->log('send', "PASS NOPASS");
fwrite($this->socket, "NICK ".$this->user."\n\r");
$this->log('send', "NICK ".$this->user);
fwrite($this->socket, "USER ".$this->user." * * :".$this->user." is a Bot using FINOd\n\r");
$this->log('send', "USER ".$this->user." * * :".$this->user." is aBot using FINOd");
}
else
{
$this->log('error', "Couldn't connect to server. Please doublecheck everything.");
die();
}
}
static function getInstance($host, $port, $user, $channel, $nickserv, $mail, $pass)
{
if (self::$instance == NULL)
{
self::$instance = new self($host, $port, $user, $channel, $nickserv, $mail, $pass);
}
return self::$instance;
}
function log($type, $msg)
{
echo "[".strtoupper($type)." ".date('H').":".date('i').":".date('s')."] $msg\n";
}
function get()
{
$input = (fgets($this->socket, 1024));
if (rtrim($input) != "")
{
$input = rtrim($input);
$this->log('get', $input);
return $input;
}
}
function handler($msg)
{
$commands = new commands();
$messages = new messages($msg);
if(substr($msg, 0, 4) == 'PING')
{
$commands->pong($msg);
}
elseif(strpos($msg, $this->user." :End of /MOTD command."))
{
var_dump($this->channel);
if(is_object($this->channel))
{
foreach($this->channel->channel as $channelitem)
$commands->join($channelitem);
}
//$commands->privmsg("#Brotkasten", "\xe4 \xc3\xb6 \xc3\xbc \xc3\x9f \xc3\x84 \xc3\x96 \xc3\x9c");
$commands->umode("+B");
}
elseif (strpos($msg, "NOTICE ".$this->user." :Your nick isn't registered") and strtolower($messages->getSender()) == 'nickserv' and strtolower($this->nickserv) == 'y' and $this->pass != "" and $this->mail != "")
{
$nickserv = nickserv::getInstance($this->user, $this->mail, $this->pass);
$nickserv->register();
}
elseif (strpos($msg, 'NOTICE '.$this->user.' :This nickname is registered and protected. If it is your') and strtolower($messages->getSender()) == 'nickserv' and strtolower($this->nickserv) == 'y')
{
$nickserv = nickserv::getInstance($this->user, $this->mail, $this->pass);
$nickserv->login();
}
elseif ($messages->getType() == "PRIVMSG" and $messages->getSender() != $this->user and $messages->getCommandPrefix() == "!")
{
$usercommands = new usercommands;
$usercommands->handler($msg);
}
}
}
?>