2016-04-11 06:04:47 +02:00
|
|
|
local setandget = {}
|
2016-03-15 21:37:19 +01:00
|
|
|
|
2016-06-07 06:31:34 +02:00
|
|
|
local utilities = require('otouto.utilities')
|
2016-04-11 06:04:47 +02:00
|
|
|
|
2016-05-27 05:28:44 +02:00
|
|
|
function setandget:init(config)
|
2016-04-11 06:04:47 +02:00
|
|
|
self.database.setandget = self.database.setandget or {}
|
2016-05-27 05:28:44 +02:00
|
|
|
setandget.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('set', true):t('get', true).table
|
|
|
|
setandget.doc = [[```
|
|
|
|
]]..config.cmd_pat..[[set <name> <value>
|
|
|
|
Stores a value with the given name. Use "]]..config.cmd_pat..[[set <name> --" to delete the stored value.
|
|
|
|
]]..config.cmd_pat..[[get [name]
|
2016-03-15 21:37:19 +01:00
|
|
|
Returns the stored value or a list of stored values.
|
|
|
|
```]]
|
2016-05-27 05:28:44 +02:00
|
|
|
end
|
2016-03-15 21:37:19 +01:00
|
|
|
|
2016-05-27 05:28:44 +02:00
|
|
|
setandget.command = 'set <name> <value>'
|
2016-03-15 21:37:19 +01:00
|
|
|
|
2016-05-27 05:28:44 +02:00
|
|
|
function setandget:action(msg, config)
|
2016-03-15 21:37:19 +01:00
|
|
|
|
otouto 3.11
"things occurred"
Added some utilities (id_from_username, id_from_message), removed some utilities (latcyr, others?).
Removed cycle-wasting "shortcuts" -- no more automatic id_str or name; text_lower remains.
Moved userdata (nicknames, lastfm, etc) to a different tree in the database (automatic migration will occur). /me now returns userdata.
Speaking of migration, database now stores the latest version run to make future automigration easy.
Database now saves hourly rather than minutely.
Changed readme and some plugins to reflect above changes.
Removed broken rockspec (Brayden, feel free to re-add once it's working).
Added option to automatically block people (via drua) when blacklisted.
Fixed about.lua trigger problems.
administration 1.11 - Removed /kickme and /broadcast. Users should leave manually, and announcements should be made via channel rather than spam. /setqotd now handles forwarded messages correctly. /kick, /ban, /hammer,
/mod, /admin now support multiple arguments. Added get_targets function. No migration is necessary.
2016-07-05 09:29:11 +02:00
|
|
|
local chat_id_str = tostring(msg.chat.id)
|
2016-04-08 23:12:02 +02:00
|
|
|
local input = utilities.input(msg.text)
|
otouto 3.11
"things occurred"
Added some utilities (id_from_username, id_from_message), removed some utilities (latcyr, others?).
Removed cycle-wasting "shortcuts" -- no more automatic id_str or name; text_lower remains.
Moved userdata (nicknames, lastfm, etc) to a different tree in the database (automatic migration will occur). /me now returns userdata.
Speaking of migration, database now stores the latest version run to make future automigration easy.
Database now saves hourly rather than minutely.
Changed readme and some plugins to reflect above changes.
Removed broken rockspec (Brayden, feel free to re-add once it's working).
Added option to automatically block people (via drua) when blacklisted.
Fixed about.lua trigger problems.
administration 1.11 - Removed /kickme and /broadcast. Users should leave manually, and announcements should be made via channel rather than spam. /setqotd now handles forwarded messages correctly. /kick, /ban, /hammer,
/mod, /admin now support multiple arguments. Added get_targets function. No migration is necessary.
2016-07-05 09:29:11 +02:00
|
|
|
self.database.setandget[chat_id_str] = self.database.setandget[chat_id_str] or {}
|
2016-03-15 21:37:19 +01:00
|
|
|
|
2016-05-27 05:28:44 +02:00
|
|
|
if msg.text_lower:match('^'..config.cmd_pat..'set') then
|
2016-03-15 21:37:19 +01:00
|
|
|
|
|
|
|
if not input then
|
2016-05-29 19:08:39 +02:00
|
|
|
utilities.send_message(self, msg.chat.id, setandget.doc, true, nil, true)
|
2016-03-15 21:37:19 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
local name = utilities.get_word(input:lower(), 1)
|
2016-04-08 23:12:02 +02:00
|
|
|
local value = utilities.input(input)
|
2016-03-15 21:37:19 +01:00
|
|
|
|
|
|
|
if not name or not value then
|
2016-05-29 19:08:39 +02:00
|
|
|
utilities.send_message(self, msg.chat.id, setandget.doc, true, nil, true)
|
2016-03-15 21:37:19 +01:00
|
|
|
elseif value == '--' or value == '—' then
|
otouto 3.11
"things occurred"
Added some utilities (id_from_username, id_from_message), removed some utilities (latcyr, others?).
Removed cycle-wasting "shortcuts" -- no more automatic id_str or name; text_lower remains.
Moved userdata (nicknames, lastfm, etc) to a different tree in the database (automatic migration will occur). /me now returns userdata.
Speaking of migration, database now stores the latest version run to make future automigration easy.
Database now saves hourly rather than minutely.
Changed readme and some plugins to reflect above changes.
Removed broken rockspec (Brayden, feel free to re-add once it's working).
Added option to automatically block people (via drua) when blacklisted.
Fixed about.lua trigger problems.
administration 1.11 - Removed /kickme and /broadcast. Users should leave manually, and announcements should be made via channel rather than spam. /setqotd now handles forwarded messages correctly. /kick, /ban, /hammer,
/mod, /admin now support multiple arguments. Added get_targets function. No migration is necessary.
2016-07-05 09:29:11 +02:00
|
|
|
self.database.setandget[chat_id_str][name] = nil
|
2016-05-29 19:08:39 +02:00
|
|
|
utilities.send_message(self, msg.chat.id, 'That value has been deleted.')
|
2016-03-15 21:37:19 +01:00
|
|
|
else
|
otouto 3.11
"things occurred"
Added some utilities (id_from_username, id_from_message), removed some utilities (latcyr, others?).
Removed cycle-wasting "shortcuts" -- no more automatic id_str or name; text_lower remains.
Moved userdata (nicknames, lastfm, etc) to a different tree in the database (automatic migration will occur). /me now returns userdata.
Speaking of migration, database now stores the latest version run to make future automigration easy.
Database now saves hourly rather than minutely.
Changed readme and some plugins to reflect above changes.
Removed broken rockspec (Brayden, feel free to re-add once it's working).
Added option to automatically block people (via drua) when blacklisted.
Fixed about.lua trigger problems.
administration 1.11 - Removed /kickme and /broadcast. Users should leave manually, and announcements should be made via channel rather than spam. /setqotd now handles forwarded messages correctly. /kick, /ban, /hammer,
/mod, /admin now support multiple arguments. Added get_targets function. No migration is necessary.
2016-07-05 09:29:11 +02:00
|
|
|
self.database.setandget[chat_id_str][name] = value
|
2016-05-29 19:08:39 +02:00
|
|
|
utilities.send_message(self, msg.chat.id, '"' .. name .. '" has been set to "' .. value .. '".', true)
|
2016-03-15 21:37:19 +01:00
|
|
|
end
|
|
|
|
|
2016-05-27 05:28:44 +02:00
|
|
|
elseif msg.text_lower:match('^'..config.cmd_pat..'get') then
|
2016-03-15 21:37:19 +01:00
|
|
|
|
|
|
|
if not input then
|
|
|
|
local output
|
otouto 3.11
"things occurred"
Added some utilities (id_from_username, id_from_message), removed some utilities (latcyr, others?).
Removed cycle-wasting "shortcuts" -- no more automatic id_str or name; text_lower remains.
Moved userdata (nicknames, lastfm, etc) to a different tree in the database (automatic migration will occur). /me now returns userdata.
Speaking of migration, database now stores the latest version run to make future automigration easy.
Database now saves hourly rather than minutely.
Changed readme and some plugins to reflect above changes.
Removed broken rockspec (Brayden, feel free to re-add once it's working).
Added option to automatically block people (via drua) when blacklisted.
Fixed about.lua trigger problems.
administration 1.11 - Removed /kickme and /broadcast. Users should leave manually, and announcements should be made via channel rather than spam. /setqotd now handles forwarded messages correctly. /kick, /ban, /hammer,
/mod, /admin now support multiple arguments. Added get_targets function. No migration is necessary.
2016-07-05 09:29:11 +02:00
|
|
|
if utilities.table_size(self.database.setandget[chat_id_str]) == 0 then
|
2016-03-15 21:37:19 +01:00
|
|
|
output = 'No values have been stored here.'
|
|
|
|
else
|
|
|
|
output = '*List of stored values:*\n'
|
otouto 3.11
"things occurred"
Added some utilities (id_from_username, id_from_message), removed some utilities (latcyr, others?).
Removed cycle-wasting "shortcuts" -- no more automatic id_str or name; text_lower remains.
Moved userdata (nicknames, lastfm, etc) to a different tree in the database (automatic migration will occur). /me now returns userdata.
Speaking of migration, database now stores the latest version run to make future automigration easy.
Database now saves hourly rather than minutely.
Changed readme and some plugins to reflect above changes.
Removed broken rockspec (Brayden, feel free to re-add once it's working).
Added option to automatically block people (via drua) when blacklisted.
Fixed about.lua trigger problems.
administration 1.11 - Removed /kickme and /broadcast. Users should leave manually, and announcements should be made via channel rather than spam. /setqotd now handles forwarded messages correctly. /kick, /ban, /hammer,
/mod, /admin now support multiple arguments. Added get_targets function. No migration is necessary.
2016-07-05 09:29:11 +02:00
|
|
|
for k,v in pairs(self.database.setandget[chat_id_str]) do
|
2016-03-15 21:37:19 +01:00
|
|
|
output = output .. '• ' .. k .. ': `' .. v .. '`\n'
|
|
|
|
end
|
|
|
|
end
|
2016-05-29 19:08:39 +02:00
|
|
|
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
2016-03-15 21:37:19 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local output
|
otouto 3.11
"things occurred"
Added some utilities (id_from_username, id_from_message), removed some utilities (latcyr, others?).
Removed cycle-wasting "shortcuts" -- no more automatic id_str or name; text_lower remains.
Moved userdata (nicknames, lastfm, etc) to a different tree in the database (automatic migration will occur). /me now returns userdata.
Speaking of migration, database now stores the latest version run to make future automigration easy.
Database now saves hourly rather than minutely.
Changed readme and some plugins to reflect above changes.
Removed broken rockspec (Brayden, feel free to re-add once it's working).
Added option to automatically block people (via drua) when blacklisted.
Fixed about.lua trigger problems.
administration 1.11 - Removed /kickme and /broadcast. Users should leave manually, and announcements should be made via channel rather than spam. /setqotd now handles forwarded messages correctly. /kick, /ban, /hammer,
/mod, /admin now support multiple arguments. Added get_targets function. No migration is necessary.
2016-07-05 09:29:11 +02:00
|
|
|
if self.database.setandget[chat_id_str][input:lower()] then
|
|
|
|
output = '`' .. self.database.setandget[chat_id_str][input:lower()] .. '`'
|
2016-03-15 21:37:19 +01:00
|
|
|
else
|
|
|
|
output = 'There is no value stored by that name.'
|
|
|
|
end
|
|
|
|
|
2016-05-29 19:08:39 +02:00
|
|
|
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
2016-03-15 21:37:19 +01:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
return setandget
|