This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot-2/otouto/plugins/pokemon-go.lua

85 lines
2.4 KiB
Lua
Raw Normal View History

2016-07-14 02:00:58 +02:00
-- For some reason you can't have an é in variable names. :(
local pokemon_go = {}
local utilities = require('otouto.utilities')
pokemon_go.command = 'pokego <team>'
function pokemon_go:init(config)
2016-08-15 07:00:24 +02:00
pokemon_go.triggers = utilities.triggers(self.info.username, config.cmd_pat)
:t('pokego', true):t('pokégo', true)
:t('pokemongo', true):t('pokémongo', true)
:t('pogo', true):t('mongo', true).table
pokemon_go.doc = config.cmd_pat .. [[pokego <team>
Set your Pokémon Go team for statistical purposes. The team must be valid, and can be referred to by name or color (or the first letter of either). Giving no team name will show statistics.]]
2016-08-15 07:00:24 +02:00
local db = self.database.pokemon_go
if not db then
self.database.pokemon_go = {}
db = self.database.pokemon_go
end
if not db.membership then
db.membership = {}
end
for _, set in pairs(db.membership) do
setmetatable(set, utilities.set_meta)
end
2016-07-14 02:00:58 +02:00
end
local team_ref = {
2016-08-15 07:00:24 +02:00
mystic = "Mystic",
m = "Mystic",
valor = "Valor",
v = "Valor",
instinct = "Instinct",
i = "Instinct",
blue = "Mystic",
b = "Mystic",
red = "Valor",
r = "Valor",
yellow = "Instinct",
y = "Instinct"
2016-07-14 02:00:58 +02:00
}
function pokemon_go:action(msg, config)
2016-08-15 07:00:24 +02:00
local output
local input = utilities.input(msg.text_lower)
2016-07-14 02:00:58 +02:00
2016-08-15 07:00:24 +02:00
if input then
local team = team_ref[input]
if not team then
output = 'Invalid team.'
2016-07-14 02:00:58 +02:00
else
2016-08-15 07:00:24 +02:00
local id_str = tostring(msg.from.id)
local db = self.database.pokemon_go
local db_membership = db.membership
if not db_membership[team] then
db_membership[team] = utilities.new_set()
end
for t, set in pairs(db_membership) do
if t ~= team then
set:remove(id_str)
else
set:add(id_str)
end
end
output = 'Your team is now '..team..'.'
2016-07-14 02:00:58 +02:00
end
2016-08-15 07:00:24 +02:00
else
local db = self.database.pokemon_go
local db_membership = db.membership
2016-07-14 02:00:58 +02:00
2016-08-15 07:00:24 +02:00
local output_temp = {'Membership:'}
for t, set in pairs(db_membership) do
table.insert(output_temp, t..': '..#set)
end
2016-07-14 02:00:58 +02:00
2016-08-15 07:00:24 +02:00
output = table.concat(output_temp, '\n')
2016-07-14 02:00:58 +02:00
end
2016-08-15 07:00:24 +02:00
utilities.send_reply(self, msg, output)
2016-07-14 02:00:58 +02:00
end
return pokemon_go