Added basic DB interface.

master
q3k 2013-09-29 18:20:12 +02:00
parent 4ad6c3ca1c
commit ead8e9a304
5 changed files with 14 additions and 32 deletions

View File

@ -195,12 +195,8 @@ function irc:Connect(server, port, nickname, username, realname)
-- Connection procedure (callback hell!)
local FinishedInitialNotices = function()
hook.Remove('irc.Notice', 'irc.Connect')
hook.Add('irc.Mode', 'irc.Connect', function(Target, Mode)
if Target == self._nickname then
print("Got mode")
hook.Remove('irc.Mode', 'irc.Connect')
hook.Call('irc.Connected')
end
self:OnResponse(376, function()
hook.Call('irc.Connected')
end)
self:SetNick(self._nickname)
self:LoginUser(username, realname)

View File

@ -72,7 +72,6 @@ function API.Register(plugin_id, plugin_name, version, url, author)
Plugin.Version = Version
Plugin.URL = url
Plugin.Author = author
end
function API.CurrentTime(plugin_id)
@ -83,6 +82,10 @@ function API.ConfigGet(plugin_id, Key)
return config:Get("plugin-" .. plugin_id, Key)
end
function API.DBOpen(plugin_id, Handle)
return db.Open(Handle)
end
local Quotas = {}
-- Start counting a coroutine quota
function plugin.StartQuota(Seconds)

View File

@ -75,7 +75,7 @@ function reactor:Run()
-- we actually got something on our sockets
for Socket, Data in pairs(self._read_sockets) do
if r[Socket] ~= nil then
Socket:settimeout(2)
--Socket:settimeout(3)
local Line, Error = Socket:receive('*l')
if Error then
error('Could not receive line: ' .. Error)

View File

@ -1,29 +1,11 @@
postgres = {}
local function check_connection()
if not postgres.db or not postgres.db:ping() then
local Server = plugin.ConfigGet('server')
local Username = plugin.ConfigGet('username')
local Password = plugin.ConfigGet('password')
local Database = plugin.ConfigGet('database')
local Port = tonumber(plugin.ConfigGet('port')) or 5432
postgres.db = DBI.Connect('PostgreSQL', Database, Username, Password, Server, Port)
end
if not postgres.db then
error("Could not connect to the PostgreSQL database!")
return false
end
return true
end
plugin.AddHook('auth.GetLevel', 'GetLevel', function(Channel, Account)
if check_connection() then
local Statement = postgres.db:prepare("select _level from _level where _account = ? and _channel = ?")
print(Account, Channel.Name)
Statement:execute(Account, Channel.Name)
for Row in Statement:rows(true) do
return tonumber(Row._level)
end
return 0
local DB = plugin.DBOpen('auth')
local Query = DB:Query("select _level from _level where _account = ? and _channel = ?",
Account, Channel.Name)
for Row in Query do
return tonumber(Row._level)
end
return 0
end)

View File

@ -1,5 +1,6 @@
require('core.hook')
require('core.config')
require('core.db')
require('core.reactor')
require('core.irc')
require('core.bot')