otouto v3.12

Minor changes across the board. More planned. I also may have accidentally screwed with access
permissions (so looks like every file is marked modified).
Moved drua-tg.lua into the otouto/ directory.
Added pokego-calculator.lua plugin (similar to pidgeycalc.com).
This commit is contained in:
topkecleon 2016-07-25 05:03:35 -04:00
parent 701f6bbd41
commit b7c81c464f
59 changed files with 250 additions and 212 deletions

0
.editorconfig Normal file → Executable file
View File

1
.gitignore vendored Normal file → Executable file
View File

@ -1,3 +1,4 @@
otouto/plugins/mokubot*
otouto/plugins/oubot*
*.db
tg

0
LICENSE Executable file → Normal file
View File

0
README.md Executable file → Normal file
View File

0
config.lua Executable file → Normal file
View File

0
otouto/bindings.lua Executable file → Normal file
View File

20
otouto/bot.lua Executable file → Normal file
View File

@ -4,7 +4,7 @@ local bot = {}
local bindings -- Load Telegram bindings.
local utilities -- Load miscellaneous and cross-plugin functions.
bot.version = '3.11'
bot.version = '3.12'
function bot:init(config) -- The function run when the bot is started or reloaded.
@ -12,7 +12,7 @@ function bot:init(config) -- The function run when the bot is started or reloade
utilities = require('otouto.utilities')
assert(
config.bot_api_key and config.bot_api_key ~= '',
config.bot_api_key ~= '',
'You did not set your bot token in the config!'
)
self.BASE_URL = 'https://api.telegram.org/bot' .. config.bot_api_key .. '/'
@ -29,21 +29,6 @@ function bot:init(config) -- The function run when the bot is started or reloade
self.database = utilities.load_data(self.info.username..'.db')
end
-- MIGRATION CODE 3.10 -> 3.11
if self.database.users and self.database.version ~= '3.11' then
self.database.userdata = {}
for id, user in pairs(self.database.users) do
self.database.userdata[id] = {}
self.database.userdata[id].nickname = user.nickname
self.database.userdata[id].lastfm = user.lastfm
user.nickname = nil
user.lastfm = nil
user.id_str = nil
user.name = nil
end
end
-- END MIGRATION CODE
-- Table to cache user info (usernames, IDs, etc).
self.database.users = self.database.users or {}
-- Table to store userdata (nicknames, lastfm usernames, etc).
@ -58,6 +43,7 @@ function bot:init(config) -- The function run when the bot is started or reloade
local p = require('otouto.plugins.'..v)
table.insert(self.plugins, p)
if p.init then p.init(self, config) end
if p.doc then p.doc = '```\n'..p.doc..'\n```' end
end
print('@' .. self.info.username .. ', AKA ' .. self.info.first_name ..' ('..self.info.id..')')

View File

@ -1,14 +1,36 @@
--[[
drua-tg
A fork of JuanPotato's lua-tg (https://github.com/juanpotato/lua-tg),
Based on JuanPotato's lua-tg (https://github.com/juanpotato/lua-tg),
modified to work more naturally from an API bot.
Usage:
drua = require('drua-tg')
drua.IP = 'localhost'
drua.PORT = 4567
drua.IP = 'localhost' -- 'localhost' is default
drua.PORT = 4567 -- 4567 is default
drua.message(chat_id, text)
]]--
The MIT License (MIT)
Copyright (c) 2015-2016 Juan Potato
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
]]
local SOCKET = require('socket')

2
otouto/plugins/about.lua Executable file → Normal file
View File

@ -4,7 +4,7 @@ local bot = require('otouto.bot')
local utilities = require('otouto.utilities')
about.command = 'about'
about.doc = '`Returns information about the bot.`'
about.doc = 'Returns information about the bot.'
about.triggers = {
''

View File

@ -19,10 +19,11 @@
now support multiple arguments. Added get_targets function. No migration is
necessary.
]]--
1.11.1 - Bugfixes. /hammer can now be used in PM.
]]
local JSON = require('dkjson')
local drua = dofile('drua-tg.lua')
local drua = require('otouto.drua-tg')
local bindings = require('otouto.bindings')
local utilities = require('otouto.utilities')
@ -49,7 +50,7 @@ function administration:init(config)
administration.flags = administration.init_flags(config.cmd_pat)
administration.init_command(self, config)
administration.doc = '`Returns a list of administrated groups.\nUse '..config.cmd_pat..'ahelp for more administrative commands.`'
administration.doc = 'Returns a list of administrated groups.\nUse '..config.cmd_pat..'ahelp for more administrative commands.'
administration.command = 'groups [query]'
-- In the worst case, don't send errors in reply to random messages.
@ -1199,7 +1200,9 @@ function administration.init_command(self_, config_)
elseif target.rank >= administration.get_rank(self, msg.from.id, msg.chat.id, config) then
output = output .. target.name .. ' is too privileged to be globally banned.\n'
else
if group then
administration.kick_user(self, msg.chat.id, target.id, 'hammered by ' .. utilities.build_name(msg.from.first_name, msg.from.last_name), config)
end
if #targets == 1 then
for k,v in pairs(self.database.administration.groups) do
if not v.flags[6] then
@ -1209,7 +1212,7 @@ function administration.init_command(self_, config_)
end
end
self.database.blacklist[target.id_str] = true
if group.flags[6] == true then
if group and group.flags[6] == true then
group.mods[target.id_str] = nil
group.bans[target.id_str] = true
output = output .. target.name .. ' has been globally and locally banned.\n'

9
otouto/plugins/apod.lua Executable file → Normal file
View File

@ -12,16 +12,17 @@ apod.command = 'apod [date]'
function apod:init(config)
apod.triggers = utilities.triggers(self.info.username, config.cmd_pat)
:t('apod', true):t('apodhd', true):t('apodtext', true).table
apod.doc = [[```
]]..config.cmd_pat..[[apod [query]
apod.doc = config.cmd_pat .. [[apod [query]
Returns the Astronomy Picture of the Day.
If the query is a date, in the format YYYY-MM-DD, the APOD of that day is returned.
Examples:
]] .. config.cmd_pat .. [[apodhd [query]
Returns the image in HD, if available.
]] .. config.cmd_pat .. [[apodtext [query]
Returns the explanation of the APOD.
Source: nasa.gov
```]]
Source: nasa.gov]]
end
function apod:action(msg, config)

5
otouto/plugins/bandersnatch.lua Executable file → Normal file
View File

@ -6,10 +6,7 @@ bandersnatch.command = 'bandersnatch'
function bandersnatch:init(config)
bandersnatch.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('bandersnatch'):t('bc').table
bandersnatch.doc = [[```
Shun the frumious Bandersnatch.
Alias: ]]..config.cmd_pat..[[bc
```]]
bandersnatch.doc = 'Shun the frumious Bandersnatch. \nAlias: ' .. config.cmd_pat .. 'bc'
end
local fullnames = { "Wimbledon Tennismatch", "Rinkydink Curdlesnoot", "Butawhiteboy Cantbekhan", "Benadryl Claritin", "Bombadil Rivendell", "Wanda's Crotchfruit", "Biblical Concubine", "Syphilis Cankersore", "Buckminster Fullerene", "Bourgeoisie Capitalist" }

6
otouto/plugins/bible.lua Executable file → Normal file
View File

@ -12,11 +12,9 @@ function bible:init(config)
end
bible.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('bible', true):t('b', true).table
bible.doc = [[```
]]..config.cmd_pat..[[bible <reference>
bible.doc = config.cmd_pat .. [[bible <reference>
Returns a verse from the American Standard Version of the Bible, or an apocryphal verse from the King James Version. Results from biblia.com.
Alias: ]]..config.cmd_pat..[[b
```]]
Alias: ]] .. config.cmd_pat .. 'b'
end
bible.command = 'bible <reference>'

View File

@ -11,11 +11,6 @@ local ltn12 = require('ltn12')
local utilities = require('otouto.utilities')
bing.command = 'bing <query>'
bing.doc = [[```
/bing <query>
Returns the top web search results from Bing.
Aliases: /g, /google
```]]
bing.search_url = 'https://api.datamarket.azure.com/Data.ashx/Bing/Search/Web?Query=\'%s\'&$format=json'
@ -26,6 +21,9 @@ function bing:init(config)
return
end
bing.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('bing', true):t('g', true):t('google', true).table
bing.doc = config.cmd_pat .. [[bing <query>
Returns the top web search results from Bing.
Aliases: ]] .. config.cmd_pat .. 'g, ' .. config.cmd_pat .. 'google'
end
function bing:action(msg, config)

4
otouto/plugins/blacklist.lua Executable file → Normal file
View File

@ -93,7 +93,7 @@ function blacklist:action(msg, config)
self.database.blacklist[target.id_str] = true
output = output .. target.name .. ' is now blacklisted.\n'
if config.drua_block_on_blacklist and target.id > 0 then
require('drua-tg').block(target.id)
require('otouto.drua-tg').block(target.id)
end
end
end
@ -107,7 +107,7 @@ function blacklist:action(msg, config)
self.database.blacklist[target.id_str] = nil
output = output .. target.name .. ' is no longer blacklisted.\n'
if config.drua_block_on_blacklist and target.id > 0 then
require('drua-tg').unblock(target.id)
require('otouto.drua-tg').unblock(target.id)
end
end
end

6
otouto/plugins/calc.lua Executable file → Normal file
View File

@ -8,10 +8,8 @@ calc.command = 'calc <expression>'
function calc:init(config)
calc.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('calc', true).table
calc.doc = [[```
]]..config.cmd_pat..[[calc <expression>
Returns solutions to mathematical expressions and conversions between common units. Results provided by mathjs.org.
```]]
calc.doc = config.cmd_pat .. [[calc <expression>
Returns solutions to mathematical expressions and conversions between common units. Results provided by mathjs.org.]]
end
function calc:action(msg, config)

2
otouto/plugins/cats.lua Executable file → Normal file
View File

@ -13,7 +13,7 @@ function cats:init(config)
end
cats.command = 'cat'
cats.doc = '`Returns a cat!`'
cats.doc = 'Returns a cat!'
function cats:action(msg, config)

View File

@ -3,9 +3,10 @@ local channel = {}
local bindings = require('otouto.bindings')
local utilities = require('otouto.utilities')
--channel.command = 'ch <channel> \\n <message>'
channel.doc = [[```
/ch <channel>
function channel:init(config)
channel.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('ch', true).table
channel.command = 'ch <channel> \\n <message>'
channel.doc = config.cmd_pat .. [[ch <channel>
<message>
Sends a message to a channel. Channel may be specified via ID or username. Messages are markdown-enabled. Users may only send messages to channels for which they are the owner or an administrator.
@ -15,13 +16,7 @@ The following markdown syntax is supported:
_italic text_
[text](URL)
`inline fixed-width code`
```pre-formatted fixed-width code block```
Due to the frequent dysfunction and incompletion of the API method used to determine the administrators of a channel, this command may not work for the owners of some channels.
```]]
function channel:init(config)
channel.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('ch', true).table
```pre-formatted fixed-width code block```]]
end
function channel:action(msg, config)
@ -51,7 +46,7 @@ function channel:action(msg, config)
output = 'Please enter a message to be sent. Markdown is supported.'
end
else
output = 'Sorry, you do not appear to be an administrator for that channel.\nThere is currently a known bug in the getChatAdministrators method, where administrator lists will often not show a channel\'s owner.'
output = 'Sorry, you do not appear to be an administrator for that channel.'
end
else
output = 'Sorry, I was unable to retrieve a list of administrators for that channel.\n`' .. t.description .. '`'

0
otouto/plugins/chatter.lua Executable file → Normal file
View File

2
otouto/plugins/commit.lua Executable file → Normal file
View File

@ -5,7 +5,7 @@ local commit = {}
local utilities = require('otouto.utilities')
commit.command = 'commit'
commit.doc = '`Returns a commit message from whatthecommit.com.`'
commit.doc = 'Returns a commit message from whatthecommit.com.'
function commit:init(config)
commit.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('commit').table

View File

@ -27,6 +27,7 @@ function control:action(msg, config)
end
package.loaded['otouto.bindings'] = nil
package.loaded['otouto.utilities'] = nil
package.loaded['otouto.drua-tg'] = nil
package.loaded['config'] = nil
if not msg.text_lower:match('%-config') then
for k, v in pairs(require('config')) do

6
otouto/plugins/currency.lua Executable file → Normal file
View File

@ -7,12 +7,10 @@ currency.command = 'cash [amount] <from> to <to>'
function currency:init(config)
currency.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('cash', true).table
currency.doc = [[```
]]..config.cmd_pat..[[cash [amount] <from> to <to>
currency.doc = config.cmd_pat .. [[cash [amount] <from> to <to>
Example: ]] .. config.cmd_pat .. [[cash 5 USD to EUR
Returns exchange rates for various currencies.
Source: Google Finance.
```]]
Source: Google Finance.]]
end
function currency:action(msg, config)

6
otouto/plugins/dice.lua Executable file → Normal file
View File

@ -6,10 +6,8 @@ dice.command = 'roll <nDr>'
function dice:init(config)
dice.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('roll', true).table
dice.doc = [[```
]]..config.cmd_pat..[[roll <nDr>
Returns a set of dice rolls, where n is the number of rolls and r is the range. If only a range is given, returns only one roll.
```]]
dice.doc = config.cmd_pat .. [[roll <nDr>
Returns a set of dice rolls, where n is the number of rolls and r is the range. If only a range is given, returns only one roll.]]
end
function dice:action(msg)

View File

@ -9,12 +9,10 @@ dilbert.command = 'dilbert [date]'
function dilbert:init(config)
dilbert.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('dilbert', true).table
dilbert.doc = [[```
]]..config.cmd_pat..[[dilbert [YYYY-MM-DD]
dilbert.doc = config.cmd_pat .. [[dilbert [YYYY-MM-DD]
Returns the latest Dilbert strip or that of the provided date.
Dates before the first strip will return the first strip. Dates after the last trip will return the last strip.
Source: dilbert.com
```]]
Source: dilbert.com]]
end
function dilbert:action(msg, config)

5
otouto/plugins/echo.lua Executable file → Normal file
View File

@ -6,10 +6,7 @@ echo.command = 'echo <text>'
function echo:init(config)
echo.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('echo', true).table
echo.doc = [[```
]]..config.cmd_pat..[[echo <text>
Repeats a string of text.
```]]
echo.doc = config.cmd_pat .. 'echo <text> \nRepeats a string of text.'
end
function echo:action(msg)

2
otouto/plugins/eightball.lua Executable file → Normal file
View File

@ -3,7 +3,7 @@ local eightball = {}
local utilities = require('otouto.utilities')
eightball.command = '8ball'
eightball.doc = '`Returns an answer from a magic 8-ball!`'
eightball.doc = 'Returns an answer from a magic 8-ball!'
function eightball:init(config)
eightball.triggers = utilities.triggers(self.info.username, config.cmd_pat,

2
otouto/plugins/fortune.lua Executable file → Normal file
View File

@ -16,7 +16,7 @@ function fortune:init(config)
end
fortune.command = 'fortune'
fortune.doc = '`Returns a UNIX fortune.`'
fortune.doc = 'Returns a UNIX fortune.'
function fortune:action(msg)

6
otouto/plugins/gImages.lua Executable file → Normal file
View File

@ -20,11 +20,9 @@ function gImages:init(config)
end
gImages.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('image', true):t('i', true):t('insfw', true).table
gImages.doc = [[```
]]..config.cmd_pat..[[image <query>
gImages.doc = config.cmd_pat .. [[image <query>
Returns a randomized top result from Google Images. Safe search is enabled by default; use "]] .. config.cmd_pat .. [[insfw" to disable it. NSFW results will not display an image preview.
Alias: ]]..config.cmd_pat..[[i
```]]
Alias: ]] .. config.cmd_pat .. 'i'
end
gImages.command = 'image <query>'

6
otouto/plugins/gMaps.lua Executable file → Normal file
View File

@ -7,11 +7,9 @@ gMaps.command = 'location <query>'
function gMaps:init(config)
gMaps.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('location', true):t('loc', true).table
gMaps.doc = [[```
]]..config.cmd_pat..[[location <query>
gMaps.doc = config.cmd_pat .. [[location <query>
Returns a location from Google Maps.
Alias: ]]..config.cmd_pat..[[loc
```]]
Alias: ]] .. config.cmd_pat .. 'loc'
end
function gMaps:action(msg, config)

6
otouto/plugins/gSearch.lua Executable file → Normal file
View File

@ -9,11 +9,9 @@ gSearch.command = 'google <query>'
function gSearch:init(config)
gSearch.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('g', true):t('google', true):t('gnsfw', true).table
gSearch.doc = [[```
]]..config.cmd_pat..[[google <query>
gSearch.doc = config.cmd_pat .. [[google <query>
Returns four (if group) or eight (if private message) results from Google. Safe search is enabled by default, use "]] .. config.cmd_pat .. [[gnsfw" to disable it.
Alias: ]]..config.cmd_pat..[[g
```]]
Alias: ]] .. config.cmd_pat .. 'g'
end
function gSearch:action(msg, config)

0
otouto/plugins/greetings.lua Executable file → Normal file
View File

6
otouto/plugins/hackernews.lua Executable file → Normal file
View File

@ -9,10 +9,8 @@ hackernews.command = 'hackernews'
function hackernews:init(config)
hackernews.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('hackernews', true):t('hn', true).table
hackernews.doc = [[```
Returns four (if group) or eight (if private message) top stories from Hacker News.
Alias: ]]..config.cmd_pat..[[hn
```]]
hackernews.doc = [[Returns four (if group) or eight (if private message) top stories from Hacker News.
Alias: ]] .. config.cmd_pat .. 'hn'
end
function hackernews:action(msg, config)

6
otouto/plugins/hearthstone.lua Executable file → Normal file
View File

@ -37,11 +37,9 @@ function hearthstone:init(config)
end
hearthstone.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('hearthstone', true):t('hs').table
hearthstone.doc = [[```
]]..config.cmd_pat..[[hearthstone <query>
hearthstone.doc = config.cmd_pat .. [[hearthstone <query>
Returns Hearthstone card info.
Alias: ]]..config.cmd_pat..[[hs
```]]
Alias: ]] .. config.cmd_pat .. 'hs'
end
hearthstone.command = 'hearthstone <query>'

41
otouto/plugins/help.lua Executable file → Normal file
View File

@ -8,54 +8,45 @@ local utilities = require('otouto.utilities')
local help_text
function help:init(config)
local commandlist = {}
help_text = '*Available commands:*\n'..config.cmd_pat
for _,plugin in ipairs(self.plugins) do
if plugin.command then
table.insert(commandlist, plugin.command)
--help_text = help_text .. '\n• '..config.cmd_pat .. plugin.command:gsub('%[', '\\[')
if plugin.doc then
plugin.help_word = utilities.get_word(plugin.command, 1)
end
end
end
table.insert(commandlist, 'help [command]')
table.sort(commandlist)
help_text = help_text .. table.concat(commandlist, '\n'..config.cmd_pat) .. '\nArguments: <required> [optional]'
help_text = help_text:gsub('%[', '\\[')
help.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('help', true):t('h', true).table
help.doc = config.cmd_pat .. 'help [command] \nReturns usage information for a given command.'
end
function help:action(msg)
local input = utilities.input(msg.text_lower)
-- Attempts to send the help message via PM.
-- If msg is from a group, it tells the group whether the PM was successful.
if not input then
if input then
for _,plugin in ipairs(self.plugins) do
if plugin.help_word == input:gsub('^/', '') then
local output = '*Help for* _' .. plugin.help_word .. '_ *:*\n' .. plugin.doc
utilities.send_message(self, msg.chat.id, output, true, nil, true)
return
end
end
utilities.send_reply(self, msg, 'Sorry, there is no help for that command.')
else
-- Attempt to send the help message via PM.
-- If msg is from a group, tell the group whether the PM was successful.
local res = utilities.send_message(self, msg.from.id, help_text, true, nil, true)
if not res then
utilities.send_reply(self, msg, 'Please [message me privately](http://telegram.me/' .. self.info.username .. '?start=help) for a list of commands.', true)
elseif msg.chat.type ~= 'private' then
utilities.send_reply(self, msg, 'I have sent you the requested information in a private message.')
end
return
end
for _,plugin in ipairs(self.plugins) do
if plugin.command and utilities.get_word(plugin.command, 1) == input and plugin.doc then
local output = '*Help for* _' .. utilities.get_word(plugin.command, 1) .. '_ *:*\n' .. plugin.doc
utilities.send_message(self, msg.chat.id, output, true, nil, true)
return
end
end
utilities.send_reply(self, msg, 'Sorry, there is no help for that command.')
end
return help

5
otouto/plugins/imdb.lua Executable file → Normal file
View File

@ -9,10 +9,7 @@ imdb.command = 'imdb <query>'
function imdb:init(config)
imdb.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('imdb', true).table
imdb.doc = [[```
]]..config.cmd_pat..[[imdb <query>
Returns an IMDb entry.
```]]
imdb.doc = config.cmd_pat .. 'imdb <query> \nReturns an IMDb entry.'
end
function imdb:action(msg, config)

6
otouto/plugins/lastfm.lua Executable file → Normal file
View File

@ -16,13 +16,11 @@ function lastfm:init(config)
end
lastfm.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('lastfm', true):t('np', true):t('fmset', true).table
lastfm.doc = [[```
]]..config.cmd_pat..[[np [username]
lastfm.doc = config.cmd_pat .. [[np [username]
Returns what you are or were last listening to. If you specify a username, info will be returned for that username.
]] .. config.cmd_pat .. [[fmset <username>
Sets your last.fm username. Otherwise, ]]..config.cmd_pat..[[np will use your Telegram username. Use "]]..config.cmd_pat..[[fmset --" to delete it.
```]]
Sets your last.fm username. Otherwise, ]] .. config.cmd_pat .. [[np will use your Telegram username. Use "]] .. config.cmd_pat .. [[fmset --" to delete it.]]
end
lastfm.command = 'lastfm'

View File

@ -5,7 +5,7 @@ local utilities = require('otouto.utilities')
function me:init(config)
me.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('me', true).table
me.command = 'me'
me.doc = '`Returns userdata stored by the bot.`'
me.doc = 'Returns userdata stored by the bot.'
end
function me:action(msg, config)

6
otouto/plugins/nick.lua Executable file → Normal file
View File

@ -6,10 +6,8 @@ nick.command = 'nick <nickname>'
function nick:init(config)
nick.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('nick', true).table
nick.doc = [[```
]]..config.cmd_pat..[[nick <nickname>
Set your nickname. Use "]]..config.cmd_pat..[[nick --" to delete it.
```]]
nick.doc = config.cmd_pat .. [[nick <nickname>
Set your nickname. Use "]] .. config.cmd_pat .. 'nick --" to delete it.'
end
function nick:action(msg, config)

0
otouto/plugins/ping.lua Executable file → Normal file
View File

6
otouto/plugins/pokedex.lua Executable file → Normal file
View File

@ -9,11 +9,9 @@ pokedex.command = 'pokedex <query>'
function pokedex:init(config)
pokedex.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('pokedex', true):t('dex', true).table
pokedex.doc = [[```
]]..config.cmd_pat..[[pokedex <query>
pokedex.doc = config.cmd_pat .. [[pokedex <query>
Returns a Pokedex entry from pokeapi.co.
Alias: ]]..config.cmd_pat..[[dex
```]]
Alias: ]] .. config.cmd_pat .. 'dex'
end
function pokedex:action(msg, config)

View File

@ -0,0 +1,108 @@
local utilities = require('otouto.utilities')
local pgc = {}
function pgc:init(config)
pgc.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('gocalc', true).table
pgc.doc = config.cmd_pat .. [[gocalc <required candy> <number of Pokémon> <number of candy>
Calculates the number of Pokémon that must be transferred before evolving, how many evolutions the user is able to perform, and how many Pokémon and candy will be left over.
All arguments must be positive numbers. Batch jobs may be performed by separating valid sets of arguments by lines.
Example (forty pidgeys and three hundred pidgey candies):
]] .. config.cmd_pat .. 'gocalc 12 40 300'
pgc.command = 'gocalc <required candy> <#pokemon> <#candy>'
end
-- This function written by Juan Potato. MIT-licensed.
local pidgey_calc = function(candies_to_evolve, mons, candies)
local transferred = 0;
local evolved = 0;
while true do
if math.floor(candies / candies_to_evolve) == 0 or mons == 0 then
break
else
mons = mons - 1
candies = candies - candies_to_evolve + 1
evolved = evolved + 1
if mons == 0 then
break
end
end
end
while true do
if (candies + mons) < (candies_to_evolve + 1) or mons == 0 then
break
end
while candies < candies_to_evolve do
transferred = transferred + 1
mons = mons - 1
candies = candies + 1
end
mons = mons - 1
candies = candies - candies_to_evolve + 1
evolved = evolved + 1
end
return {
transfer = transferred,
evolve = evolved,
leftover_mons = mons,
leftover_candy = candies
}
end
local single_job = function(input)
local req_candy, mons, candies = input:match('^(%d+) (%d+) (%d+)$')
req_candy = tonumber(req_candy)
mons = tonumber(mons)
candies = tonumber(candies)
if not (req_candy and mons and candies) then
return { err = 'Invalid input: Three numbers expected.' }
elseif req_candy > 400 then
return { err = 'Invalid required candy: Maximum is 400.' }
elseif mons > 1000 then
return { err = 'Invalid number of Pokémon: Maximum is 1000.' }
elseif candies > 10000 then
return { err = 'Invalid number of candies: Maximum is 10000.' }
else
return pidgey_calc(req_candy, mons, candies)
end
end
function pgc:action(msg)
local input = utilities.input(msg.text)
if not input then
utilities.send_reply(self, msg, pgc.doc, true)
return
end
input = input .. '\n'
local output = ''
local total_evolutions = 0
for line in input:gmatch('(.-)\n') do
local info = single_job(line)
output = output .. '`' .. line .. '`\n'
if info.err then
output = output .. info.err .. '\n\n'
else
total_evolutions = total_evolutions + info.evolve
local s = '*Transfer:* %s. \n*Evolve:* %s (%s XP, %s minutes). \n*Leftover:* %s mons, %s candy.\n\n'
s = s:format(info.transfer, info.evolve, info.evolve..'k', info.evolve*0.5, info.leftover_mons, info.leftover_candy)
output = output .. s
end
end
local s = '*Total evolutions:* %s. \n*Recommendation:* %s'
local recommendation
local egg_count = math.floor(total_evolutions/60)
if egg_count < 1 then
recommendation = 'Wait until you have atleast sixty Pokémon to evolve before using a lucky egg.'
else
recommendation = 'Use %s lucky egg(s) for %s evolutions.'
recommendation = recommendation:format(egg_count, egg_count*60)
end
s = s:format(total_evolutions, recommendation)
output = output .. s
utilities.send_reply(self, msg, output, true)
end
return pgc

View File

@ -9,10 +9,8 @@ function pokemon_go:init(config)
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).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.
```]]
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.]]
local db = self.database.pokemon_go
if not db then
self.database.pokemon_go = {}

View File

@ -7,10 +7,7 @@ preview.command = 'preview <link>'
function preview:init(config)
preview.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('preview', true).table
preview.doc = [[```
]]..config.cmd_pat..[[preview <link>
Returns a full-message, "unlinked" preview.
```]]
preview.doc = config.cmd_pat .. 'preview <link> \nReturns a full-message, "unlinked" preview.'
end
function preview:action(msg)

2
otouto/plugins/pun.lua Executable file → Normal file
View File

@ -3,7 +3,7 @@ local pun = {}
local utilities = require('otouto.utilities')
pun.command = 'pun'
pun.doc = '`Returns a pun.`'
pun.doc = 'Returns a pun.'
function pun:init(config)
pun.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('pun').table

2
otouto/plugins/reactions.lua Executable file → Normal file
View File

@ -11,7 +11,7 @@ local reactions = {}
local utilities = require('otouto.utilities')
reactions.command = 'reactions'
reactions.doc = '`Returns a list of "reaction" emoticon commands.`'
reactions.doc = 'Returns a list of "reaction" emoticon commands.'
local mapping = {
['shrug'] = '¯\\_(ツ)_/¯',

6
otouto/plugins/reddit.lua Executable file → Normal file
View File

@ -9,11 +9,9 @@ reddit.command = 'reddit [r/subreddit | query]'
function reddit:init(config)
reddit.triggers = utilities.triggers(self.info.username, config.cmd_pat, {'^/r/'}):t('reddit', true):t('r', true):t('r/', true).table
reddit.doc = [[```
]]..config.cmd_pat..[[reddit [r/subreddit | query]
reddit.doc = config.cmd_pat .. [[reddit [r/subreddit | query]
Returns the top posts or results for a given subreddit or query. If no argument is given, returns the top posts from r/all. Querying specific subreddits is not supported.
Aliases: ]]..config.cmd_pat..[[r, /r/subreddit
```]]
Aliases: ]] .. config.cmd_pat .. 'r, /r/subreddit'
end
local format_results = function(posts)

View File

@ -8,10 +8,7 @@ function remind:init(config)
self.database.reminders = self.database.reminders or {}
remind.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('remind', true).table
remind.doc = [[```
]]..config.cmd_pat..[[remind <duration> <message>
Repeats a message after a duration of time, in minutes.
```]]
remind.doc = config.cmd_pat .. 'remind <duration> <message> \nRepeats a message after a duration of time, in minutes.'
end
function remind:action(msg)

View File

@ -5,12 +5,10 @@ local utilities = require('otouto.utilities')
function setandget:init(config)
self.database.setandget = self.database.setandget or {}
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>
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]
Returns the stored value or a list of stored values.
```]]
Returns the stored value or a list of stored values.]]
end
setandget.command = 'set <name> <value>'

View File

@ -6,10 +6,7 @@ shout.command = 'shout <text>'
function shout:init(config)
shout.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('shout', true).table
shout.doc = [[```
]]..config.cmd_pat..[[shout <text>
Shouts something. Input may be the replied-to message.
```]]
shout.doc = config.cmd_pat .. 'shout <text> \nShouts something. Input may be the replied-to message.'
end
function shout:action(msg)

5
otouto/plugins/slap.lua Executable file → Normal file
View File

@ -6,10 +6,7 @@ slap.command = 'slap [target]'
function slap:init(config)
slap.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('slap', true).table
slap.doc = [[```
]]..config.cmd_pat..[[slap [target]
Slap somebody.
```]]
slap.doc = config.cmd_pat .. 'slap [target] \nSlap somebody.'
end
local slaps = {

6
otouto/plugins/time.lua Executable file → Normal file
View File

@ -8,10 +8,8 @@ time.command = 'time <location>'
function time:init(config)
time.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('time', true).table
time.doc = [[```
]]..config.cmd_pat..[[time <location>
Returns the time, date, and timezone for the given location.
```]]
time.doc = config.cmd_pat .. [[time <location>
Returns the time, date, and timezone for the given location.]]
end
function time:action(msg, config)

6
otouto/plugins/translate.lua Executable file → Normal file
View File

@ -9,10 +9,8 @@ translate.command = 'translate [text]'
function translate:init(config)
translate.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('translate', true):t('tl', true).table
translate.doc = [[```
]]..config.cmd_pat..[[translate [text]
Translates input or the replied-to message into the bot's language.
```]]
translate.doc = config.cmd_pat .. [[translate [text]
Translates input or the replied-to message into the bot's language.]]
end
function translate:action(msg, config)

6
otouto/plugins/urbandictionary.lua Executable file → Normal file
View File

@ -10,11 +10,9 @@ urbandictionary.command = 'urbandictionary <query>'
function urbandictionary:init(config)
urbandictionary.triggers = utilities.triggers(self.info.username, config.cmd_pat)
:t('urbandictionary', true):t('ud', true):t('urban', true).table
urbandictionary.doc = [[```
]]..config.cmd_pat..[[urbandictionary <query>
urbandictionary.doc = config.cmd_pat .. [[urbandictionary <query>
Returns a definition from Urban Dictionary.
Aliases: ]]..config.cmd_pat..[[ud, ]]..config.cmd_pat..[[urban
```]]
Aliases: ]] .. config.cmd_pat .. 'ud, ' .. config.cmd_pat .. 'urban'
end
function urbandictionary:action(msg, config)

6
otouto/plugins/weather.lua Executable file → Normal file
View File

@ -13,10 +13,8 @@ function weather:init(config)
end
weather.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('weather', true).table
weather.doc = [[```
]]..config.cmd_pat..[[weather <location>
Returns the current weather conditions for a given location.
```]]
weather.doc = config.cmd_pat .. [[weather <location>
Returns the current weather conditions for a given location.]]
end
weather.command = 'weather <location>'

5
otouto/plugins/whoami.lua Executable file → Normal file
View File

@ -6,10 +6,9 @@ whoami.command = 'whoami'
function whoami:init(config)
whoami.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('who', true):t('whoami').table
whoami.doc = [[```
whoami.doc = [[
Returns user and chat info for you or the replied-to message.
Alias: ]]..config.cmd_pat..[[who
```]]
Alias: ]] .. config.cmd_pat .. 'who'
end
function whoami:action(msg)

6
otouto/plugins/wikipedia.lua Executable file → Normal file
View File

@ -9,11 +9,9 @@ wikipedia.command = 'wikipedia <query>'
function wikipedia:init(config)
wikipedia.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('wikipedia', true):t('wiki', true):t('w', true).table
wikipedia.doc = [[```
]]..config.cmd_pat..[[wikipedia <query>
wikipedia.doc = config.cmd_pat .. [[wikipedia <query>
Returns an article from Wikipedia.
Aliases: ]]..config.cmd_pat..[[w, ]]..config.cmd_pat..[[wiki
```]]
Aliases: ]] .. config.cmd_pat .. 'w, ' .. config.cmd_pat .. 'wiki'
end
local get_title = function(search)

6
otouto/plugins/xkcd.lua Executable file → Normal file
View File

@ -8,10 +8,8 @@ xkcd.command = 'xkcd [i]'
function xkcd:init(config)
xkcd.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('xkcd', true).table
xkcd.doc = [[```
]]..config.cmd_pat..[[xkcd [i]
Returns the latest xkcd strip and its alt text. If a number is given, returns that number strip. If "r" is passed in place of a number, returns a random strip.
```]]
xkcd.doc = config.cmd_pat .. [[xkcd [i]
Returns the latest xkcd strip and its alt text. If a number is given, returns that number strip. If "r" is passed in place of a number, returns a random strip.]]
end
function xkcd:action(msg, config)

6
otouto/plugins/youtube.lua Executable file → Normal file
View File

@ -15,11 +15,9 @@ function youtube:init(config)
end
youtube.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('youtube', true):t('yt', true).table
youtube.doc = [[```
]]..config.cmd_pat..[[youtube <query>
youtube.doc = config.cmd_pat .. [[youtube <query>
Returns the top result from YouTube.
Alias: ]]..config.cmd_pat..[[yt
```]]
Alias: ]] .. config.cmd_pat .. 'yt'
end
youtube.command = 'youtube <query>'

0
otouto/utilities.lua Executable file → Normal file
View File