[ASECO2.x] Plugin | JokeBot

This forum is dedicated to the Aseco/Rasp 2 server records and control script by Flo and Assembler Maniac. Announcements and issues can be discussed in this forum.

Moderators: Flo, Assembler Maniac, f*ckfish, TM-Patrol

Post Reply
User avatar
J-S
happy cruiser
happy cruiser
Posts: 149
Joined: 24 Apr 2008 18:20
Owned TM-games: TMN,TMUF,TMO,TMS
Manialink(s): shark
Location: Grenoble - France
Contact:

[ASECO2.x] Plugin | JokeBot

Post by J-S » 01 Jun 2008 18:51

JokeBot

Works with ASECO2.x
Description: It's a bot who gives some jokes :wink: when you use the command '/joke'.

Thanks to Oliverde8 and Assembler Maniac who help me, I took pieces of Chatbot. :roll:

JokeBot in chat :

Image

Installation :
- Put plugin in plugins directory.
- Edit plugins.xml and add this line :

Code: Select all

<plugin>plugin.jokebot.php</plugin>
Edit xml files to add jokes or riddles (question and answer), change parameters, or change name's bot...


Download (rar contains xml files and plugin):
  • JokeBot v1.20
    - Fixed a loop problem
    - Changed Xml files to improve reading
    - Added Categories
    - Added /joke <Categorie_Name> command
    - Added /joke default to put the plugin in default settings when you have loaded a categorie !
    - Added /jokecategories to list categories
    - Added /joke on to put the plugin on
    - Added /joke off to put the plugin of
    - Added /jokehelp
    - Added "loopshowjoketime" to allow joke loop (put to 0 if you don't want loop ...)
=====================================
My others plugins :
Quizbot: here
InfoTeam: here
Lottery : here
Betting Forever : In dev and beta testing ...
Last edited by J-S on 17 Aug 2008 12:59, edited 5 times in total.

Ptitzizi
road tourist
road tourist
Posts: 104
Joined: 03 May 2008 15:13
Owned TM-games: TMF

Re: [ASECO2.x] Plugin | JokeBot

Post by Ptitzizi » 01 Jun 2008 21:02

Lol JS :D
I'll try it, it seems to be fun :D

calsmurf2904
smooth traffic navigator
smooth traffic navigator
Posts: 199
Joined: 08 Jul 2008 15:23
Owned TM-games: TMNF,TMN
Location: Netherlands
Contact:

Re: [ASECO2.x] Plugin | JokeBot

Post by calsmurf2904 » 25 Jul 2008 17:20

I hope you don't mind but i edited your code so that it automatically shows an joke....not when you use the /joke command

Code: Select all

<?php

/* plugin.jokebot.php

 Original idea (and some text) from JS many other contributors have had hands in this like Oliverde8 (Thanks to him, he helps me to implement the methode OnMainLoop) and Assembler Maniac who explain me the utility of Function.

 edit jokebot.xml to change words/phrases/general settings

 */

class JokeBot extends Plugin
	{
	private $TimeSend = array();
	private $last;
      private $showjoketime;
	
	private $textmsgs = array();
	private $sentencecut;
	private $BotTag;
	

	function loadSettings()
		{
		$settings = $this->Aseco->xml_parser->parseXML('jokebot.xml'); //We parse the xml file

		$settings = $settings['SETTINGS'];// We take the settings
            
		
		$i=0;
		while(!empty($settings['WATCHFOR'][0]['TEXT'][$i]))
			{
			$this->textmsgs[] = $settings['WATCHFOR'][0]['TEXT'][$i];// We put the jokes in a table to exploit these
			$i++;
			}
		$this->BotTag = $settings['BOTTAG'][0];// We put the name of the bot in a variable
            $this->time = 0;
            $this->showjoketime = ($settings['SHOWJOKETIME'][0])*60;
		}

	function chatJoke(&$command = null){

		$stop=false;
		while(!$stop){
			$n=array_rand($this->textmsgs);
			if($this->textmsgs[$n]!=$this->last){
				$stop=true;
			}
		}
		$test123 = '?.'; // the character use to cut the question and answer for riddle
		$sentencetocut = $this->textmsgs[$n];// we put the joke in a variable
		$pos1 = stripos($this->textmsgs[$n], $test123); //We test if the joke contain the special character '?.'
		if ( $pos1 === false){ //if not
			$this->message = $this->BotTag . $this->textmsgs[$n];

			$this->Aseco->client->query("ChatSendServerMessage", $this->message);// We send the joke
		}
		else {//Else it's a riddle with question and anwser
			$this->TimeSend[0]=	$this->Aseco->getUptime();//We take the time 
			$this->sentencecut = explode("?.", $this->textmsgs[$n],2); // we cut the riddle to have got question and answer
			$this->message = $this->BotTag . $this->sentencecut[0];

			$this->Aseco->client->query("ChatSendServerMessage", $this->message); // We send the first part (the question)
			}
	}
	
	function send_when_time(){ //The function which send when time has come to deliver the answer
		if(!isset($this->TimeSend[0])) return;
	      
		$uptime=$this->Aseco->getUptime();// We take the time

		if($uptime-($this->TimeSend[0])>10){// We look if 10 has passed
			
			$this->Aseco->client->query("ChatSendServerMessage", $this->BotTag . $this->sentencecut[1]);//We send the answer of riddle (the second part)
			
			$i=0;
			while(isset($this->TimeSend[$i+1])){
				$this->TimeSend[$i]=$this->TimeSend[$i+1];
				unset($this->TimeSend[$i+1]);
				$i++;
			}
			//means no next to show must delete 0
			if($i==0){
				unset($this->TimeSend[$i]);			
			}
		
		}
	}

     function show_joke(){
     if ($this->time!=$this->showjoketime){
     $this->time = $this->time+1;
     }else{
     $this->chatJoke();
     $this->time = 0;
     }
     }
}


$_PLUGIN = new JokeBot();
$_PLUGIN->setAuthor('JS');
$_PLUGIN->setVersion(1.0);
$_PLUGIN->setDescription('Bot that tell blague');
$_PLUGIN->addChatCommand('joke', 'chatJoke', 'give some jokes');
$_PLUGIN->addChatCommand('admin jokebotrestart', 'loadSettings', 'Reload jokebot with current settings from jokebot.xml');
$_PLUGIN->addEvent('onMainLoop', 'show_joke');
$_PLUGIN->addEvent('onMainLoop', 'send_when_time');
$_PLUGIN->addEvent('onStartup', 'loadSettings');
?>
You need to add <showjoketime>180</showjoketime> to your xml file.
Image
Current Projects :
Aseco 2.x Dedimania plugin
Aseco 2.x Clan management Plugin
Servers :
LSR Race Server
Server Specs :
TmForever Server 2.11.16 05-08-08 (D-M-Y)
Xaseco 1.03 with FufiMenu and FufiWidgets

User avatar
J-S
happy cruiser
happy cruiser
Posts: 149
Joined: 24 Apr 2008 18:20
Owned TM-games: TMN,TMUF,TMO,TMS
Manialink(s): shark
Location: Grenoble - France
Contact:

Re: [ASECO2.x] Plugin | JokeBot

Post by J-S » 28 Jul 2008 18:16

ok Thanks calsmurf2904 :thumbsup:

I edit my package to add your modification :wink:

User avatar
J-S
happy cruiser
happy cruiser
Posts: 149
Joined: 24 Apr 2008 18:20
Owned TM-games: TMN,TMUF,TMO,TMS
Manialink(s): shark
Location: Grenoble - France
Contact:

Re: [ASECO2.x] Plugin | JokeBot

Post by J-S » 13 Aug 2008 17:17

I publish a new release which bring a lot of new feature !
The xml file's architecture has been changed...
  • JokeBot v1.20
    - Fixed a loop problem
    - Changed Xml files to improve reading
    - Added Categories
    - Added /joke <Categorie_Name> command
    - Added /joke default to put the plugin in default settings when you have loaded a categorie !
    - Added /jokecategories to list categories
    - Added /joke on to put the plugin on
    - Added /joke off to put the plugin of
    - Added /jokehelp
    - Added "loopshowjoketime" to allow joke loop (put to 0 if you don't want loop ...)
If you see suggestions or bugs, do not hesitate to communicate them.

(the link is in the first post ...)

Post Reply