Formatting of code : You can (and must) use [ tcl ] an [ /tcl ] tags (without spaces in tags) to format your TCL codes and have syntax coloration x


Bartender script (PHP)
#1
Hi,

I will try my luck here, im after someone who can convert a PHP script into TCL script:

PHP Code:
<?php

class serve_mod extends module {

    public 
$title "iRC SerVe";
    public 
$author "g2x3k";
    public 
$version "0.2";

    public function 
init() {
        
// init


        // not working atm .. *TODO
        
$this->serve["settings"]["antispam"] = "1/3"//1 trigger each 3 sec ...
        
$this->serve["settings"]["spamreplies"][] = "Hey hey there dont you think its going a bit to fast there only [since] since youre last ...";
        
$this->serve["settings"]["spamreplies"][] = "iam busy ...";
        
$this->serve["settings"]["spamreplies"][] = "havent you just had ?";
        
$this->serve["settings"]["dateformat"] = "h:i:s";
        
// config of avaible stuff for serving ...
        
        
$this->serve["triggers"]["bar"] = "This Bar have: !coffee !bang !cola !beer !joint !head !mix !whisky !pipe !pussy !coke !icecream";
        
$this->serve["triggers"]["coke"] = "Are you stupid? We doesn't do shit like this... GO SLAP YOUR SELF IN THE NUTS! :P";
        
        
$this->serve["triggers"]["coffee"]  "Making a cup of coffee for [nick], [today] made today of [total] ordered wich make it the [sumtotal] time i make coffee";

        
$this->serve["triggers"]["bang"][]     = "fills a bang from stash and serves it to [nick] ([today]/[total]/[sumtotal])";
        
$this->serve["triggers"]["cola"][]     = "Serves icecold cola ([today]/[total]/[sumtotal])";
        $this->serve["triggers"]["cola"][]     = "Serves cola that been laying in pile of shit ~45c ([today]/[total]/[sumtotal])";
        $this->serve["triggers"]["cola"][]     = "Serves cola been standing close to box of dryice ~1,3c ([today]/[total]/[sumtotal])";
        
$this->serve["triggers"]["cola"][]     = "Serves cola that been standing next to comp for few hrs ([today]/[total]/[sumtotal])";
        
$this->serve["triggers"]["beer"][]     = "Serves icecold beer ([today]/[total]/[sumtotal])";
        
$this->serve["triggers"]["joint"][] = "Grabs a joint to [nick] from the stash ([today]/[total]/[sumtotal])";

        
$this->serve["triggers"]["head"][]     = ".h.e.a.d. ([total])";
        
$this->serve["triggers"]["head"][]     = "head for you sir. ([total])";
        
        $this->serve["triggers"]["wine"][]     = "pours up some fine stuff from the basement ([total])";
        $this->serve["triggers"]["wine"][]     = "here you are, found something out back ([total])";        
        $this->serve["triggers"]["wine"][]     = "lucky you we just got one of this left enjoy ([total])";
        
$this->serve["triggers"]["wine"][]     = "so youre hit hard, where you want it ?, dont cry";
        
        
$this->serve["triggers"]["mix"][]     = "grinding up some weed for a mix ([total])";
        
$this->serve["triggers"]["mix"][]     = "grabs some the good stuff for a mix ([total])";
        
$this->serve["triggers"]["mix"][]     = "sneaks into g2x3ks stash and steals for a mix, here you go ([total])";
        
$this->serve["triggers"]["mix"][]     = "goes strain hunting in india for some good shit for your mix ([total])";
        
$this->serve["triggers"]["mix"][]     = "goes strain hunting in morocco for some good shit for your mix ([total])";

        
$this->serve["triggers"]["pipe"][]     = "goes strain hunting in morocco for some good shit for your pipe ([total])";
        $this->serve["triggers"]["pipe"][]     = "saw some shit in corner, fills a pipe ([total])";
        $this->serve["triggers"]["pipe"][]     = "skunky just arrieved peace all over ([total])";
        
        $this
->serve["triggers"]["whiskey"][]     = "serves whiskey on the rocks ([total])";
        $this->serve["triggers"]["whiskey"][]     = "found some weird looking bottle in corner, might hit gold cheers ([total])";
        $this->serve["triggers"]["whiskey"][]     = "cola and bad whiskey for you ([total])";
        
        $this
->serve["triggers"]["pussy"][]    = "slaps [nick] in face with a smelly pussy ([total])";
        
$this->serve["triggers"]["pussy"][] = "Sends some pussy [nick]`s way .. ([total])";
        
$this->serve["triggers"]["pussy"][] = "not enough money to suply you aswell ... ([total])";

        $this->serve["triggers"]["icecream"][]     = "here [nick]... one ball for you only ([today]/[total]/[sumtotal])";
        $this->serve["triggers"]["icecream"][]     = "finds a biig icecream for [nick] eat and you get for free (50$ to use toilet) ([today]/[total]/[sumtotal])";
        $this->serve["triggers"]["icecream"][]     = "dusts off something that look like icecream from the corner of fridge, here [nick] ([today]/[total]/[sumtotal])";
        
// - docu:
        // [nick] = nick that triggered, [today] how many heads/coffee person had today
        // [total] = how many nick had it total, [last] time of last, [since] time since last
        // [sumtotal], [sumchannel], [sumnetwork] = how many all had

        // - reply syntax (random reply) :
        // $this->serve["triggers"]["coffee"]["replies"][] = "some reply here";
        // $this->serve["triggers"]["coffee"]["replies"][] = "another reply here";
        // - reply syntax - two line reply:
        // $this->serve["triggers"]["coffee"]["replies"][1] = "Line 1 of the reply 1";
        // $this->serve["triggers"]["coffee"]["replies"][1] = "Line 2 of the reply 1";
        // $this->serve["triggers"]["coffee"]["replies"][2] = "Line 1 of the reply 2";
        // $this->serve["triggers"]["coffee"]["replies"][2] = "Line 2 of the reply 2";
        // * [1/2] binds the two replies togeter must be incremented

        // - default settings syntax
        // $this->serve["settings"]["antispam"] = "1/3"; //1 trigger each 3 sec ...
        // $this->serve["settings"]["dateformat"] = "h:i:s";
        // - trigger settings syntax (overrides default settings if set)
        // $this->serve["triggers"]["coffee"]["settings"]["antispam"] = "1/60"; one a minute
        // $this->serve["triggers"]["coffee"]["settings"]["spamreplies"][] = "hey stop that iam burning my hands on this coffee ... one per minute shuld be enough";
        // set timer to clear "today" stats every 24hr

        // timer stuff
        //timerinfo for nxt day
        
$args = new argClass();
        
$args->timerid strtotime(date("Y-m-d 00"time()+86400).":00:00");
        
$settimer $args->timerid-time();
        
//start timers
        
$this->ircClass->privMsg("#coders""timer set to run at $args->timerid / ".date("Y-m-d H:i:s",$args->timerid));
        
$this->timerClass->addTimer("serveclear" $args->timerid$this"timer_serve"$args$settimerfalse);

    }

    public function 
timer_serve($args false) {
        
//clear daily stats
        
$res $this->db->query("UPDATE `layer13`.`servestats` SET `today` = '0'");
        
$this->ircClass->privMsg("#coders""cleared serve_today");

        
//timerinfo for nxt day
        
$args = new argClass();
        
$args->timerid strtotime(date("Y-m-d 00"time()+86400).":00:00");
        
$settimer $args->timerid-time();
        
//start timers
        
$this->ircClass->privMsg("#coders""timer set to run at $args->timerid / ".date("Y-m-d H:i:s",$args->timerid));
        
$this->timerClass->addTimer("serveclear" $args->timerid$this"timer_serve"$args$settimerfalse);
    }

    public function 
priv_serve($line$args) {
        
$chan strtolower($line['to']);
        
$nick $line['fromNick'];
        
$address $line["fromIdent"]."@".$line["fromHost"];
        
$network $this->ircClass->getServerConf ("NETWORK");

        
// failsafes ...
        
if (strpos $chan"#" ) === false)
        return;
        if (
$this->ircClass->getStatusRaw () != STATUS_CONNECTED_REGISTERED)
        return;
        if (
$line['to'] == $this->ircClass->getNick())
        return; 
// dont work in private ...
      
        
foreach ($this->serve["triggers"] as $trigger => $reply) {
            if (
preg_match("/(!|\.)$trigger\b/i"$line["text"])) {

                
// parse trigger settings and replies

                
$rid rand(0count($reply)-1);

                if (
is_array($reply)) $reply $reply[$rid];


                
// check for nick in db
                
$ures $this->db->query("SELECT * FROM servestats WHERE nick LIKE ".sqlesc($nick)." AND network LIKE '$network' AND type LIKE ".sqlesc($trigger)." LIMIT 1");
                if (
mysql_num_rows($ures) >= 1) {
                    
$urow mysql_fetch_assoc($ures);

                    
$nres $this->db->query("UPDATE `layer13`.`servestats` SET `today` = today+1, `total` = total+1 WHERE `servestats`.`id` = $urow[id]");

                }
                else {
                    
// check for address in db'
                    
$ures $this->db->query("SELECT * FROM servestats WHERE address LIKE ".sqlesc($address)." AND network LIKE '$network' AND type LIKE ".sqlesc($trigger)."");
                    if (
mysql_num_rows($ures) >= 1) {
                        
$urow mysql_fetch_assoc($ures);
                        
//$this->ircClass->privMsg("$chan", "found in db using address .. setting nick and updateing");
                        
$nres $this->db->query("UPDATE `layer13`.`servestats` SET `today` = today+1, `total` = total+1, `nick` = ".sqlesc($nick)." WHERE `servestats`.`id` = $urow[id]");
                    }
                    else {
                        
// else add
                        //$this->ircClass->privMsg("$chan", "not found in db ($nick - $address) .. adding");
                        
$ires $this->db->query("INSERT INTO `layer13`.`servestats` (`id`, `nick`, `address`, `type`, `last`, `today`, `total`, `channel`, `network`)
                         VALUES (NULL, "
.sqlesc($nick).", ".sqlesc($address).", ".sqlesc($trigger).", UNIX_TIMESTAMP(), '1', '1', ".sqlesc($chan).", ".sqlesc($network).");");
                    }
                }

                
// grab info from db parse reply and return result
                
$ures $this->db->query("SELECT * FROM servestats WHERE nick LIKE ".sqlesc($nick)." AND network LIKE '$network' AND type LIKE ".sqlesc($trigger)." LIMIT 1");
                
$urow mysql_fetch_assoc($ures);
                
//grap totals
                
$tres $this->db->query("SELECT sum(total) as sumtotal, sum(today) as sumtoday  FROM servestats WHERE network LIKE '$network' AND type LIKE ".sqlesc($trigger)." LIMIT 1");
                
$trow mysql_fetch_assoc($tres);

                
$message str_replace(array("[nick]""[today]""[total]""[sumtotal]""[sumtoday]"), array("$nick"$urow["today"], $urow["total"], $trow["sumtotal"],$trow["sumtoday"]), $reply);
                
//lookup nick or insert, update stats and reply
                //$this->ircClass->privMsg("$chan", "trigger: $trigger - $reply @ $chan/$network");
                
$this->ircClass->privMsg("$chan""$message");
            }
        }
    }

    function 
addOrdinalNumberSuffix($num) {
        if (!
in_array(($num 100),array(11,12,13))){
            switch (
$num 10) {
                
// Handle 1st, 2nd, 3rd
                
case 1:  return $num.'st';
                case 
2:  return $num.'nd';
                case 
3:  return $num.'rd';
            }
        }
        return 
$num.'th';
    }
}
?>

SQL shcema
PHP Code:
CREATE TABLE IF NOT EXISTS `servestats` (
  `idint(11NOT NULL AUTO_INCREMENT,
  `nickvarchar(32CHARACTER SET latin1 NOT NULL,
  `addressvarchar(255CHARACTER SET latin1 NOT NULL,
  `typevarchar(255CHARACTER SET latin1 NOT NULL,
  `lastdecimal(11,0NOT NULL,
  `todayint(11NOT NULL,
  `totalint(11NOT NULL,
  `channelvarchar(255CHARACTER SET latin1 NOT NULL,
  `networkvarchar(255CHARACTER SET latin1 NOT NULL,
  PRIMARY KEY (`id`)
ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=

Here is a little how it works : 


Code:
- docu:
[nick] = nick that triggered, [today] how many heads/coffee person had today
[total] = how many nick had it total, [last] time of last, [since] time since last
[sumtotal], [sumchannel], [sumnetwork] = how many all had
Menu:
PHP Code:
$this->serve["triggers"]["bar"] = "This Bar have: !coffee !bang !cola !beer !joint !head !mix !whisky !pipe !pussy !coke !icecream"


PHP Code:
!coffee 


PHP Code:
$this->serve["triggers"]["coffee"]  "Making a cup of coffee for [nick], [today] made today of [total] ordered wich make it the [sumtotal] time i make coffee"

There is also a spam trigger so it dosn't flood a channel
Hope to get some help, as I have no idea to code it myself?
  Reply
#2
You don't really need MySQL as the script is quite simple (and also its datas). For a better portability, a text file (dictionary) or a light DB (sqlite) should be better.
And as eggdrop is mono-server, you don't need the network information.
zeolia: tchat gratuit, sans inscription ni publicité
Merci de ne pas demander d'aide en MP
Away
  Reply
#3
(13/05/2023, 12:25)CrazyCat Wrote: You don't really need MySQL as the script is quite simple (and also its datas). For a better portability, a text file (dictionary) or a light DB (sqlite) should be better.
And as eggdrop is mono-server, you don't need the network information.

Hi, 

thanks for the reply! Something you can do? as I wrote "I have no clue" in scripting Sad
  Reply
#4
I can probably do a little script, it'll help you to learn tcl :)
zeolia: tchat gratuit, sans inscription ni publicité
Merci de ne pas demander d'aide en MP
Away
  Reply
#5
(13/05/2023, 12:45)CrazyCat Wrote: I can probably do a little script, it'll help you to learn tcl :)

Sound great
  Reply
#6
Have you forgotten me :)
  Reply
#7
If your script consists of making joke commands, there is a script that does it: https://scripts.eggdrop.fr/details-Jokes-s71.html
  Reply
#8
Not quite jokes, it's a bartender script :)
  Reply
#9
You should explain in words exactly what the script does, people aren't going to have fun re-reading the entire code to understand how it works.

Explains step by step what you can do with the script, even how the antiflood works. CrazyCat is very nice to do this job for you .. even reading it several times, I find it difficult to understand.

What I understand by reading is that you can perform joke orders combined with a system of stats for each order.
  Reply
#10
Let me try to axplain it agian !

If you type :

Code:
!coffee
The bot replies with:

Code:
Making a cup of coffee for [nick], [today] made today of [total] ordered wich make it the [sumtotal] time i make coffee
- where is substitute [total] ie total / [sumtotal] with ie: 20

and the original script stores that in mysql database. and CrazyCat talked about sql wasn't needed it could be done with something more lightweight

Hope you get it now?
  Reply
#11
It's a jokes-like script, it just has stats added (and random answer).
I've already did the main part of the script, but I'm trying to find the best way to store the stats with a good optimisation.

@fire-fox: I've a job and a life, so I can't spend all my time on the script, particularly when it's a free thing I do just to help
zeolia: tchat gratuit, sans inscription ni publicité
Merci de ne pas demander d'aide en MP
Away
  Reply
#12
You can have a look @ https://gitlab.com/tcl-scripts/games/bartender

Datas are saved per channel in eggdrop channel settings, so the real save is made every 5 minutes.
zeolia: tchat gratuit, sans inscription ni publicité
Merci de ne pas demander d'aide en MP
Away
  Reply
#13
Thanks, i'll give it a go :)

@CrazyCat - What do you mean by : Datas are saved per channel in eggdrop channel settings (in the .chan file)


So fare it's working fine!

perhaps alittle ajustment :
when

Code:
set replies(cola) [list "Serves icecold cola (%utoday/%utotal/%ctotal)" \
      "Serves cola that been laying in pile of shit ~45c (%utoday/%utotal/%ctotal)" \
      "Serves cola been standing close to box of dryice ~1,3c (%utoday/%utotal/%ctotal)" \
      "Serves cola that been standing next to comp for few hrs (%utoday/%utotal/%ctotal)"]
I would like it to add nick to like:

Code:
      set replies(cola) [list "Serves icecold cola to %nick (%utoday/%utotal/%ctotal)" \
      "Serves cola that been laying in pile of shit ~45c (%utoday/%utotal/%ctotal)" \
      "Serves cola been standing close to box of dryice ~1,3c (%utoday/%utotal/%ctotal)" \
      "Serves cola that been standing next to comp for few hrs (%utoday/%utotal/%ctotal)"]
It dosn't take the line with %nick only the others without %nick
- and when I do !beer nick it replies with my nick

Another observation when you do like !beer and !cola it counts stats to all of them?
  Reply
#14
it's useless to put the same post twice, I deleted the duplicate.
  Reply
#15
My mistake, I hit the wrong button!
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)