diff --git a/core/bot.lua b/core/bot.lua index 09db53b..efed768 100644 --- a/core/bot.lua +++ b/core/bot.lua @@ -44,7 +44,10 @@ function bot:OnChannelMessage(Username, Channel, Message) end if not self._commands[Command] then - Channel:Say("Unknown command '" .. Command .. "'.") + local FellBack = hook.Call("bot.UnknownCommand", Username, Channel, Command, Arguments) + if not FellBack then + Channel:Say("Unknown command '" .. Command .. "'.") + end else local CommandData = self._commands[Command] if #Arguments ~= CommandData.Arguments and CommandData.Arguments ~= -1 then diff --git a/plugins/auth-postgres.lua b/plugins/auth-postgres.lua index 7032c2a..7a17d8a 100644 --- a/plugins/auth-postgres.lua +++ b/plugins/auth-postgres.lua @@ -1,7 +1,7 @@ postgres = {} plugin.AddHook('auth.GetLevel', 'GetLevel', function(Channel, Account) - local DB = plugin.DBOpen('auth') + local DB = plugin.DBOpen('main') local Query = DB:Query("select _level from _level where _account = ? and _channel = ?", Account, Channel.Name) for Row in Query do diff --git a/plugins/hackerspace.lua b/plugins/hackerspace.lua index 10fa69e..7be6d55 100644 --- a/plugins/hackerspace.lua +++ b/plugins/hackerspace.lua @@ -12,6 +12,39 @@ plugin.AddCommand('at', 0, function(Username, Channel) if #Users == 0 then Channel:Say("Trochę Łotwa. Nawet zimnioka nie ma.") else - Channel:Say(table.concat(Users, ',')) + Channel:Say(table.concat(Users, ', ')) end end, "Show who's at the Warsaw Hackerspace.") + +plugin.AddCommand('describe', 1, function(Username, Channel, Term) + local db = plugin.DBOpen('main') + local Header = false + local Counter = 0 + for Row in db:Query('select _oid::text from _term where lower(_name) = lower(?);', Term) do + local Oid = Row._oid + for Row2 in db:Query('select _text from _entry where _term_oid = ?', Oid) do + if not Header then + Channel:Say(string.format('I heard "%s" is:', Term)) + Header = true + end + local Text = Row2._text + Channel:Say(string.format('[%i] ', Counter) .. Text) + Counter = Counter + 1 + end + end + if not Header then + Channel:Say("No such term!") + end + +end, "Describe a saved term.") + +plugin.AddHook('bot.UnknownCommand', 'DescribeTerm', function(Username, Channel, Command, Arguments) + local db = plugin.DBOpen('main') + for Row in db:Query('select _oid::text from _term where lower(_name) = lower(?);', Command) do + local Oid = Row._oid + for Row2 in db:Query('select _text from _entry where _term_oid = ? order by random() limit 1;', Oid) do + Channel:Say(Row2._text) + return true + end + end +end)