All pastes #886204 Raw Edit

Anonymous

public text v1 · immutable
#886204 ·published 2008-01-31 14:57 UTC
rendered paste body
; Basic AI Database Setup

; Debug Window
on *:start: {
  window -xEk0 @Debugger
}

on *:connect: {
  ; If the database exists, skip this, otherwise, we must create it.

  if ($exists($scriptdir\impulse.db)) { 
    aline @Debugger -- Debugging [[ $+ $time $+ ]] -- :: Database Exists = True 
  }
  else {
    var %bot.home = $?="What server will the bot run on? (Example: irc.dal.net)"
    var %bot.chan = $?="What is the name of the channel this bot will run in? (Example: #bot)"
    var %bot.boss = $?="Enter the owner's nickname:"

    var %bot.base = $sqlite_open($scriptdir\impulse.db)

    if (%bot.base) { 
      aline @Debugger -- Debugging [[ $+ $time $+ ]] -- :: Database is now created and initalized. 
    }
    else {
      aline @Debugger -- Debugging [[ $+ $time $+ ]] -- :: Database is missing, restarting...   
      .timer 1 10 exit -rn
    }

    ; If the table "BotInfo" doesn't exist, create it and the proper fields.
    sqlite_exec %bot.base CREATE TABLE IF NOT EXISTS BotInfo (ID INTEGER PRIMARY KEY AUTOINCREMENT, Owner UNIQUE, OwnerIP, OwnerIPMask, BotServer, BotChannel)

    ; Get the owner IP address.
    .dns $me

    var %sql = INSERT INTO BotInfo (Owner, OwnerIP, OwnerIPMask, BotServer, BotChannel) VALUES ( $sqlite_qt($me) , $sqlite_qt(%dns.ip) , $sqlite_qt(%dns.mask) , $sqlite_qt(%bot.home) , $sqlite_qt(%bot.chan) )

    if ($sqlite_errno != $SQLITE_OK) { 
      aline @Debugger -- Debugging [[ $+ time $+ ]] -- :: Error Num: %sqlite_errstr - Error with Query 
    }
    else {
      halt
    }

    if ($sqlite_exec( %bot.base, %sql )) {
      aline @Debugger -- Debugging [[ $+ time $+ ]] -- :: Query Executed Successfully
      unset %dns.* 
    }
    else { 
      halt | echo -a Error Num: %sqlite_errstr - Error with Query
    }
  }

  ; Bug Area:  Not returning value..?
  if (%ai.chan == $null) { 
    aline @Debugger -- Debugging [[ $+ $time $+ ]] -- :: Retrieving "Channel" Record...
    var %bot.base = $sqlite_open($scriptdir\impulse.db)
    var %sql = SELECT BotChannel FROM BotInfo
    var %request = $sqlite_query(%bot.base, %sql)

    aline @Debugger -- Debugging [[ $+ $time $+ ]] -- :: %sql
    echo -a %bot.base

    aline @Debugger -- Debugging [[ $+ $time $+ ]] -- :: %sql

    if (%request) { 
      aline @Debugger -- Debugging [[ $+ $time $+ ]] -- :: Query Executed Successfully
      echo -a %sql
      echo -a %request
      set %tmp $sqlite_fetch_field(%result, 1).name
      aline @Debugger -- Debugging [[ $+ $time $+ ]] -- :: %tmp
      sqlite_free %sql
    }
    else {
      echo -a Err Number: %sqlite_errno - Error executing query: %sqlite_errstr
    }
  }
}

; This works !
alias add.move {
  set %new.move.detect $1-
  set %new.move.freq $?="How often will the bot use it? (From 1 to 10)"

  sqlite_exec %bot.base CREATE TABLE IF NOT EXISTS BotMoves (ID INTEGER PRIMARY KEY AUTOINCREMENT, Move UNIQUE, Freq)

  var %sql = INSERT INTO BotMoves (Move, Freq) VALUES ( $sqlite_qt( $1- ) , $sqlite_qt(%new.move.freq) )

  if ($sqlite_exec( %bot.base, %sql )) {
    echo -a Query Parsed | unset %new.* 
  }
  else { 
    echo -a Error Num: %sqlite_errstr - Error with Query
  }
}

on *:DNS:{ set %dns.mask $dns(0).addr | set %dns.ip $dns(0).ip }

on *:notice:*now your turn*: {
  var %sql = SELECT Referee FROM OppStatus

  if ($sqlite_exec( %bot.base, %sql )) {
    msg %bot
  }

}