Archive > BeBot Hyborian support

Trivia Module

<< < (2/4) > >>

Wizhk:
OK so In Settings I now have.

null
-1
null

It still wont find the Trivia questions.

Jiheld:
me too, you sure you have the .txt file in the right folder?

Wizhk:
I have an extras folder in c:/ , c:/bebot , c:/bebot/custom , c:/custom/modules , and maybe a few other places.. lol.

They are all text files and I have added.txt to the name on them all and removed .txt from the name on them all.

Still nothing.

Can you copy and paste your trivia module php file. maybe I have a wrong one.

Wizhk

Jiheld:

--- Quote ---<?php
/*
 * Trivia.php - Module template.
 *
 * Developed by Meathooks and Elesar of the Eldar Guild (http://eldarguild.org)
 *     a Age of Conan Guild on the Dagoth server
 *
 */
   
$trivia = new Trivia($bot);

class trivia Extends BaseActiveModule
{
   function __construct (&$bot)
   {
      parent::__construct(&$bot, get_class($this));

      $this -> register_command('gc', 'trivia', 'MEMBER');

      $this -> help['description'] = 'Trivia Questions and you have to guess the answers.';
      $this -> help['command']['trivia ask']="Displays a random trivia question for you to answer.";
      $this -> help['command']['trivia answer [yourguess]']="Sends your answer to the current trivia question.";
      $this -> help['command']['trivia giveup]']="Sends the answer to the current trivia question.";

      $this -> bot -> core("settings") -> create("Trivia", "Entry", "-1", "");
      $this -> bot -> core("settings") -> create("Trivia", "Question", "*NONE*", "");
      $this -> bot -> core("settings") -> create("Trivia", "Answer", "*NONE*", "");
   }

   function command_handler($name, $msg, $origin)
   {
      if ($msg == "trivia ask")
      {
         $msg = $this->get_trivia();
      }
      elseif ($msg == "trivia giveup")
      {
         $msg = $this->giveup_trivia();
      }
      else if (preg_match("/^trivia answer (.+)$/i", $msg, $info))
      {
         $msg = $this->answer_trivia($info[1], $name);
      }
      else
      {
         $msg = "##highlight##TRIVIA::##end## UNKNOWN COMMAND part of Trivia Module";
      }

      return ($msg);
   }
   
   function get_trivia()
   {
      $trivia_active = $this->bot->core("settings")->get("Trivia","Entry");

      if($trivia_active == -1)
      {
         $handle = fopen("txt/trivia.txt", "r");
         if ($handle)
         {
            while (!feof($handle))
            {
               $buffer = fgets($handle, 8192);

               $pos = strpos($buffer, "*");
               if ($pos !== false)
               {
                  $question = substr($buffer, 0, $pos);
                  $array_questions[] = $question;

                  $answer = substr($buffer, $pos + 1, strlen($buffer) - $pos);
                  $array_answers[] = $answer;
               }
            }
         }

         $trivia_array_max = count($array_questions);

         $trivia_active = rand(0, $trivia_array_max);
         $this->bot->core("settings")->save("Trivia", "Entry", $trivia_active);
         $this->bot->core("settings")->save("Trivia", "Question", $array_questions[$trivia_active]);
         $this->bot->core("settings")->save("Trivia", "Answer", $array_answers[$trivia_active]);
      }

      $question = $this->bot->core("settings")->get("Trivia","Question");

      if ($question != "" and $question != "**NONE**")
      {
         $strmsg = "##highlight##TRIVIA::##end## ##highlight##[Question]##end## " . $question;
         $strmsg .= "\nTo submit your guess for the trivia, type in:   ##highlight##!trivia answer YOURANSWER##end##";
      }
      else
      {
         $strmsg = "##highlight##TRIVIA::##end## No trivia questions were found, please have some added :)";
      }

      return $strmsg;
   }

   function answer_trivia($stranswer, $name)
   {
      $answer = trim($this->bot->core("settings")->get("Trivia","Answer"));

      if ($answer != "" and $answer != "**NONE**")
      {
         if (strcmp(strtolower($answer), strtolower($stranswer)) != 0)
         {
            $strmsg = "##highlight##TRIVIA::##end## " . $name . "'s guess for the trivia question was incorrect ($stranswer), please try again.";
         }
         else
         {
            $strmsg = "##highlight##TRIVIA::##end## " . $name . " answered the trivia question ##highlight##CORRECTLY##end##.  The answer was ##highlight##$answer##end##.  Good Job!  (type '!trivia ask' to ask another question)";
            $this->bot->core("settings")->save("Trivia", "Entry", -1);
            $this->bot->core("settings")->save("Trivia", "Question", "**NONE**");
            $this->bot->core("settings")->save("Trivia", "Answer", "**NONE**");
         }
      }
      else
      {
         $strmsg = "##highlight##TRIVIA::##end## No trivia questions active or found to answer, try !trivia ask";
      }

      return $strmsg;          
   }

   function giveup_trivia($stranswer, $name)
   {
      $answer = trim($this->bot->core("settings")->get("Trivia","Answer"));

      if ($answer != "" and $answer != "**NONE**")
      {
         $strmsg = "##highlight##TRIVIA::##end## You all gave up :( .. lol ... the answer to the trivia question is ##highlight##$answer##end##.";
         $this->bot->core("settings")->save("Trivia", "Entry", -1);
         $this->bot->core("settings")->save("Trivia", "Question", "**NONE**");
         $this->bot->core("settings")->save("Trivia", "Answer", "**NONE**");
      }
      else
      {
         $strmsg = "##highlight##TRIVIA::##end## No trivia questions active or found to answer, try !trivia ask";
      }

      return $strmsg;          
   }
}
?>
--- End quote ---

Wizhk:
Interesting.. your file doesn't point to the extras folder.

Copied and pasted, placed a new trivia.txt in the module folder, did the -1, and all is fine now.

Thanks alot.

Wizhk

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version