Skip to content

Commit

Permalink
simplified the logic in the privmsg hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephMoniz committed Sep 29, 2010
1 parent b240535 commit cfbb792
Show file tree
Hide file tree
Showing 15 changed files with 287 additions and 293 deletions.
6 changes: 3 additions & 3 deletions config.ini
@@ -1,14 +1,14 @@
[nickserv]
nick = "DevLector"
nick = "DevLector2"
registered = TRUE
password = "d|g!74ldrp3pper2012"

[access]
Bren2010[level] = 2
Bren2010[hostmask] = "Bren2010!Bren2010@bren2010.com"

;Thetan[level] = 1
;Thetan[hostmask] = "Thetan`Family!Thetan@HTS-EEB48195.dsl.mindspring.com"
Thetan[level] = 2
Thetan[hostmask] = "Thetan!Thetan@HTS-EEB48195.dsl.mindspring.com"

[lecture]
lector = "Romnous"
Expand Down
56 changes: 28 additions & 28 deletions lector.php
Expand Up @@ -38,7 +38,7 @@
/******************* CODE ********************/
error_reporting(0);

if ($daemon == TRUE) {
if ($daemon) {
if(pcntl_fork()) die(); // This turns the bot into a daemon.
}

Expand All @@ -56,7 +56,7 @@
$mode = "q";
$initiated = FALSE;

if ($record == TRUE) {
if ($record) {
$startTime = time();
$lectureHandle = fopen("recording.log", "w");
}
Expand All @@ -67,31 +67,31 @@

cmd_send("JOIN " . $channel); // Join default channel.

while (1) {
while ($data = fgets($socket)) {
$pingCheck = substr($data, 0, strlen("PING :"));

if ($pingCheck == "PING :") {
$pong = substr($data, strlen("PING :"));
cmd_send("PONG :" . $pong);
} else {
$message = new ircMsg($data);

$command = strtolower($message->getCommand());

$modules->hook($command, $message);


$text = smartResponse($message);

if ($output == TRUE) {
echo $text['text'];
}

if ($record == TRUE && $initiated == TRUE && $text['record'] == TRUE && $text['text'] != "") {
fwrite($lectureHandle, format(time() - $startTime) . " " . $text['text']);
}
}
}
while (!feof($socket)) {
$data = fgets($socket);
$pingCheck = substr($data, 0, strlen("PING :"));

if ($pingCheck == "PING :") {
$pong = substr($data, strlen("PING :"));
cmd_send("PONG :" . $pong);
} else {
$message = new ircMsg($data);

$command = strtolower($message->getCommand());

$modules->hook($command, $message);

$text = smartResponse($message);

if ($output) echo $text['text'];


if ($record && $initiated && $text['record'] && $text['text'] != "") {
fwrite($lectureHandle, format(time() - $startTime) . " " . $text['text']);
}
}
}
echo 'wAT!
';
?>
3 changes: 2 additions & 1 deletion modules.php
Expand Up @@ -69,8 +69,9 @@ public function hook($hook, $message)
{
if (!$this->modules[$hook]) return;

foreach ($this->modules[$hook] as $module)
foreach ($this->modules[$hook] as $name => $module)
{
echo "{$name}\n";
if (!$module['enabled']) continue;
$module['module']($message);
}
Expand Down
44 changes: 21 additions & 23 deletions modules/privmsg/change_position.php
@@ -1,35 +1,33 @@

return function($message) {
global $accessArray;
global $initiated;
global $nick;

$hostmask = $message->getNick() . "!" . $message->getName() . "@" . $message->getHost();

$search = searchAccess($hostmask, $accessArray);

$parameters = $message->getParameters();
$where = $parameters[0];
$command = substr(trim($parameters[1]), 0, 1);;

if ($search !== FALSE && $where == $nick && $command == "c") {
global $initiated;

if ($initiated == TRUE) {
global $channel;
global $position;
global $lecture;
if ($where != $nick) return;

$hostmask = $message->getNick() . "!" . $message->getName() . "@" . $message->getHost();
if (!searchAccess($hostmask, $accessArray)) return;

if ($parameters[1][0] != 'c') return;

if (!$initiated)
return say("Please initiate a lecture to show slides.");

global $channel;
global $position;
global $lecture;

$realPos = trim(substr($parameters[1], 1));
$realPos = trim(substr($parameters[1], 1));

if (!empty($lecture[$realPos])) {
$position = $realPos;
say("Changed slide position to " . $realPos . ".");
} else {
say("The requested slide could not be found.");
}
} else {
say("Please initiate a lecture to show slides.");
}
if (!empty($lecture[$realPos])) {
$position = $realPos;
say("Changed slide position to " . $realPos . ".");
} else {
say("The requested slide could not be found.");
}
}
};
?>
39 changes: 18 additions & 21 deletions modules/privmsg/end_lecture.php
Expand Up @@ -6,30 +6,27 @@

$parameters = $message->getParameters();
$where = $parameters[0];

$hostmask = $message->getNick() . "!" . $message->getName() . "@" . $message->getHost();

$search = searchAccess($hostmask, $accessArray);
if ($where != $nick) return;

$hostmask = $message->getNick() . "!" . $message->getName() . "@" . $message->getHost();
if (!searchAccess($hostmask, $accessArray)) return;

$text = trim($parameters[1]);

if ($where == $nick && $search !== FALSE && $text == "e") {
if ($parameters[1][0] != 'e') return;

if (!$initiated)
return say("No lecture has been initiated.");

if ($initiated == TRUE) {
global $mode;
global $channel;
global $intro;
global $rules;
global $mode;
global $channel;
global $intro;
global $rules;

$initiated = FALSE;
$mode = "q";
$initiated = FALSE;
$mode = "q";

cmd_send("MODE " . $channel . " -m");
talk($channel, "The lecture has come to an end. I hope you enjoyed it and learned something new!");
say("The lecture has been ended.");
} else {
say("No lecture has been initiated.");
}
}
}
cmd_send("MODE " . $channel . " -m");
talk($channel, "The lecture has come to an end. I hope you enjoyed it and learned something new!");
say("The lecture has been ended.");
};
?>
51 changes: 24 additions & 27 deletions modules/privmsg/initiate.php
Expand Up @@ -6,34 +6,31 @@

$parameters = $message->getParameters();
$where = $parameters[0];

$hostmask = $message->getNick() . "!" . $message->getName() . "@" . $message->getHost();

$search = searchAccess($hostmask, $accessArray);

if ($where != $nick) return;

$hostmask = $message->getNick() . "!" . $message->getName() . "@" . $message->getHost();
if (!searchAccess($hostmask, $accessArray)) return;

$text = trim($parameters[1]);
if ($where == $nick && $search !== FALSE && $text == "i") {

if ($initiated == FALSE) {
global $mode;
global $position;
global $channel;
global $intro;
global $rules;
global $startTime;
if ($parameters[1][0] != 'i') return;
if ($initiated)
return say("The lecture has already been initiated.");
global $mode;
global $position;
global $channel;
global $intro;
global $rules;
global $startTime;

$initiated = TRUE;
$mode = "l";
$position = 0;
$startTime = time();
$initiated = TRUE;
$mode = "l";
$position = 0;
$startTime = time();

cmd_send("MODE " . $channel . " +m");
talk($channel, $intro . "\n" . $rules);
say("The lecture has been initiated.");
} else {
say("The lecture has already been initiated.");
}
}
}
cmd_send("MODE " . $channel . " +m");
talk($channel, $intro . "\n" . $rules);
say("The lecture has been initiated.");
};
?>
46 changes: 21 additions & 25 deletions modules/privmsg/lecture_mode.php
Expand Up @@ -6,33 +6,29 @@

$parameters = $message->getParameters();
$where = $parameters[0];

$hostmask = $message->getNick() . "!" . $message->getName() . "@" . $message->getHost();

if ($where != $nick) return;

$hostmask = $message->getNick() . "!" . $message->getName() . "@" . $message->getHost();
if (!searchAccess($hostmask, $accessArray)) return;

$search = searchAccess($hostmask, $accessArray);
if ($parameters[1][0] != 'l') return;

if (!$initiated)
return say("Please initiate a lecture to use this command.");

$text = trim($parameters[1]);

if ($where == $nick && $search !== FALSE && $text == "l") {

if ($initiated == TRUE) {
global $mode;

global $mode;

if ($mode == "q") {
global $channel;
global $lector;
$mode = "l";
if ($mode == "q") {
global $channel;
global $lector;
$mode = "l";

cmd_send("MODE " . $channel . " +m");
talk($channel, "The lecture is now resuming, so please end any off topic discussions and redirect your attention back to " . $lector . ".");
say("The lecture is now in lecture mode.");
} else {
say("The lecture is already in lecture mode.");
}
} else {
say("Please initiate a lecture to use this command.");
}
}
}
cmd_send("MODE " . $channel . " +m");
talk($channel, "The lecture is now resuming, so please end any off topic discussions and redirect your attention back to " . $lector . ".");
say("The lecture is now in lecture mode.");
}
};
?>
44 changes: 21 additions & 23 deletions modules/privmsg/next_slide.php
@@ -1,34 +1,32 @@

return function($message) {
global $accessArray;
global $initiated;
global $nick;

$hostmask = $message->getNick() . "!" . $message->getName() . "@" . $message->getHost();

$search = searchAccess($hostmask, $accessArray);

$parameters = $message->getParameters();
$where = $parameters[0];
$text = trim($parameters[1]);

if ($where != $nick) return;

$hostmask = $message->getNick() . "!" . $message->getName() . "@" . $message->getHost();
if (!searchAccess($hostmask, $accessArray)) return;

if ($parameters[1][0] != 'n') return;

if (!$initiated)
return say("Please initiate a lecture to show slides.");

if ($search !== FALSE && $where == $nick && $text == "n") {
global $initiated;

if ($initiated == TRUE) {
global $channel;
global $position;
global $lecture;
global $channel;
global $position;
global $lecture;

if (!empty($lecture[$position])) {
talk($channel, $lecture[$position]);
say("Played slide " . $position . ".");
$position++;
} else {
say("Out of slides.");
}
} else {
say("Please initiate a lecture to show slides.");
}
if (!empty($lecture[$position])) {
talk($channel, $lecture[$position]);
say("Played slide " . $position . ".");
$position++;
} else {
say("Out of slides.");
}
}
};
?>

0 comments on commit cfbb792

Please sign in to comment.