MySQL Seen System + Cache 1.14 STABLE (MBC Base)

By Noutrious on Sep 05, 2011

This is a module for MySQL Bot Core system. You'll need http://www.hawkee.com/snippet/8882/ in case for this to work.

[quote][12:02] !seen wubwubwub [12:02] -#DEV-SQL- Last seen wubwubwub before 34secs changing nickname to Hawkee[/quote]

MySQL Database Structure:

CREATE TABLE `seen` (
  `nickname` varchar(50) NOT NULL,
  `address` varchar(200) NOT NULL,
  `time` datetime NOT NULL,
  `network` varchar(50) NOT NULL,
  `action` enum('j','p','q','n','a','t') NOT NULL,
  `extra` varchar(100) NOT NULL,
  PRIMARY KEY (`nickname`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CHANGELOG: 1.00 STABLE -> 1.01 STABLE

  • Removed $iif statement on result return, didn't return action if no %extra variable.
  • Updated $m.dbres variable with extra network checking according to MBC version 1.02 (still works with 1.01 though) 1.00 STABLE -> 1.02 STABLE
  • Implemented communication with core system according to MBC version 1.12 (must update core, if updating module) 1.02 STABLE -> 1.14 STABLE
  • Implemented caching, now safe for remote MySQL server users.
  • Added fourth parameter to the m.modules, that will be used in next base version.
  • Added nick changing to m.seen.action.
  • Changed return value for the result. 1.14 STABLE -> 1.15 STABLE
  • Added checking whether extra parameter exists before trying to write it in cache database.
; MySQL Bot Core
; Module: Seen System
; Version: 1.15 STABLE
; Author: Nils Putnins (Neisen@Neisen.lv)

; - aliases
alias -l m.seen.db return $qt($mircdirseen.mbc.ini)
alias -l m.seenres return $iif($readini($m.seen.db,$1,$2),$v1,$m.dbres($2,seen,nickname,$1))
alias -l m.seen {
  if (!$isid && $3) {
    writeini -n $m.seen.db $1 address $2
    writeini -n $m.seen.db $1 time $ctime
    writeini -n $m.seen.db $1 network $network
    writeini -n $m.seen.db $1 action $left($3, 1)
    $iif($4,writeini -n $m.seen.db $1 extra $v1)
  }
  else if ($prop == sync) {
    var %records = $ini($m.seen.db,0), %sql = REPLACE INTO `seen` (`nickname`,`address`,`time`,`network`,`action`,`extra`) VALUES (?, ?, ?, ?, ?, ?)
    while %records {
      var %target = $ini($m.seen.db,%records)
      noop $mysql_query(%m.sql, %sql, %target, $m.seenres(%target,address), $asctime($m.seenres(%target,time),yyyy-mm-dd HH:nn:ss), $m.seenres(%target,network), $m.seenres(%target,action), $m.seenres(%target,extra))
      dec %records
    }
    .remove $m.seen.db
  }
  else if ($1) {
    if ($1 == $me) return Uhm...?
    else if ($1 == $nick) return Ehm...?
    else if ($1 ison $2) return Erhm..?
    var %result = $iif($m.seenres($1,time) !isnum,$ctime($v1),$v1)
    $iif(!%result,return No seen results for this nickname.)
    return Last seen $bold($1) before $duration($calc($ctime - %result),2) $m.seen.action($m.seenres($1,action)) $m.seenres($1,extra)
  }
}

alias -l m.seen.action {
  if ($1 = t) return saying something on
  else if ($1 = a) return making action in
  else if ($1 = q) return quitting
  else if ($1 = j) return joining
  else if ($1 = p) return parting
  else if ($1 = n) return changing nickname to
}

; - actions
on *:JOIN:#:m.seen $nick $fulladdress join $chan
on *:PART:#:m.seen $nick $fulladdress part $chan
on *:QUIT:m.seen $nick $fulladdress quit
on *:NICK:m.seen $nick $fulladdress nick $newnick
on *:ACTION:*:#:m.seen $nick $fulladdress action $chan
on *:TEXT:*:*:{
  if ($chan) m.seen $nick $fulladdress text $chan
  if ($1 == $command(seen)) $iif($chan,notice,msg) $nick $m.seen($2,$chan)
}

; - communicating with core
on *:SIGNAL:m.modules:{
  m.modules $+(Seen System,$chr(124),$command(seen),$chr(124),0,$chr(124),$remove($script,$mircdir))
  noop $m.seen().sync
}
Sign in to comment.
Noutrious   -  Sep 08, 2011

Update, caching added - huge suggestion to every who's using it to upgrade... especially if remote MySQL server.

 Respond  
Noutrious   -  Sep 06, 2011

First, set up the core and then just load this module, it'll do everything else itself. :)

 Respond  
x1L22   -  Sep 06, 2011

How It Works

 Respond  
Noutrious   -  Sep 05, 2011

Note that this doesn't work without the Core - http://www.hawkee.com/snippet/8882/

 Respond  
Aha2Y   -  Sep 05, 2011

Oh then I have read the script wrong. Very nice!

 Respond  
Wader   -  Sep 05, 2011

Aha2y its only using local variables for the MySQL return from the server (Its the way SQL works). Its actually storing all the data inside a MySQL Database.

 Respond  
Noutrious   -  Sep 05, 2011

Aha2Y, well, I suggest you study, what MySQL is then. :)

 Respond  
Aha2Y   -  Sep 05, 2011

I don't get it, Its still using a bunch of variables.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.