From ad3a16a814d2e10a46bbe30307ac4d885c291903 Mon Sep 17 00:00:00 2001 From: topkecleon Date: Tue, 8 Mar 2016 08:15:48 -0500 Subject: [PATCH] Changed database name to the bot's name (rather than generic "otouto"). You must manually rename your db file. --- .gitignore | 6 +++--- bot.lua | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 5222ffe..526c2a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ -plugins/mokubot.lua -plugins/qtbot.lua -plugins/weeabot.lua +plugins/mokubot* +plugins/qtbot* +plugins/weeabot* *.db lua-tg tg diff --git a/bot.lua b/bot.lua index 6fa0304..5ba0d5b 100755 --- a/bot.lua +++ b/bot.lua @@ -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