Changed database name to the bot's name (rather than generic

"otouto"). You must manually rename your db file.
This commit is contained in:
topkecleon 2016-03-08 08:15:48 -05:00
parent a2bdecb7bb
commit ad3a16a814
2 changed files with 16 additions and 8 deletions

6
.gitignore vendored
View File

@ -1,6 +1,6 @@
plugins/mokubot.lua
plugins/qtbot.lua
plugins/weeabot.lua
plugins/mokubot*
plugins/qtbot*
plugins/weeabot*
*.db
lua-tg
tg

18
bot.lua
View File

@ -11,15 +11,15 @@ bot_init = function() -- The function run when the bot is started or reloaded.
dofile('bindings.lua') -- Load Telegram bindings.
dofile('utilities.lua') -- Load miscellaneous and cross-plugin functions.
-- Load the "database"! ;)
if not database then
database = load_data('otouto.db')
end
-- Fetch bot information. Try until it succeeds.
repeat bot = getMe() until bot
bot = bot.result
-- Load the "database"! ;)
if not database then
database = load_data(bot.username..'.db')
end
plugins = {} -- Load plugins.
for i,v in ipairs(config.plugins) do
local p = dofile('plugins/'..v)
@ -36,6 +36,7 @@ bot_init = function() -- The function run when the bot is started or reloaded.
last_cron = last_cron or os.date('%M', os.time()) -- the time of the last cron job,
is_started = true -- and whether or not the bot should be running.
database.usernames = database.usernames or {} -- Table to cache usernames by user ID.
database.users = database.users or {} -- Table to cache userdata.
end
@ -45,6 +46,13 @@ on_msg_receive = function(msg) -- The fn run whenever a message is received.
database.usernames[msg.from.username:lower()] = msg.from.id
end
if not database.users[tostring(msg.from.id)] then
database.users[tostring(msg.from.id)] = {}
end
for k,v in pairs(msg.from) do
database.users[tostring(msg.from.id)][k] = v
end
if msg.date < os.time() - 5 then return end -- Do not process old messages.
if not msg.text then msg.text = msg.caption or '' end