-
Notifications
You must be signed in to change notification settings - Fork 2
/
i-mscp-bot
executable file
·120 lines (100 loc) · 3.67 KB
/
i-mscp-bot
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
#!/usr/bin/php
<?php
/**
* i-MSCP-Bot - A bot for the i-MSCP project
* Copyright (C) 2011 by Laurent Declercq
*
* This program 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 2
* of the License, or (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2011 by Laurent Declercq
* @author Laurent Declercq <[email protected]>
* @version SVN: $Id$
* @link http://www.i-pms.net i-PMS Home Site
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL v2
*/
// Bot version
define('BOT_VERSION', '0.0.1');
define('BOT_DESCRIPTION', 'i-MSCP Bot to query Trac');
// Irc hostname to connect to
define('IRC_HOSTNAME', 'irc.freenode.net');
// Irc hostname port to connnect to
define('IRC_PORT', 6667);
// Public Irc nickname
define('IRC_NICKNAME', 'i-mscp-bot');
// Bot real name
define('IRC_REALNAME', 'i-MSCP bot');
// Identification username
define('IRC_USERNAME', null);
// Identification password
define('IRC_PASSWORD', null);
$ircChannelsToListenOn = array(
'#i-mscp', # Community channel
'#i-mscp-dev' # Development channel
);
defined('ROOT_PATH') || define('ROOT_PATH', realpath(dirname(__FILE__)));
// Sets include_path
set_include_path(implode(PATH_SEPARATOR, array(
'/usr/local/lib/iMSCP/library',
'/usr/local/lib/iMSCP/library/vendor/pear',
get_include_path())));
if (!require_once( 'Net/SmartIRC.php')) {
die('Net_SmartIRC pear package not found. Please install it and restart the bot.');
}
// Temporary fix to prevent kick
class nokick
{
/**
*
* @param Net_SmartIRC_messagehandler $ircHandler
* @param Net_SmartIRC_data $ircData Irc Data
* @return void
*/
public function join($ircHandler, $ircData)
{
global $ircChannelsToListenOn;
foreach ($ircChannelsToListenOn as $channel) {
$ircHandler->join($channel);
}
$ircHandler->message(
SMARTIRC_TYPE_CHANNEL, $ircData->channel,
$ircData->nick . ": You are happy? Stop to play now...");
}
}
// Configure the bot
$smartIrc = new Net_SmartIRC();
$smartIrc->setAutoReconnect(true);
$smartIrc->setAutoRetry(true);
$smartIrc->setAutoRetryMax(5);
$smartIrc->setUseSockets(true);
$smartIrc->setCtcpVersion(BOT_DESCRIPTION . ' v' . BOT_VERSION);
$smartIrc->setSenddelay(0);
$smartIrc->setChannelSyncing(true);
$smartIrc->setUserSyncing(true);
$smartIrc->setReconnectdelay(250);
// Include library to Irc Queries
require_once 'iMSCP/Bot/Trac/Queries.php';
// Handler to answer queries
$smartIrc->registerActionhandler(
SMARTIRC_TYPE_CHANNEL, '/.*/i', new iMSCP_Bot_Trac_Queries(), 'querieshandler');
// Handler to rejoin the channel on kick
$smartIrc->registerActionhandler(SMARTIRC_TYPE_KICK, '', new nokick(), 'join');
// Connection, login, join...
$smartIrc->connect(IRC_HOSTNAME, IRC_PORT);
$smartIrc->login(IRC_NICKNAME, IRC_REALNAME, 0, IRC_USERNAME, IRC_PASSWORD);
sleep(3);
$smartIrc->join($ircChannelsToListenOn);
$smartIrc->listen(); // Entering in loop here
$smartIrc->disconnect();
exit(0);