Skip to content

Commit

Permalink
0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
S3x0r committed Aug 29, 2017
1 parent a33782b commit b2c2100
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 64 deletions.
34 changes: 23 additions & 11 deletions BOT.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
//------------------------------------------------------------------------------------------------
define('VER', '0.3.0');
define('VER', '0.3.1');
define('START_TIME',time());
//------------------------------------------------------------------------------------------------
Start();
//------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -103,7 +104,6 @@ function LoadConfig()

SaveData('../data.ini', 'DATA', 'nickname', $GLOBALS['C_NICKNAME']); /* saving nickname to data file */
$GLOBALS['RND_NICKNAME'] = $GLOBALS['C_NICKNAME'].'|'.rand(0,99); /* set random nickname */
$GLOBALS['StartTime'] = time(); /* starting time */

CLI_MSG("1. Configuration Loaded from: CONFIG.INI");

Expand Down Expand Up @@ -230,12 +230,14 @@ function Engine()
global $hostname;
global $piece1;
global $piece2;
global $ex;
global $rawcmd;

/* main socket loop */
while(1) {
while(!feof($GLOBALS['socket'])) {
$mask = NULL;
$data = fgets ($GLOBALS['socket'], 512);
$data = fgets($GLOBALS['socket'], 512);
if($GLOBALS['C_SHOW_RAW'] == 'yes') { echo $data; }

flush();
Expand Down Expand Up @@ -282,12 +284,12 @@ function Engine()
}
}
//---
if (count ($ex) < 4)
continue;
$rawcmd = explode (':', $ex[3]);
$args = NULL; for ($i = 4; $i < count($ex); $i++) { $args .= $ex[$i] . ''; }
//new
$args1 = NULL; for ($i = 4; $i < count($ex); $i++) { $args1 .= $ex[$i] . ' '; }
if(count ($ex) < 4)
continue;

$rawcmd = explode (':', $ex[3]);
$args = NULL; for($i=4; $i < count($ex); $i++) { $args .= $ex[$i].''; }
$args1 = NULL; for($i=4; $i < count($ex); $i++) { $args1 .= $ex[$i].' '; }

$pieces = explode(" ", $args1);
$piece1 = $pieces[0];
Expand Down Expand Up @@ -328,8 +330,7 @@ function Engine()
CLI_MSG('* '.$nick.' ('.$ident.'@'.$host.') Quit');
//todo:save_to_database(); /* Saving to database -> !seen */
break;

}
}

/* CTCP */
if($GLOBALS['C_CTCP_RESPONSE'] == 'yes') {
Expand Down Expand Up @@ -387,6 +388,17 @@ function Engine()
}
}
//------------------------------------------------------------------------------------------------
function msg_without_command()
{
$input = NULL;
for($i=3; $i <= (count($GLOBALS['ex'])); $i++) { $input .= $GLOBALS['ex'][$i]." "; }

$in = rtrim($input);
$data = str_replace($GLOBALS['rawcmd'][1].' ', '', $in);

return $data;
}
//------------------------------------------------------------------------------------------------
function HasAccess($mask)
{
global $admins;
Expand Down
2 changes: 1 addition & 1 deletion CONFIG.INI
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ command_prefix = '!'

[CTCP]
ctcp_response = 'yes'
ctcp_version = 'davybot (0.3.0)'
ctcp_version = 'davybot (0.3.1)'
ctcp_finger = 'davybot'

[FETCH]
Expand Down
6 changes: 6 additions & 0 deletions DOCS/CHANGELOG.TXT
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

v0.3.1 changes (29.08.2017):
- corrected start time
- new plugin: !winamp - you can now control winamp by bot :)
- save plugin code cleanup
- topic plugin bug fixed

v0.3.0 changes (25.08.2017):
- changed from 'password' to -> 'register <password_from_config>'
- new plugin: !weather -- Shows actual weather: !weather <city>
Expand Down
77 changes: 35 additions & 42 deletions PLUGINS/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
function plugin_save()
{

if(empty($GLOBALS['args'])) { CHANNEL_MSG('Usage: '.$GLOBALS['C_CMD_PREFIX'].'save help to list commands'); }
if(empty($GLOBALS['args'])) { CHANNEL_MSG('Usage: '.$GLOBALS['C_CMD_PREFIX'].'save <help> to list commands'); }

else {

if($GLOBALS['args'] == 'help')
{
switch($GLOBALS['args']) {

case "help":
CHANNEL_MSG('Save commands:');
CHANNEL_MSG('save auto_join - Saving auto join on channel when connected: !save auto_join <yes/no>');
CHANNEL_MSG('save auto_rejoin - Saving auto rejoin when kicked from channel: !save auto_rejoin <yes/no>');
Expand All @@ -26,93 +27,85 @@ function plugin_save()
CHANNEL_MSG('save port - Saving port to config: !save port <new_port>');
CHANNEL_MSG('save server - Saving server to config: !save server <new_server>');
CHANNEL_MSG('save try_connect - Saving how many times try connect to server: !save try_connect <value>');
}

if($GLOBALS['piece1'] == 'auto_join')
{
break;

}

switch($GLOBALS['piece1']) {

case "auto_join":
SaveData('../CONFIG.INI', 'CHANNEL', 'auto_join', $GLOBALS['piece2']);
CHANNEL_MSG('Auto_join Saved.');
CLI_MSG('!save auto_join on: '.$GLOBALS['C_CNANNEL'].', New auto_join: '.$GLOBALS['piece2']);
}
break;

if($GLOBALS['piece1'] == 'auto_rejoin')
{
case "auto_rejoin":
SaveData('../CONFIG.INI', 'AUTOMATIC', 'auto_rejoin', $GLOBALS['piece2']);
CHANNEL_MSG('Auto_rejoin Saved.');
CLI_MSG('!save auto_rejoin on: '.$GLOBALS['C_CNANNEL'].', New auto_rejoin: '.$GLOBALS['piece2']);
}
break;

if($GLOBALS['piece1'] == 'channel')
{
case "channel":
SaveData('../CONFIG.INI', 'CHANNEL', 'channel', $GLOBALS['piece2']);
CHANNEL_MSG('Channel Saved.');
CLI_MSG('!save channel on: '.$GLOBALS['C_CNANNEL'].', New channel: '.$GLOBALS['piece2']);
}
break;

if($GLOBALS['piece1'] == 'command_prefix')
{
case "command_prefix":
SaveData('../CONFIG.INI', 'COMMAND', 'command_prefix', $GLOBALS['piece2']);
CHANNEL_MSG('Command_prefix Saved.');
CLI_MSG('!save command_prefix on: '.$GLOBALS['C_CNANNEL'].', New command_prefix: '.$GLOBALS['piece2']);
}
break;

if($GLOBALS['piece1'] == 'connect_delay')
{
case "connect_delay":
SaveData('../CONFIG.INI', 'SERVER', 'connect_delay', $GLOBALS['piece2']);
CHANNEL_MSG('Connect_delay Saved.');
CLI_MSG('!save connect_delay on: '.$GLOBALS['C_CNANNEL'].', New connect_delay: '.$GLOBALS['piece2']);
}
break;

if($GLOBALS['piece1'] == 'fetch_server')
{
case "fetch_server":
SaveData('../CONFIG.INI', 'FETCH', 'fetch_server', $GLOBALS['piece2']);
CHANNEL_MSG('Server Saved.');
CLI_MSG('!save fetch_server on: '.$GLOBALS['C_CNANNEL'].', New server: '.$GLOBALS['piece2']);
}
break;

if($GLOBALS['piece1'] == 'ident')
{
case "ident":
SaveData('../CONFIG.INI', 'BOT', 'ident', $GLOBALS['piece2']);
CHANNEL_MSG('Ident Saved.');
CLI_MSG('!save ident on: '.$GLOBALS['C_CNANNEL'].', New ident: '.$GLOBALS['piece2']);
}
break;

if($GLOBALS['piece1'] == 'name')
{
case "name":
SaveData('../CONFIG.INI', 'BOT', 'name', $GLOBALS['piece2']);
CHANNEL_MSG('Name Saved.');
CLI_MSG('!save name on: '.$GLOBALS['C_CNANNEL'].', New name: '.$GLOBALS['piece2']);
}
break;

if($GLOBALS['piece1'] == 'nick')
{
case "nick":
SaveData('../CONFIG.INI', 'BOT', 'nickname', $GLOBALS['piece2']);
CHANNEL_MSG('Nick Saved.');
CLI_MSG('!save nick on: '.$GLOBALS['C_CNANNEL'].', New nick: '.$GLOBALS['piece2']);
}
break;

if($GLOBALS['piece1'] == 'port')
{
case "port":
SaveData('../CONFIG.INI', 'SERVER', 'port', $GLOBALS['piece2']);
CHANNEL_MSG('Port Saved.');
CLI_MSG('!save port on: '.$GLOBALS['C_CNANNEL'].', New port: '.$GLOBALS['piece2']);
}
break;

if($GLOBALS['piece1'] == 'server')
{
case "server":
SaveData('../CONFIG.INI', 'SERVER', 'server', $GLOBALS['piece2']);
CHANNEL_MSG('Server Saved.');
CLI_MSG('!save server on: '.$GLOBALS['C_CNANNEL'].', New server: '.$GLOBALS['piece2']);
}
break;

if($GLOBALS['piece1'] == 'try_connect')
{
case "try_connect":
SaveData('../CONFIG.INI', 'SERVER', 'try_connect', $GLOBALS['piece2']);
CHANNEL_MSG('Try_connect Saved.');
CLI_MSG('!save try_connect on: '.$GLOBALS['C_CNANNEL'].', New try_connect: '.$GLOBALS['piece2']);
}
break;

}
}
}

?>
11 changes: 4 additions & 7 deletions PLUGINS/topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@

function plugin_topic()
{

if(empty($GLOBALS['args'])) { CHANNEL_MSG('Usage: '.$GLOBALS['C_CMD_PREFIX'].'topic <topic>'); }

else {
$data = trim($GLOBALS['args']);
fputs($GLOBALS['socket'], 'TOPIC '.$GLOBALS['C_CNANNEL'].' '.$data."\n");

CLI_MSG('!topic on: '.$GLOBALS['C_CNANNEL'].', New topic: '.$data);
}
else {
fputs($GLOBALS['socket'], 'TOPIC '.$GLOBALS['C_CNANNEL'].' '.msg_without_command()."\n");
CLI_MSG('!topic on: '.$GLOBALS['C_CNANNEL'].', New topic: \''.msg_without_command().'\'');
}
}

?>
2 changes: 1 addition & 1 deletion PLUGINS/uptime.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
function plugin_uptime()
{
$now = time();
$time = $now - $GLOBALS['StartTime'];
$time = $now - START_TIME;

$year=floor($time/(365*24*60*60));
$time-=$year*(365*24*60*60);
Expand Down
51 changes: 51 additions & 0 deletions PLUGINS/winamp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
if(PHP_SAPI !== 'cli') { die('This script can\'t be run from a web browser. Use CLI to run it.'); }

$plugin_description = 'Controls winamp: !winamp <help>';
$plugin_command = 'winamp';

/*
NEED TO CONFIGURE!
Specify winamp CLAmp.exe program location
*/
$GLOBALS['winamp_loc'] = 'C:\Dokumenty\programy\Winamp\CLAmp.exe';
//---


function plugin_winamp()
{

if(empty($GLOBALS['args'])) { CHANNEL_MSG('Usage: '.$GLOBALS['C_CMD_PREFIX'].'winamp <help> to list commands'); }

else {

switch($GLOBALS['args']) {

case "help":
CHANNEL_MSG('Winamp commands:');
CHANNEL_MSG('winamp stop - Stop music: !winamp stop');
CHANNEL_MSG('winamp pause - Pause music: !winamp pause');
CHANNEL_MSG('winamp play - Play music: !winamp play');
CHANNEL_MSG('winamp next - Next song: !winamp next');
CHANNEL_MSG('winamp prev - Previous song: !winamp prev');
CHANNEL_MSG('winamp title - Show song title: !winamp title');
break;

case "stop": exec($GLOBALS['winamp_loc'].' /stop'); break;
case "pause": exec($GLOBALS['winamp_loc'].' /pause'); break;
case "play": exec($GLOBALS['winamp_loc'].' /play'); sendTitle($target); break;
case "next": exec($GLOBALS['winamp_loc'].' /next'); sendTitle($target); break;
case "prev": exec($GLOBALS['winamp_loc'].' /prev'); sendTitle($target); break;
case "title": sendTitle($target); break;
}
}
}

function sendTitle($target)
{
$title = exec($GLOBALS['winamp_loc'].' /title');
CHANNEL_MSG("Playing: ".$title, $target);
}

?>
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
![Powered by S3x0r](http://minionki.com.pl/powered.png)
### Easy to use IRC BOT in PHP language, ready to use from first time
### Easy to use IRC BOT in PHP language, ready to use from first start

<dl>
<pre>
Expand Down Expand Up @@ -79,5 +79,6 @@ update -- Updates the BOT if new version is available: !update
uptime -- Shows BOT uptime: !uptime
voice -- Gives voice: !voice nick
weather -- Shows actual weather: !weather city
winamp -- Controls winamp: !winamp <help>
</pre>
</dl>
3 changes: 2 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ topic -- Changing Topic in channel: !topic <topic>
update -- Updates the BOT if new version is available: !update
uptime -- Shows BOT uptime: !uptime
voice -- Gives voice: !voice <nick>
weather -- Shows actual weather: !weather <city>
weather -- Shows actual weather: !weather <city>
winamp -- Controls winamp: !winamp <help>

0 comments on commit b2c2100

Please sign in to comment.