Skip to content

Instantly share code, notes, and snippets.

@StarlitGhost
Last active February 28, 2018 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StarlitGhost/6130366 to your computer and use it in GitHub Desktop.
Save StarlitGhost/6130366 to your computer and use it in GitHub Desktop.
The original PHP version of MoronBot!
<?php
/* CHECKS FOR A URL IN THE... URL. GOES TO DEFAULT ONE OTHERWISE */
if (isset($_GET['url']) == true) {
$url=$_GET['url'];
} else {
$url="irc.editingarchive.com";
}
/* CHECKS FOR A CHANNEL IN THE URL. GOES TO DEFAULT ONE OTHERWISE */
if (isset($_GET['channel']) == true) {
$chan="#".$_GET['channel'];
} else {
$chan="#Funland";
}
/* LETS THE BOT RUN INDEFINITELY */
set_time_limit(0);
/* SETS UP SOME USEFUL VARIABLES */
$meh = false;
while ($meh == false) {
$socket=fsockopen("$url",6667);
$nick="MoronBot";
$owner="TyranicMoron";
$home="#Funland";
$goodbye="Bye guys!";
$joined=false;
$meh=true;
}
/* SETS UP SOME RANDOM VARIABLES */
$meh = false;
while ($meh == false) {
$spam=false;
$explode=false;
$guessed=true;
$memorylength=10;
$greet=true;
$convert=array(
"JOIN" => "joined.",
"PRIVMSG" => "said:",
"KICK" => "kicked:",
"PART" => "left.",
"NICK" => "changed their name to:",
"MODE" => "set the mode to:",
"TOPIC" => "set the topic to:"
);
$meh = true;
}
/* JOINS THE SERVER AND CHANNEL, AND SETS THE BOT'S NICKNAME */
fputs($socket,"USER $nick www.tyranicmoron.co.uk Bottiness :Moron McBot\n");
fputs($socket,"NICK $nick\n");
/* BEGINS THE ENDLESS LOOP */
while (1) {
/* GET DATA AND STAY ALIVE */
while ($data = fgets($socket, 1024)) {
$meh = false;
while ($meh == false) {
ob_flush();
flush();
sleep(0.1);
print(nl2br($data));
$ex=explode(' ',$data);
$aftercommands=trim(implode(" ",array_slice($ex,4,count($ex)-1)));
$text=trim(implode(" ",array_slice($ex,3,count($ex)-1)));
$user=explode('!',$ex[0]);
$user=str_replace(':','',$user[0]);
if (!$joined) {
fputs($socket,"JOIN $chan\n");
fputs($socket,"PRIVMSG NickServ :IDENTIFY whitill\n");
$joined=true;
}
if ($ex[0]=="PING") {
fputs($socket,"PONG $ex[1]\n");
}
$meh=true;
}
/* COMMANDS */
$command = str_replace(array(chr(10), chr(13)), '', $ex[3]);
if ($explode == true) {
/* UNFREEZE THE BOT */
if (preg_match("/^\:\!clean\-?up$/i",$command)) {
fputs($socket, "PRIVMSG $ex[2] :*reassembled!*\n");
fputs($socket, "NICK MoronBot\n");
$nick="MoronBot";
$explode=false;
}
/* FREEZE THE BOT */
} elseif (preg_match("/^\:\!explode$/i",$command)) {
fputs($socket, "NICK BombBot\n");
fputs($socket, "PRIVMSG $ex[2] :Kaboom!\n");
$explode=true;
} elseif (preg_match("/^\:\!emo$/i",$command)) {
fputs($socket, "NICK EmoBot\n");
fputs($socket, "PRIVMSG $ex[2] :Goodbye, cruel world!\n");
fputs($socket, "PRIVMSG $ex[2] :*slits his wrists*\n");
fputs($socket, "PRIVMSG $ex[2] :*spurts blood all over the place*\n");
$explode=true;
/* CHECK FOR CHEESE :D */
} elseif (preg_match("/cheese/i",$text) == true) {
fputs($socket, "PRIVMSG $ex[2] :OMG Cheese.\n");
} else {
/* MAIN COMMANDS */
/* ENABLES COMMANDS THROUGH PM */
if ($ex[2] == $nick) {
$ex[2]=trim(str_replace(':','',$command));
$command=":$ex[4]";
$aftercommands=trim(implode(" ",array_slice($ex,5,count($ex)-1)));
}
/* OWNER ONLY */
/* ABORT THE BOT */
if (preg_match("/^\:\!(sepp?ukk?u|suicide|abort|quit|boom|die|kill)$/i",$command)) {
if ($user == $owner) {
fputs($socket, "PRIVMSG $ex[2] :Arrrggghhh!\n");
fputs($socket, "PART $ex[2] :Died\n");
die();
} else {
fputs($socket, "PRIVMSG $ex[2] :YOU FAIL!\n");
}
}
/* CHANGE THE BOT'S NICKNAME */
if (preg_match("/^\:\!nick$/i",$command)) {
if ($user == $owner) {
fputs($socket,"NICK $aftercommands\n");
$nick=$aftercommands;
} else {
fputs($socket, "PRIVMSG $ex[2] :BAD! NAUGHTY! DON'T DO IT!\n");
}
}
/* ANYONE */
/* TELL THE BOT TO JOIN <CHANNEL> */
if (preg_match("/^\:\!join$/i",$command)) {
fputs($socket,"JOIN $aftercommands\n");
}
/* TELL THE BOT TO LEAVE THE CHANNEL */
if (preg_match("/^\:\!(leave|goaway)$/i",$command)) {
if ($ex[2] != $home || $user == $owner) {
fputs($socket,"PART $ex[2] :Fine, I know when I'm not wanted.\n");
} else {
fputs($socket,"KICK $ex[2] $user :Hey, don't try to make me leave my own channel!\n");
}
}
/* LISTS THE COMMANDS */
if (preg_match("/^\:\!commands$/i",$command)) {
fputs($socket, "NOTICE $user :ANYONE: !say, !do, !buy, !time, !date, !join, !leave/!goaway, !memory, !spam - 'stop', !guess, !8ball, !explode/!emo - !clean-up, !help, 'cheese', 'windmill', commands through PM (/msg MoronBot #channel !command text).\n");
fputs($socket, "NOTICE $user :OWNER ONLY: !nick, !abort/!seppuku(diff spellings)/!suicide/!quit/!boom/!die/!kill.\n");
fputs($socket, "NOTICE $user :AUTOMATIC: welcoming people to the channel.\n");
}
/* PROVIDES HELP ON INDIVIDUAL COMMANDS */
if (preg_match("/^\:\!help$/i",$command)) {
if ($aftercommands == "") {
fputs($socket, "NOTICE $user :To see information about a command, type !help !command-name. To get a command listing, type !commands\n");
} elseif (preg_match("/^\:?\!?help$/i",$aftercommands)) {
fputs($socket, "NOTICE $user :USAGE: !help !<command>\n");
fputs($socket, "NOTICE $user :Gives help on command '<command>'\n");
} elseif (preg_match("/^\:?\!?commands$/i",$aftercommands)) {
fputs($socket, "NOTICE $user :USAGE: !commands\n");
fputs($socket, "NOTICE $user :Lists all available commands\n");
} elseif (preg_match("/^\:?\!?say$/i",$aftercommands)) {
fputs($socket, "NOTICE $user :USAGE: !say <text>\n");
fputs($socket, "NOTICE $user :Makes MoronBot say '<text>'\n");
} elseif (preg_match("/^\:?\!?do$/i",$aftercommands)) {
fputs($socket, "NOTICE $user :USAGE: !do <action>\n");
fputs($socket, "NOTICE $user :Makes MoronBot do '<action>'\n");
} elseif (preg_match("/^\:?\!?buy$/i",$aftercommands)) {
fputs($socket, "NOTICE $user :USAGE: !buy <object>\n");
fputs($socket, "NOTICE $user :MoronBot sells you '<object>'\n");
} elseif (preg_match("/^\:?\!?time$/i",$aftercommands)) {
fputs($socket, "NOTICE $user :USAGE: !time\n");
fputs($socket, "NOTICE $user :MoronBot tells you the time on the computer he's running on\n");
} elseif (preg_match("/^\:?\!?date$/i",$aftercommands)) {
fputs($socket, "NOTICE $user :USAGE: !date\n");
fputs($socket, "NOTICE $user :MoronBot tells you the date on the computer he's running on\n");
} elseif (preg_match("/^\:?\!?join$/i",$aftercommands)) {
fputs($socket, "NOTICE $user :USAGE: !join #channel\n");
fputs($socket, "NOTICE $user :Makes MoronBot join the channel '#channel'\n");
} elseif (preg_match("/^\:?\!?(leave|goaway)$/i",$aftercommands)) {
fputs($socket, "NOTICE $user :USAGE: !leave OR !goaway\n");
fputs($socket, "NOTICE $user :Makes MoronBot leave the channel the command is said in\n");
} elseif (preg_match("/^\:?\!?memory$/i",$aftercommands)) {
fputs($socket, "NOTICE $user :USAGE: !memory\n");
fputs($socket, "NOTICE $user :MoronBot tells you the last ten events from the channel.\n");
} elseif (preg_match("/^\:?\!?spam$/i",$aftercommands)) {
fputs($socket, "NOTICE $user :USAGE: !spam <text>\n");
fputs($socket, "NOTICE $user :Makes MoronBot reply with '<text>' whenever someone says anything\n");
} elseif (preg_match("/^\:?\!?stop$/i",$aftercommands)) {
fputs($socket, "NOTICE $user :USAGE: Just say 'stop' anywhere in your message\n");
fputs($socket, "NOTICE $user :Used to stop MoronBot from spamming. He'll spam one last time for good luck though :D\n");
} elseif (preg_match("/^\:?\!?guess$/i",$aftercommands)) {
fputs($socket, "NOTICE $user :USAGE: !guess <range>\n");
fputs($socket, "NOTICE $user :Starts a guessing game. The <range> is optional, default is 100. You can guess by having a number anywhere in your message.\n");
} elseif (preg_match("/^\:?\!?8\-?ball$/i",$aftercommands)) {
fputs($socket, "NOTICE $user :USAGE: !8Ball <text>\n");
fputs($socket, "NOTICE $user :Makes MoronBot chek his 8-Ball for the answer to '<text>'\n");
} elseif (preg_match("/^\:?\!?(explode|emo)$/i",$aftercommands)) {
fputs($socket, "NOTICE $user :USAGE: !explode OR !emo\n");
fputs($socket, "NOTICE $user :Freezes MoronBot - No commands will be executed until the !clean-up command is given\n");
} elseif (preg_match("/^\:?\!?clean\-?up$/i",$aftercommands)) {
fputs($socket, "NOTICE $user :USAGE: !clean-up\n");
fputs($socket, "NOTICE $user :Un-freezes MoronBot. Allows commands to work again after !explode or !emo\n");
} elseif (preg_match("/^\:?\!?nick$/i",$aftercommands)) {
fputs($socket, "NOTICE $user :USAGE: !nick <nickname>\n");
fputs($socket, "NOTICE $user :Changes MoronBot's nickname to '<nickname>'. Owner-only command\n");
} elseif (preg_match("/^\:?\!?(sepp?ukk?u|suicide|abort|quit|boom|die|kill)$/i",$aftercommands)) {
fputs($socket, "NOTICE $user :USAGE: !command (there are too many to list =P)\n");
fputs($socket, "NOTICE $user :Kills MoronBot, ie: Stops execution of his script. He'll no longer be running AT ALL after this command\n");
} else {
fputs($socket, "NOTICE $user :$aftercommands is not a valid command\n");
}
}
/* RANDOM FUNCTIONS OF WIN */
/* ANYONE */
/* ANY TIME WINDMILL IS SAID */
if (preg_match("/windmill/i",$text) == true) {
fputs($socket, "PRIVMSG $ex[2] :WINDMILLS DO NOT WORK THAT WAY!\n");
}
/* FIXING A BUG XD */
if (preg_match("/\!\/boom/",$text) == false) {
/* SAY <TEXT> */
if (preg_match("/^\:\!say$/i",$command)) {
fputs($socket, "PRIVMSG $ex[2] :$aftercommands\n");
}
/* DO <TEXT> */
if (preg_match("/^\:\!do$/i",$command)) {
$string=chr(0x01);
fputs($socket, "PRIVMSG $ex[2] :$string"."ACTION $aftercommands"."$string\n");
}
/* BUY <TEXT> */
if (preg_match("/^\:\!buy$/i",$command)) {
$randprice="£".rand(1,100).".".rand(10,99);
$string="$aftercommands costs $randprice. $randprice has been deducted from your account. Enjoy your \"$aftercommands\".";
fputs($socket, "PRIVMSG $ex[2] :$string\n");
}
/* SPAM <TEXT> UNTIL TOLD TO 'STOP' */
if (preg_match("/^\:\!spam$/i",$command)) {
if ($spam == false) {
if ($aftercommands != "") {
$spamstring=$aftercommands;
} else {
$spamstring="spam";
}
$spamchannel=$ex[2];
$spam=true;
}
}
if ($spam == true) {
if (preg_match("/stop/i",$text) == true) {
$spam=false;
}
fputs($socket, "PRIVMSG $spamchannel :$spamstring\n");
}
/* 8 BALL */
if (preg_match("/^\:\!8\-?ball$/i",$command)) {
if ($aftercommands != "") {
$answerarray=array("Likely","Unlikely","Certain","Impossible","Possible","Doubtful");
$answerpos=rand(1,count($answerarray)-1);
$answer="\"$aftercommands\" is \"$answerarray[$answerpos]\"";
} else {
$answer="You didn't ask anything!";
}
fputs($socket, "PRIVMSG $ex[2] :My 8-Ball says: $answer\n");
}
} else {
fputs($socket, "PRIVMSG $ex[2] :*Bomb defused!*\n");
}
/* TELL THE TIME (LOCAL) */
if (preg_match("/^\:\!time$/i",$command)) {
$string=date("g\:i a");
fputs($socket, "PRIVMSG $ex[2] :It's $string\n");
}
/* TELL THE DATE (LOCAL) */
if (preg_match("/^\:\!date$/i",$command)) {
$string=date("l, jS \of F");
fputs($socket, "PRIVMSG $ex[2] :Today is $string\n");
}
/* MEMORY */
if (preg_match("/^\:\!memory$/i",$command)) {
$file=file("$ex[2].txt");
$file=array_slice($file,count($file)-11);
fputs($socket, "NOTICE $user :The last 10 events in this channel were:\n");
$string="";
foreach ($file as $line) {
fputs($socket, "NOTICE $user :$line");
$string=$string.$line;
}
$fd=fopen("$ex[2].txt","w");
fwrite($fd,$string);
fclose($fd);
}
/* GREETING TOGGLE */
if (preg_match("/^\:\!no\-?greet$/i",$command)) {
if ($greet == true) {
$greet=false;
fputs($socket, "PRIVMSG $ex[2] :Greeting Off\n");
} else {
$greet=true;
fputs($socket, "PRIVMSG $ex[2] :Greeting On\n");
}
}
/* GAMES */
/* ANYONE */
/* GUESS THE NUMBER */
if ($guessed == false) {
if (preg_match("/^\:\!ihateguess$/i",$command)) {
fputs($socket, "PRIVMSG $guesschannel :Ok, we won't play anymore then. The answer was $guessnumber.\n");
$guessed=true;
}
if ((preg_match("/[0-9]+/",$text,$guess) == true) && ($ex[2] == $guesschannel)) {
$guess=implode("",$guess);
$guesscount+=1;
if ($guessnumber == $guess) {
fputs($socket, "PRIVMSG $guesschannel :Well done, $user. The number was $guessnumber. It took you $guesscount guesses.\n");
$guessed=true;
} else {
if ($guess > $guessnumber) {
fputs($socket, "PRIVMSG $guesschannel :$guess is too high.\n");
}
if ($guess < $guessnumber) {
fputs($socket, "PRIVMSG $guesschannel :$guess is too low.\n");
}
}
}
}
if (preg_match("/^\:\!guess$/i",$command)) {
if ($guessed == true) {
if (preg_match("/[0-9]+/",$aftercommands,$range)) {
$range=implode("",$range);
$guessnumber=rand(1,$range);
} else {
$range=100;
$guessnumber=rand(1,$range);
}
if ($guessnumber < 0) {
fputs($socket, "PRIVMSG $ex[2] :Invalid range, please try again.\n");
} else {
$guesschannel=$ex[2];
$guessed=false;
$guesscount=0;
fputs($socket, "PRIVMSG $guesschannel :I've thought of a number between 1 and $range. Care to guess?\n");
}
} else {
fputs($socket, "PRIVMSG $ex[2] :I'm already playing guess in $guesschannel, sorry.\n");
}
}
/* AUTO FUNCTIONS */
/* WELCOME PEOPLE ON JOIN */
if ($ex[1] == "JOIN" && $greet == true) {
$ex[2]=trim(str_replace(':','',$ex[2]));
if ($user == $nick) {
fputs($socket, "PRIVMSG $ex[2] :Hey guys!\n");
} else {
$string="PRIVMSG $ex[2] :Hey $user!\n";
fputs($socket, $string);
}
}
/* AUTO-REJOIN ON KICK */
if ($ex[1] == "KICK" && $ex[3] == $nick) {
fputs($socket,"JOIN $ex[2]\n");
}
/* STORE EVENTS */
if ($user != $url && !preg_match("/^\:\!memory$/i",$command) && preg_match("/^\#/",$ex[2])) {
if (preg_match("/^\:/",$text)) {
$text=substr($text,1);
}
$string=str_replace(array_keys($convert),array_values($convert),$ex[1]);
$fd=fopen("$ex[2].txt","a");
fwrite($fd,"<$user> $string $text\n");
fclose($fd);
}
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment