I should probably commit now. Less global magic!

This commit is contained in:
Brayden Banks
2016-04-08 14:12:02 -07:00
parent 550d0743b7
commit acb679f8fa
41 changed files with 1213 additions and 1241 deletions

View File

@ -1,26 +1,30 @@
local command = 'about'
local doc = '`Returns information about the bot.`'
local about = {}
local triggers = {
local bindings = require('bindings')
about.command = 'about'
about.doc = '`Returns information about the bot.`'
about.triggers = {
''
}
local action = function(msg)
function about:action(msg)
-- Filthy hack, but here is where we'll stop forwarded messages from hitting
-- other plugins.
if msg.forward_from then return end
local message = config.about_text .. '\nBased on @otouto v'..version..' by topkecleon.'
local message = self.config.about_text .. '\nBased on @otouto v'..self.version..' by topkecleon.'
if msg.new_chat_participant and msg.new_chat_participant.id == bot.id then
sendMessage(msg.chat.id, message, true)
if msg.new_chat_participant and msg.new_chat_participant.id == self.info.id then
bindings.sendMessage(self, msg.chat.id, message, true)
return
elseif msg.text_lower:match('^/about[@'..bot.username..']*') then
sendMessage(msg.chat.id, message, true)
elseif msg.text_lower:match('^/about[@'..self.info.username..']*') then
bindings.sendMessage(self, msg.chat.id, message, true)
return
elseif msg.text_lower:match('^/start') then
sendMessage(msg.chat.id, message, true)
bindings.sendMessage(self, msg.chat.id, message, true)
return
end
@ -28,9 +32,4 @@ local action = function(msg)
end
return {
action = action,
triggers = triggers,
doc = doc,
command = command
}
return about

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,13 @@
local command = 'apod [date]'
local doc = [[```
local apod = {}
local HTTPS = require('ssl.https')
local JSON = require('cjson')
local URL = require('socket.url')
local bindings = require('bindings')
local utilities = require('utilities')
apod.command = 'apod [date]'
apod.doc = [[```
/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.
@ -10,31 +18,29 @@ Returns the explanation of the APOD.
Source: nasa.gov
```]]
local triggers = {
'^/apod[@'..bot.username..']*',
'^/apodhd[@'..bot.username..']*',
'^/apodtext[@'..bot.username..']*'
}
function apod:init()
apod.triggers = utilities.triggers(self.info.username)
:t('apod', true):t('apodhd', true):t('apodtext', true).table
end
local action = function(msg)
function apod:action(msg)
if not config.nasa_api_key then
config.nasa_api_key = 'DEMO_KEY'
if not self.config.nasa_api_key then
self.config.nasa_api_key = 'DEMO_KEY'
end
local input = msg.text:input()
local caption = ''
local input = utilities.input(msg.text)
local date = '*'
local disable_page_preview = false
local url = 'https://api.nasa.gov/planetary/apod?api_key=' .. config.nasa_api_key
local url = 'https://api.nasa.gov/planetary/apod?api_key=' .. self.config.nasa_api_key
if input then
if input:match('(%d+)%-(%d+)%-(%d+)$') then
url = url .. '&date=' .. URL.escape(input)
date = date .. input
else
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
bindings.sendMessage(self, msg.chat.id, apod.doc, true, msg.message_id, true)
return
end
else
@ -45,14 +51,14 @@ local action = function(msg)
local jstr, res = HTTPS.request(url)
if res ~= 200 then
sendReply(msg, config.errors.connection)
bindings.sendReply(self, msg, self.config.errors.connection)
return
end
local jdat = JSON.decode(jstr)
if jdat.error then
sendReply(msg, config.errors.results)
bindings.sendReply(msg, self.config.errors.results)
return
end
@ -62,7 +68,7 @@ local action = function(msg)
img_url = jdat.hdurl or jdat.url
end
output = date .. '[' .. jdat.title .. '](' .. img_url .. ')'
local output = date .. '[' .. jdat.title .. '](' .. img_url .. ')'
if string.match(msg.text, '^/apodtext*') then
output = output .. '\n' .. jdat.explanation
@ -73,13 +79,8 @@ local action = function(msg)
output = output .. '\nCopyright: ' .. jdat.copyright
end
sendMessage(msg.chat.id, output, disable_page_preview, nil, true)
bindings.sendMessage(self, msg.chat.id, output, disable_page_preview, nil, true)
end
return {
action = action,
triggers = triggers,
doc = doc,
command = command
}
return apod

View File

@ -1,13 +1,17 @@
local command = 'bandersnatch'
local doc = [[```
local bandersnatch = {}
local bindings = require('bindings')
local utilities = require('utilities')
bandersnatch.command = 'bandersnatch'
bandersnatch.doc = [[```
Shun the frumious Bandersnatch.
Alias: /bc
```]]
local triggers = {
'^/bandersnatch[@'..bot.username..']*',
'^/bc[@'..bot.username..']*'
}
function bandersnatch:init()
bandersnatch.triggers = utilities.triggers(self.info.username):trigger('bandersnatch'):trigger('bc').table
end
local fullnames = { "Wimbledon Tennismatch", "Rinkydink Curdlesnoot", "Butawhiteboy Cantbekhan", "Benadryl Claritin", "Bombadil Rivendell", "Wanda's Crotchfruit", "Biblical Concubine", "Syphilis Cankersore", "Buckminster Fullerene", "Bourgeoisie Capitalist" }
@ -15,7 +19,7 @@ local firstnames = { "Bumblebee", "Bandersnatch", "Broccoli", "Rinkydink", "Bomb
local lastnames = { "Coddleswort", "Crumplesack", "Curdlesnoot", "Calldispatch", "Humperdinck", "Rivendell", "Cuttlefish", "Lingerie", "Vegemite", "Ampersand", "Cumberbund", "Candycrush", "Clombyclomp", "Cragglethatch", "Nottinghill", "Cabbagepatch", "Camouflage","Creamsicle", "Curdlemilk", "Upperclass", "Frumblesnatch", "Crumplehorn", "Talisman", "Candlestick", "Chesterfield", "Bumbersplat", "Scratchnsniff", "Snugglesnatch", "Charizard", "Carrotstick", "Cumbercooch", "Crackerjack", "Crucifix", "Cuckatoo", "Cockletit", "Collywog", "Capncrunch", "Covergirl", "Cumbersnatch", "Countryside","Coggleswort", "Splishnsplash", "Copperwire", "Animorph", "Curdledmilk", "Cheddarcheese", "Cottagecheese", "Crumplehorn", "Snickersbar", "Banglesnatch", "Stinkyrash", "Cameltoe", "Chickenbroth", "Concubine", "Candygram", "Moldyspore", "Chuckecheese", "Cankersore", "Crimpysnitch", "Wafflesmack", "Chowderpants", "Toodlesnoot", "Clavichord", "Cuckooclock", "Oxfordshire", "Cumbersome", "Chickenstrips", "Battleship", "Commonwealth", "Cunningsnatch", "Custardbath", "Kryptonite", "Curdlesnoot", "Cummerbund", "Coochyrash", "Crackerdong", "Crackerdong", "Curdledong", "Crackersprout", "Crumplebutt", "Colonist", "Coochierash", "Thundersnatch" }
local action = function(msg)
function bandersnatch:action(msg)
local message
@ -25,13 +29,8 @@ local action = function(msg)
message = firstnames[math.random(#firstnames)] .. ' ' .. lastnames[math.random(#lastnames)]
end
sendReply(msg, message)
bindings.sendReply(self, msg, message)
end
return {
action = action,
triggers = triggers,
command = command,
desc = desc
}
return bandersnatch

View File

@ -1,54 +1,54 @@
if not config.biblia_api_key then
print('Missing config value: biblia_api_key.')
print('bible.lua will not be enabled.')
return
local bible = {}
local HTTP = require('socket.http')
local URL = require('socket.url')
local bindings = require('bindings')
local utilities = require('utilities')
function bible:init()
if not self.config.biblia_api_key then
print('Missing config value: biblia_api_key.')
print('bible.lua will not be enabled.')
return
end
bible.triggers = utilities.triggers(self.info.username):t('bible', true):t('b', true).table
end
local command = 'bible <reference>'
local doc = [[```
bible.command = 'bible <reference>'
bible.doc = [[```
/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: /b
```]]
local triggers = {
'^/bible*[@'..bot.username..']*',
'^/b[@'..bot.username..']* ',
'^/b[@'..bot.username..']*$'
}
function bible:action(msg)
local action = function(msg)
local input = msg.text:input()
local input = utilities.input(msg.text)
if not input then
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
bindings.sendMessage(self, msg.chat.id, self.doc, true, msg.message_id, true)
return
end
local url = 'http://api.biblia.com/v1/bible/content/ASV.txt?key=' .. config.biblia_api_key .. '&passage=' .. URL.escape(input)
local url = 'http://api.biblia.com/v1/bible/content/ASV.txt?key=' .. self.config.biblia_api_key .. '&passage=' .. URL.escape(input)
local message, res = HTTP.request(url)
if not message or res ~= 200 or message:len() == 0 then
url = 'http://api.biblia.com/v1/bible/content/KJVAPOC.txt?key=' .. config.biblia_api_key .. '&passage=' .. URL.escape(input)
url = 'http://api.biblia.com/v1/bible/content/KJVAPOC.txt?key=' .. self.config.biblia_api_key .. '&passage=' .. URL.escape(input)
message, res = HTTP.request(url)
end
if not message or res ~= 200 or message:len() == 0 then
message = config.errors.results
message = self.config.errors.results
end
if message:len() > 4000 then
message = 'The text is too long to post here. Try being more specific.'
end
sendReply(msg, message)
bindings.sendReply(self, msg, message)
end
return {
action = action,
triggers = triggers,
command = command,
doc = doc
}
return bible

View File

@ -1,24 +1,31 @@
-- This plugin will allow the admin to blacklist users who will be unable to
-- use the bot. This plugin should be at the top of your plugin list in config.
if not database.blacklist then
database.blacklist = {}
local blacklist = {}
local bindings = require('bindings')
local utilities = require('utilities')
function blacklist:init()
if not self.database.blacklist then
self.database.blacklist = {}
end
end
local triggers = {
blacklist.triggers = {
''
}
local action = function(msg)
function blacklist:action(msg)
if database.blacklist[msg.from.id_str] then return end
if database.blacklist[msg.chat.id_str] then return end
if self.database.blacklist[msg.from.id_str] then return end
if self.database.blacklist[msg.chat.id_str] then return end
if not msg.text:match('^/blacklist') then return true end
if msg.from.id ~= config.admin then return end
if msg.from.id ~= self.config.admin then return end
local target = user_from_message(msg)
local target = utilities.user_from_message(self, msg)
if target.err then
sendReply(msg, target.err)
bindings.sendReply(self, msg, target.err)
return
end
@ -26,17 +33,14 @@ local triggers = {
target.name = 'Group'
end
if database.blacklist[tostring(target.id)] then
database.blacklist[tostring(target.id)] = nil
sendReply(msg, target.name .. ' has been removed from the blacklist.')
if self.database.blacklist[tostring(target.id)] then
self.database.blacklist[tostring(target.id)] = nil
bindings.sendReply(self, msg, target.name .. ' has been removed from the blacklist.')
else
database.blacklist[tostring(target.id)] = true
sendReply(msg, target.name .. ' has been added to the blacklist.')
self.database.blacklist[tostring(target.id)] = true
bindings.sendReply(self, msg, target.name .. ' has been added to the blacklist.')
end
end
return {
action = action,
triggers = triggers
}
return blacklist

View File

@ -1,21 +1,28 @@
local command = 'calc <expression>'
local doc = [[```
local calc = {}
local URL = require('socket.url')
local HTTPS = require('ssl.https')
local bindings = require('bindings')
local utilities = require('utilities')
calc.command = 'calc <expression>'
calc.doc = [[```
/calc <expression>
Returns solutions to mathematical expressions and conversions between common units. Results provided by mathjs.org.
```]]
local triggers = {
'^/calc[@'..bot.username..']*'
}
function calc:init()
calc.triggers = utilities.triggers(self.info.username):t('calc', true).table
end
local action = function(msg)
function calc:action(msg)
local input = msg.text:input()
local input = utilities.input(msg.text)
if not input then
if msg.reply_to_message and msg.reply_to_message.text then
input = msg.reply_to_message.text
else
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
bindings.sendMessage(msg.chat.id, calc.doc, true, msg.message_id, true)
return
end
end
@ -24,19 +31,14 @@ local action = function(msg)
local output = HTTPS.request(url)
if not output then
sendReply(msg, config.errors.connection)
bindings.sendReply(self, msg, self.config.errors.connection)
return
end
output = '`' .. output .. '`'
sendMessage(msg.chat.id, output, true, msg.message_id, true)
bindings.sendMessage(self, msg.chat.id, output, true, msg.message_id, true)
end
return {
action = action,
triggers = triggers,
command = command,
doc = doc
}
return calc

View File

@ -1,38 +1,39 @@
if not config.thecatapi_key then
print('Missing config value: thecatapi_key.')
print('cats.lua will be enabled, but there are more features with a key.')
local cats = {}
local HTTP = require('socket.http')
local bindings = require('bindings')
local utilities = require('utilities')
function bindings:init()
if not self.config.thecatapi_key then
print('Missing config value: thecatapi_key.')
print('cats.lua will be enabled, but there are more features with a key.')
end
end
local command = 'cat'
local doc = '`Returns a cat!`'
cats.command = 'cat'
cats.doc = '`Returns a cat!`'
local triggers = {
'^/cat[@'..bot.username..']*$'
}
cats.triggers = utilities.triggers():t('cat')
local action = function(msg)
function cats:action(msg)
local url = 'http://thecatapi.com/api/images/get?format=html&type=jpg'
if config.thecatapi_key then
url = url .. '&api_key=' .. config.thecatapi_key
if self.config.thecatapi_key then
url = url .. '&api_key=' .. self.config.thecatapi_key
end
local str, res = HTTP.request(url)
if res ~= 200 then
sendReply(msg, config.errors.connection)
bindings.sendReply(msg, self.config.errors.connection)
return
end
str = str:match('<img src="(.-)">')
local output = '[Cat!]('..str..')'
sendMessage(msg.chat.id, output, false, nil, true)
bindings.sendMessage(self, msg.chat.id, output, false, nil, true)
end
return {
action = action,
triggers = triggers,
doc = doc,
command = command
}
return cats

View File

@ -10,7 +10,7 @@ local triggers = {
local action = function(msg)
local input = msg.text_lower:input()
local input = utilities.input(msg.text_lower)
if not input then
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
return

View File

@ -16,7 +16,7 @@ local action = function(msg)
sendChatAction(msg.chat.id, 'upload_photo')
local input = msg.text:input()
local input = utilities.input(msg.text)
if not input then input = os.date('%F') end
if not input:match('^%d%d%d%d%-%d%d%-%d%d$') then input = os.date('%F') end

View File

@ -10,7 +10,7 @@ local triggers = {
local action = function(msg)
local input = msg.text:input()
local input = utilities.input(msg.text)
if not input then
sendMessage(msg.chat.id, doc, true, msg.message_id, true)

View File

@ -27,7 +27,7 @@ local triggers = {
local action = function(msg)
local input = msg.text:input()
local input = utilities.input(msg.text)
if not input then
if msg.reply_to_message and msg.reply_to_message.text then
input = msg.reply_to_message.text

View File

@ -13,7 +13,7 @@ local triggers = {
local action = function(msg)
local input = msg.text:input()
local input = utilities.input(msg.text)
if not input then
if msg.reply_to_message and msg.reply_to_message.text then
input = msg.reply_to_message.text

View File

@ -14,7 +14,7 @@ local triggers = {
local action = function(msg)
local input = msg.text:input()
local input = utilities.input(msg.text)
if not input then
if msg.reply_to_message and msg.reply_to_message.text then
input = msg.reply_to_message.text

View File

@ -96,7 +96,7 @@ end
local action = function(msg)
local input = msg.text_lower:input()
local input = utilities.input(msg.text_lower)
if not input then
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
return

View File

@ -22,7 +22,7 @@ local triggers = {
local action = function(msg)
local input = msg.text_lower:input()
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.

View File

@ -10,7 +10,7 @@ local triggers = {
local action = function(msg)
local input = msg.text:input()
local input = utilities.input(msg.text)
if not input then
if msg.reply_to_message and msg.reply_to_message.text then
input = msg.reply_to_message.text

View File

@ -24,7 +24,7 @@ local triggers = {
local action = function(msg)
local input = msg.text:input()
local input = utilities.input(msg.text)
if string.match(msg.text, '^/lastfm') then
sendMessage(msg.chat.id, doc, true, msg.message_id, true)

View File

@ -19,7 +19,7 @@ local triggers = {
local action = function(msg)
local input = msg.text:input()
local input = utilities.input(msg.text)
if string.match(msg.text, '^/librefm') then
sendMessage(msg.chat.id, doc, true, msg.message_id, true)

View File

@ -8,7 +8,7 @@ local action = function(msg)
return
end
local input = msg.text:input()
local input = utilities.input(msg.text)
if not input then
sendReply(msg, 'Please enter a string to load.')
return

View File

@ -7,7 +7,7 @@ local action = function(msg)
local target = database.users[msg.from.id_str]
if msg.from.id == config.admin and (msg.reply_to_message or msg.text:input()) then
if msg.from.id == config.admin and (msg.reply_to_message or utilities.input(msg.text)) then
target = user_from_message(msg)
if target.err then
sendReply(msg, target.err)

View File

@ -59,7 +59,7 @@ local commands = {
['^/modcast[@'..bot.username..']*'] = function(msg)
local output = msg.text:input()
local output = utilities.input(msg.text)
if not output then
return 'You must include a message.'
end
@ -149,7 +149,7 @@ local commands = {
return config.moderation.errors.not_admin
end
local modid = msg.text:input()
local modid = utilities.input(msg.text)
if not modid then
if msg.reply_to_message then
@ -184,7 +184,7 @@ local commands = {
end
end
local userid = msg.text:input()
local userid = utilities.input(msg.text)
local usernm = userid
if msg.reply_to_message then
@ -216,7 +216,7 @@ local commands = {
end
end
local userid = msg.text:input()
local userid = utilities.input(msg.text)
local usernm = userid
if msg.reply_to_message then

View File

@ -22,7 +22,7 @@ local action = function(msg)
end
local output
local input = msg.text:input()
local input = utilities.input(msg.text)
if not input then
if database.users[target.id_str].nickname then
output = target.name .. '\'s nickname is "' .. database.users[target.id_str].nickname .. '".'

View File

@ -12,7 +12,7 @@ local triggers = {
local action = function(msg)
local input = msg.text_lower:input()
local input = utilities.input(msg.text_lower)
if not input then
if msg.reply_to_message and msg.reply_to_message.text then
input = msg.reply_to_message.text

View File

@ -10,7 +10,7 @@ local triggers = {
local action = function(msg)
local input = msg.text:input()
local input = utilities.input(msg.text)
if not input then
sendMessage(msg.chat.id, doc, true, nil, true)

View File

@ -15,12 +15,12 @@ local triggers = {
local action = function(msg)
msg.text_lower = msg.text_lower:gsub('/r/', '/r r/')
local input = msg.text_lower:input()
local input = utilities.input(msg.text_lower)
if msg.text_lower:match('^/r/') then
msg.text_lower = msg.text_lower:gsub('/r/', '/r r/')
input = get_word(msg.text_lower, 1)
else
input = msg.text_lower:input()
input = utilities.input(msg.text_lower)
end
local url

View File

@ -15,7 +15,7 @@ local triggers = {
local action = function(msg)
local input = msg.text:input()
local input = utilities.input(msg.text)
database.setandget[msg.chat.id_str] = database.setandget[msg.chat.id_str] or {}
if msg.text_lower:match('^/set') then
@ -26,7 +26,7 @@ local action = function(msg)
end
local name = get_word(input:lower(), 1)
local value = input:input()
local value = utilities.input(input)
if not name or not value then
sendMessage(msg.chat.id, doc, true, nil, true)

View File

@ -8,7 +8,7 @@ local action = function(msg)
return
end
local input = msg.text:input()
local input = utilities.input(msg.text)
input = input:gsub('', '--')
if not input then

View File

@ -10,7 +10,7 @@ local triggers = {
local action = function(msg)
local input = msg.text:input()
local input = utilities.input(msg.text)
if not input then
sendMessage(msg.chat.id, doc, true, msg.message_id, true)

View File

@ -94,7 +94,7 @@ local slaps = {
local action = function(msg)
local victim = msg.text:input()
local victim = utilities.input(msg.text)
if msg.reply_to_message then
if database.users[tostring(msg.reply_to_message.from.id)].nickname then
victim = database.users[tostring(msg.reply_to_message.from.id)].nickname

View File

@ -10,7 +10,7 @@ local triggers = {
local action = function(msg)
local input = msg.text:input()
local input = utilities.input(msg.text)
if not input then
if msg.reply_to_message and msg.reply_to_message.text then
input = msg.reply_to_message.text

View File

@ -11,7 +11,7 @@ local triggers = {
local action = function(msg)
local input = msg.text:input()
local input = utilities.input(msg.text)
if not input then
if msg.reply_to_message and msg.reply_to_message.text then
input = msg.reply_to_message.text

View File

@ -14,7 +14,7 @@ local triggers = {
local action = function(msg)
local input = msg.text:input()
local input = utilities.input(msg.text)
if not input then
if msg.reply_to_message and msg.reply_to_message.text then
input = msg.reply_to_message.text

View File

@ -16,7 +16,7 @@ local triggers = {
local action = function(msg)
local input = msg.text:input()
local input = utilities.input(msg.text)
if not input then
if msg.reply_to_message and msg.reply_to_message.text then
input = msg.reply_to_message.text

View File

@ -14,7 +14,7 @@ local triggers = {
local action = function(msg)
local input = msg.text:input()
local input = utilities.input(msg.text)
if not input then
if msg.reply_to_message and msg.reply_to_message.text then
input = msg.reply_to_message.text

View File

@ -10,7 +10,7 @@ local triggers = {
local action = function(msg)
local input = msg.text:input()
local input = utilities.input(msg.text)
local jstr, res = HTTP.request('http://xkcd.com/info.0.json')
if res ~= 200 then

View File

@ -21,7 +21,7 @@ local triggers = {
local action = function(msg)
local input = msg.text:input()
local input = utilities.input(msg.text)
if not input then
if msg.reply_to_message and msg.reply_to_message.text then
input = msg.reply_to_message.text