diff --git a/CONFIG.INI b/CONFIG.INI
index 90b3d82..a2a7496 100644
--- a/CONFIG.INI
+++ b/CONFIG.INI
@@ -96,7 +96,7 @@ command_prefix = '!'
ctcp_response = 'yes'
; ctcp version response (please do not change it:)
-ctcp_version = 'MINION (1.1.4) powered by minions!'
+ctcp_version = 'MINION (1.1.5) powered by minions!'
; ctcf finger response
ctcp_finger = 'MINION'
diff --git a/DOCS/CHANGELOG.TXT b/DOCS/CHANGELOG.TXT
index 2bc69ca..937e863 100644
--- a/DOCS/CHANGELOG.TXT
+++ b/DOCS/CHANGELOG.TXT
@@ -1,4 +1,7 @@
-
+
+ v1.1.5 changes (28.12.2020):
+ - code cleanup
+
v1.1.4 changes (26.12.2020):
- Plugin: restart - now escapes from parent process
- Plugin: server - now escapes from parent process
diff --git a/src/core_commands.php b/src/core_commands.php
index dd1e21b..8314b72 100644
--- a/src/core_commands.php
+++ b/src/core_commands.php
@@ -20,7 +20,7 @@
'Visit this page for more information.') : false;
//---------------------------------------------------------------------------------------------------------
-function CoreCmd_Seen()
+function plugin_seen()
{
if (OnEmptyArg('seen to check specified user when was last seen on channel')) {
} else { /* prevent directory traversal */
@@ -39,8 +39,6 @@ function CoreCmd_Seen()
response(file_get_contents(DATADIR."/SEEN/{$GLOBALS['args']}")) : response('No such user in my database.');
}
-
- cliLog("[PLUGIN: seen] Used by: {$GLOBALS['USER']} ({$GLOBALS['USER_HOST']}), channel: ".getBotChannel());
}
}
//---------------------------------------------------------------------------------------------------------
@@ -61,7 +59,7 @@ function SeenSave()
@file_put_contents($seenDataDir.$GLOBALS['USER'], $data) : @file_put_contents($seenDataDir.$GLOBALS['USER'], $data);
}
//---------------------------------------------------------------------------------------------------------
-function CoreCmd_Pause()
+function plugin_pause()
{
response('Pausing all activity');
@@ -72,7 +70,7 @@ function CoreCmd_Pause()
cliLog('[bot] Im in Pause mode');
}
//---------------------------------------------------------------------------------------------------------
-function CoreCmd_Unpause()
+function plugin_unpause()
{
if (isset($GLOBALS['stop'])) {
unset($GLOBALS['stop']);
@@ -85,7 +83,7 @@ function CoreCmd_Unpause()
}
}
//---------------------------------------------------------------------------------------------------------
-function CoreCmd_Panel()
+function plugin_panel()
{
if (OnEmptyArg('panel to list commands')) {
} else {
@@ -138,7 +136,7 @@ function CoreCmd_Panel()
cliLog("[PLUGIN: panel] Used by: {$GLOBALS['USER']} ({$GLOBALS['USER_HOST']}), channel: ".getBotChannel());
}
//---------------------------------------------------------------------------------------------------------
-function CoreCmd_Load()
+function plugin_load()
{
if (empty($GLOBALS['args'])) {
response("Usage {$GLOBALS['CONFIG_CMD_PREFIX']}load ");
@@ -147,7 +145,7 @@ function CoreCmd_Load()
}
}
//---------------------------------------------------------------------------------------------------------
-function CoreCmd_Unload()
+function plugin_unload()
{
if (empty($GLOBALS['args'])) {
response("Usage {$GLOBALS['CONFIG_CMD_PREFIX']}unload ");
@@ -217,8 +215,8 @@ function CoreCmd_RegisterToBot()
}
} else {
$hashed = hash('sha256', $GLOBALS['args']);
- /* if user is already an owner */
- $hashed == $GLOBALS['CONFIG_OWNER_PASSWD'] ? response('You are already my owner') : false;
+ /* if user is already an owner */
+ $hashed == $GLOBALS['CONFIG_OWNER_PASSWD'] ? response('You are already my owner') : false;
}
}
} catch (Exception $e) {
diff --git a/src/ctcp.php b/src/ctcp.php
index 0f51ca4..71a59ab 100644
--- a/src/ctcp.php
+++ b/src/ctcp.php
@@ -20,7 +20,16 @@
'Visit this page for more information.') : false;
//---------------------------------------------------------------------------------------------------------
-function CTCP()
+function if_CTCP()
+{
+ global $rawcmd;
+
+ if (empty($GLOBALS['stop']) && $GLOBALS['CONFIG_CTCP_RESPONSE'] == 'yes' && isset($rawcmd[1][0]) && $rawcmd[1][0] == '') {
+ on_CTCP();
+ }
+}
+//---------------------------------------------------------------------------------------------------------
+function on_CTCP()
{
switch ($GLOBALS['rawcmd'][1]) {
case 'version':
@@ -59,16 +68,14 @@ function CTCP()
break;
case 'ping':
- $a = str_replace(' ', '', $GLOBALS['args']);
- toServer("NOTICE {$GLOBALS['USER']} :PING {$a}");
+ toServer("NOTICE {$GLOBALS['USER']} :PING ".str_replace(' ', '', $GLOBALS['args']));
cliLog("[bot] ctcp PING by: {$GLOBALS['USER']} ({$GLOBALS['USER_HOST']})");
PlaySound('ctcp.mp3');
break;
case 'time':
- $a = date("F j, Y, g:i a");
- toServer("NOTICE {$GLOBALS['USER']} :TIME {$a}");
+ toServer("NOTICE {$GLOBALS['USER']} :TIME ".date("F j, Y, g:i a"));
cliLog("[bot] ctcp TIME by: {$GLOBALS['USER']} ({$GLOBALS['USER_HOST']})");
PlaySound('ctcp.mp3');
diff --git a/src/define.php b/src/define.php
index e1681c9..e3c7546 100644
--- a/src/define.php
+++ b/src/define.php
@@ -19,7 +19,7 @@
exit('This script can\'t be run from a web browser. Use CLI terminal to run it
'.
'Visit this page for more information.') : false;
//---------------------------------------------------------------------------------------------------------
- define('VER', '1.1.4');
+ define('VER', '1.1.5');
//---------------------------------------------------------------------------------------------------------
define('START_TIME', time());
define('PHP_VER', phpversion());
diff --git a/src/events.php b/src/events.php
index 1aa602a..56b4cea 100644
--- a/src/events.php
+++ b/src/events.php
@@ -20,6 +20,24 @@
'Visit this page for more information.') : false;
//---------------------------------------------------------------------------------------------------------
+function if_REPLY()
+{
+ global $rawDataArray;
+
+ if (isset($rawDataArray[1]) && is_numeric($rawDataArray[1])) {
+ function_exists('on_'.$rawDataArray[1]) ? call_user_func('on_'.$rawDataArray[1]) : false;
+ }
+}
+//---------------------------------------------------------------------------------------------------------
+function if_OPERATION()
+{
+ global $rawDataArray;
+
+ if (isset($rawDataArray[1]) && in_array($rawDataArray[1], ['JOIN', 'PART', 'KICK', 'TOPIC', 'PRIVMSG', 'NICK', 'QUIT', 'MODE'])) {
+ function_exists('on_'.$rawDataArray[1]) ? call_user_func('on_'.$rawDataArray[1]) : false;
+ }
+}
+//---------------------------------------------------------------------------------------------------------
function on_server_ping()
{
/* send PONG */
@@ -28,10 +46,8 @@ function on_server_ping()
//---------------------------------------------------------------------------------------------------------
function on_001() /* server message */
{
- /* :server.name 001 minion :Welcome to the Testnet IRC Network minion!minion@localhost */
-
/* 1.set server name */
- $GLOBALS['serverName'] = $GLOBALS['rawDataArray'][0];
+ setServerName($GLOBALS['rawDataArray'][0]);
/* 1.set bot nickname */
setBotNickname($GLOBALS['rawDataArray'][2]);
@@ -273,7 +289,7 @@ function on_quit()
//---------------------------------------------------------------------------------------------------------
function on_TOPIC() /* topic change */
{
- cliLog('['.getBotChannel().'] * '.$GLOBALS['USER'].'('.$GLOBALS['USER_HOST'].') sets topic: "'.inputFromLine('3').'"');
+ cliLog('['.getBotChannel().'] * '.$GLOBALS['USER'].' ('.$GLOBALS['USER_HOST'].') sets topic: "'.inputFromLine('3').'"');
}
//---------------------------------------------------------------------------------------------------------
function on_privmsg()
diff --git a/src/plugins.php b/src/plugins.php
index 8f7fc9c..88819d6 100644
--- a/src/plugins.php
+++ b/src/plugins.php
@@ -20,6 +20,48 @@
'Visit this page for more information.') : false;
//---------------------------------------------------------------------------------------------------------
+function if_PLUGIN()
+{
+ global $rawcmd;
+ global $rawDataArray;
+ global $mask;
+
+ /* Unpause -OWNER- core command */
+ (HasOwner($mask) && isset($rawcmd[1]) && $rawcmd[1] == $GLOBALS['CONFIG_CMD_PREFIX'].'unpause') ? plugin_Unpause() : false;
+
+ if (empty($GLOBALS['stop'])) {
+ /* register to bot - core command */
+ (isset($rawcmd[1]) && $rawcmd[1] == 'register' && $rawDataArray[2] == getBotNickname()) ? CoreCmd_RegisterToBot() : false;
+ //---------------------------------------------------------------------------------------------------------
+ /* response to plugins requests */
+ if (isset($rawcmd[1][0]) && $rawcmd[1][0] == $GLOBALS['CONFIG_CMD_PREFIX']) {
+ $pluginReq = str_replace($GLOBALS['CONFIG_CMD_PREFIX'], '', $rawcmd[1]);
+ $p = $GLOBALS['CONFIG_CMD_PREFIX'];
+
+ /* OWNER */
+ if (HasOwner($mask) && in_array_r($rawcmd[1], [$p.'seen', $p.'panel', $p.'load', $p.'unload', $p.'pause',
+ $GLOBALS['OWNER_PLUGINS'], $GLOBALS['ADMIN_PLUGINS'], $GLOBALS['USER_PLUGINS']])) {
+ call_user_func('plugin_'.$pluginReq);
+ pluginUsageCli($pluginReq);
+ /* ADMIN */
+ } elseif (!HasOwner($mask) && HasAdmin($mask) && in_array_r($rawcmd[1], [$p.'seen', $GLOBALS['ADMIN_PLUGINS'], $GLOBALS['USER_PLUGINS']])) {
+ call_user_func('plugin_'.$pluginReq);
+ pluginUsageCli($pluginReq);
+ /* USER */
+ } elseif (!HasOwner($mask) && !HasAdmin($mask) && in_array_r($rawcmd[1], [$p.'seen', $GLOBALS['USER_PLUGINS']])) {
+ call_user_func('plugin_'.$pluginReq);
+ pluginUsageCli($pluginReq);
+ }
+
+ if (!function_exists('plugin_')) {
+ function plugin_()
+ {
+ }
+ }
+ }
+ }
+}
+//---------------------------------------------------------------------------------------------------------
function LoadPlugins()
{
$CountedOwner = count(glob("PLUGINS/OWNER/*.php", GLOB_BRACE));
diff --git a/src/socket.php b/src/socket.php
index 944da02..cbf1682 100644
--- a/src/socket.php
+++ b/src/socket.php
@@ -106,10 +106,8 @@ function SocketLoop()
/* put raw data to array */
$rawDataArray = explode(' ', trim($rawData));
//---------------------------------------------------------------------------------------------------------
- /* PING PONG game */
- if (isset($rawDataArray[0]) && $rawDataArray[0] == 'PING') {
- on_server_ping();
- }
+ /* if ping -> response */
+ (isset($rawDataArray[0]) && $rawDataArray[0] == 'PING') ? on_server_ping() : false;
//---------------------------------------------------------------------------------------------------------
/* parse vars from rawDataArray[0] */
if (preg_match('/^:(.*)\!(.*)\@(.*)$/', $rawDataArray[0], $source)) {
@@ -119,29 +117,8 @@ function SocketLoop()
$USER_HOST = $USER_IDENT.'@'.$host;
}
//---------------------------------------------------------------------------------------------------------
- /* ON JOIN */
- isset($rawDataArray[1]) && $rawDataArray[1] == 'JOIN' ? on_join() : false;
-
- /* ON PART */
- isset($rawDataArray[1]) && $rawDataArray[1] == 'PART' ? on_part() : false;
-
- /* ON KICK */
- isset($rawDataArray[1]) && $rawDataArray[1] == 'KICK' ? on_kick() : false;
-
- /* ON TOPIC */
- isset($rawDataArray[1]) && $rawDataArray[1] == 'TOPIC' ? on_TOPIC() : false;
-
- /* ON PRIVMSG */
- isset($rawDataArray[1]) && $rawDataArray[1] == 'PRIVMSG' ? on_privmsg() : false;
-
- /* ON NICK */
- isset($rawDataArray[1]) && $rawDataArray[1] == 'NICK' ? on_nick() : false;
-
- /* ON QUIT */
- isset($rawDataArray[1]) && $rawDataArray[1] == 'QUIT' ? on_quit() : false;
-
- /* ON MODE */
- isset($rawDataArray[1]) && $rawDataArray[1] == 'MODE' ? on_mode() : false;
+ /* if operation (JOIN,PART,etc) -> response */
+ if_OPERATION();
//---------------------------------------------------------------------------------------------------------
if (count($rawDataArray) < 4) {
continue;
@@ -168,135 +145,14 @@ function SocketLoop()
isset($pieces[2]) ? $piece3 = $pieces[2] : $piece3 = '';
isset($pieces[3]) ? $piece4 = $pieces[3] : $piece4 = '';
//---------------------------------------------------------------------------------------------------------
- if (isset($rawDataArray[1])) {
- switch ($rawDataArray[1]) {
- case '001': /* server welcome message */
- on_001();
- break;
- case '002': /* host, version server */
- on_002();
- break;
- case '003': /* server creation time */
- on_003();
- break;
- case '303': /* ison */
- on_303();
- break;
- case '331': /* topic */
- on_331();
- break;
- case '332': /* topic */
- on_332();
- break;
- case '433': /* if nick already exists */
- on_432();
- break;
- case '432': /* if nick reserved */
- on_432();
- break;
- case '422': /* join if no motd */
- on_376();
- break;
- case '376': /* join after motd */
- on_376();
- break;
- case '324': /* channel modes */
- on_324();
- break;
- case '353': /* on channel join inf */
- on_353();
- break;
- case '366': /* on end names list */
- on_366();
- break;
- case '471': /* if +limit on channel */
- on_471();
- break;
- case '473': /* if +invite on channel */
- on_473();
- break;
- case '474': /* if bot +banned on channel */
- on_474();
- break;
- case '475': /* if +key on channel */
- on_475();
- break;
- }
- }
-//---------------------------------------------------------------------------------------------------------
- /* response to CTCP request */
- if (empty($GLOBALS['stop']) && $GLOBALS['CONFIG_CTCP_RESPONSE'] == 'yes' && isset($rawcmd[1][0]) && $rawcmd[1][0] == '') {
- CTCP();
- }
-//---------------------------------------------------------------------------------------------------------
- if (isset($rawcmd[1][0]) && $rawcmd[1][0] == $GLOBALS['CONFIG_CMD_PREFIX']) {
- $pluginRequest = true;
- $pluginName = str_replace($GLOBALS['CONFIG_CMD_PREFIX'], '', $rawcmd[1]);
- } else {
- $pluginRequest = false;
- unset($pluginName);
- }
+ /* if reply (001,002,etc) -> response */
+ if_REPLY();
-//---------------------------------------------------------------------------------------------------------
- /* Core command: "register 'password'" */
- if (empty($GLOBALS['stop']) && isset($rawcmd[1]) && $rawcmd[1] == 'register' && $rawDataArray[2] == getBotNickname()) {
- CoreCmd_RegisterToBot();
- }
+ /* if CTCP request -> response */
+ if_CTCP();
- /* response to core command: 'Unpause' */
- if (HasOwner($mask) && isset($rawcmd[1]) && $rawcmd[1] == $GLOBALS['CONFIG_CMD_PREFIX'].'unpause') {
- CoreCmd_Unpause();
- }
-//---------------------------------------------------------------------------------------------------------
- /* response to core plugins */
- if (empty($GLOBALS['stop']) && $pluginRequest == true) {
- /* Core command: 'Panel' */
- if (HasOwner($mask) && $rawcmd[1] == $GLOBALS['CONFIG_CMD_PREFIX'].'panel') {
- CoreCmd_Panel();
- }
- /* Core command: 'Load' */
- if (HasOwner($mask) && $rawcmd[1] == $GLOBALS['CONFIG_CMD_PREFIX'].'load') {
- CoreCmd_Load();
- }
- /* Core command: 'Unload' */
- if (HasOwner($mask) && $rawcmd[1] == $GLOBALS['CONFIG_CMD_PREFIX'].'unload') {
- CoreCmd_Unload();
- }
- /* Core command: 'Pause' */
- if (HasOwner($mask) && $rawcmd[1] == $GLOBALS['CONFIG_CMD_PREFIX'].'pause') {
- CoreCmd_Pause();
- }
- /* Core commands: 'Seen' */
- if ($rawcmd[1] == $GLOBALS['CONFIG_CMD_PREFIX'].'seen') {
- CoreCmd_Seen();
- }
-//---------------------------------------------------------------------------------------------------------
- /* response to plugins */
- if (HasOwner($mask)) {
- $ownerPlugs = [$GLOBALS['OWNER_PLUGINS'], $GLOBALS['ADMIN_PLUGINS'], $GLOBALS['USER_PLUGINS']];
- if (in_array_r($rawcmd[1], $ownerPlugs)) {
- call_user_func('plugin_'.$pluginName);
- pluginUsageCli($pluginName);
- }
- } elseif (!HasOwner($mask) && HasAdmin($mask)) {
- $adminPlugs = [$GLOBALS['ADMIN_PLUGINS'], $GLOBALS['USER_PLUGINS']];
- if (in_array_r($rawcmd[1], $adminPlugs)) {
- call_user_func('plugin_'.$pluginName);
- pluginUsageCli($pluginName);
- }
- } elseif (!HasOwner($mask) && !HasAdmin($mask)) {
- if (in_array_r($rawcmd[1], $GLOBALS['USER_PLUGINS'])) {
- call_user_func('plugin_'.$pluginName);
- pluginUsageCli($pluginName);
- }
- }
-
- if (!function_exists('plugin_')) {
- function plugin_()
- {
- }
- }
- }
+ /* if plugin request -> response */
+ if_PLUGIN();
//---------------------------------------------------------------------------------------------------------
}
/* if disconected */
@@ -390,3 +246,17 @@ function getBotChannel()
return $GLOBALS['BOT_CHANNEL'];
}
}
+//---------------------------------------------------------------------------------------------------------
+function setBotChannel($channel)
+{
+ global $botChannel;
+
+ $botChannel = $channel;
+}
+//---------------------------------------------------------------------------------------------------------
+function setServerName($name)
+{
+ global $serverName;
+
+ $serverName = $name;
+}
\ No newline at end of file