; Basic AI Database Setup
on *:DNS:{
if (%bot.dns) {
if ($dns(0) > 0) {
var %dns.mask = $sqlite_qt($dns(1).addr), %dns.ip = $sqlite_qt($dns(1).ip)
}
else {
var %dns.mask = NULL, %dns.ip = NULL
}
set -l %sql INSERT INTO Bot (Owner, IPAddress, IPMask, BServer, BChannel, BNick) VALUES ( $sqlite_qt(%bot.owner) , %dns.ip , %dns.mask , $sqlite_qt(%bot.server) , $sqlite_qt(%bot.channel) , $sqlite_qt(%bot.nick) )
echo -a SQL: %sql
if ($sqlite_exec(%botdb, %sql)) {
noop $tip(Information,Information,Query Successful $+ )
}
else {
noop $tip(Error,Error,$scriptline $+ : Error %sqlite_errno -- %sqlite_errstr $+ )
}
unset %bot.dns
}
}
on *:connect: {
; Point to Database Path
set %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 {
; Grab owner information
var %sql = SELECT Owner, IPAddress FROM Bot
var %request = $sqlite_query(%botdb, %sql)
if (%request && $sqlite_fetch_row(%request, row)) {
; 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 $hget(row, 1)
set %xfed.ip $hget(row, 2)
sqlite_free %request
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..
set %bot.server $?="What server will the bot run on?"
set %bot.owner $?="Enter the nickname of who will be administrating this bot:"
set %bot.channel $?="Where will this bot run in?"
set %bot.nick $?="What will my nick be?"
; 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)
; Get owner IP Address then setup tables
set -eu30 %bot.dns 1
.dns -c %bot.owner
}