All pastes #907320 Raw Edit

Stuff

public text v1 · immutable
·published 2008-02-17 14:27 UTC
rendered paste body
; Basic AI Database Setup

on *:DNS:{ 
  if ($dns(0) > 0) { 
    set %dns.mask $dns(1).addr | set %dns.ip $dns(1).ip
    ; Create 'Bot' table and fill in the fields
    sqlite_exec %botdb CREATE TABLE IF NOT EXISTS Bot (ID INTEGER PRIMARY KEY AUTOINCREMENT, Owner UNIQUE, IPAddress, IPMask, BServer, BChannel, BNick) 

    var %sql = INSERT INTO Bot (Owner, IPAddress, IPMask, BServer, BChannel, BNick) VALUES ( $sqlite_qt(%bot.owner) , $sqlite_qt(%dns.ip) , $sqlite_qt(%dns.mask) , $sqlite_qt(%bot.server) , $sqlite_qt(%bot.channel) , $sqlite_qt(%bot.nick) )
    echo -a SQL: %sql

    if (%sqlite_errno != $sqlite_ok) {
      noop $tip(Error,Error,$scriptline $+ Error %sqlite_errno -- %sqlite_errstr $+ ) 
    }
    if $sqlite_exec(%botdb, %sql) {
      noop $tip(Information,Information,Query Successful $+ ) 
    }
    else {
      noop $tip(Error,Error,$scriptline $+ : Error %sqlite_errno -- %sqlite_errstr $+ )
      halt 
    }
  }
  else { halt }
}

on *:connect: { 
  ; Point to Database Path
  var %botdb = $sqlite_open($scriptdir\xfed.db)

  ; If the database exists, skip the check.
  if ($exists($scriptdir\Databases\xfed.db)) { 
    noop $tip(Information,Information,Database Exists -- Loading Bot...)
    start 
  } 
  else {
    noop $tip(Information,Information,Database not created -- Running Configuration.)
    dbsetup
  }
}

alias start { 
  var %botdb = $sqlite_open($scriptdir\xfed.db)
  ; Grab owner information
  var %sql = SELECT Owner FROM Bot
  var %request = $sqlite_query(%botdb, %sql)

  if (%request) {
    ; Grab 'Owner' (1) Field from the table 'Bot' and apply it to an global variable.
    ; Grab 'IP Address' (2) Field from the table 'Bot' and apply it to an global variable.
    set %xfed.owner $sqlite_fetch_field(%request, 1)
    set %xfed.owner $sqlite_fetch_field(%request, 2)
    sqlite_free %sql
    noop $tip(Information,Information,Welcome back %xfed.owner $+ ) 
  }
  else {
    noop $tip(Error,Error,Error executing query... Error %sqlite_errno -- %sqlite_errstr $+ )
    halt
  }
}

alias dbsetup { 
  ; Do query here for correct DNS lookup..

  var %botdb = $sqlite_open($scriptdir\xfed.db)
  var %bot.server = $?="What server will the bot run on?"
  var %bot.owner = $?="Enter the nickname of who will be administrating this bot:"

  ; Get owner IP Address then setup tables
  .dns %bot.owner

  var %bot.channel = $?="Where will this bot run in?"
  var %bot.nick = $?="What will my nick be?"
}