Basic bot in a working state.
This commit is contained in:
parent
47abf398a1
commit
6c4161f17a
15 changed files with 2710 additions and 1 deletions
59
plugin/calc.lua
Normal file
59
plugin/calc.lua
Normal file
|
@ -0,0 +1,59 @@
|
|||
-- Nice plugin that uses google's calculator
|
||||
-- Google's calculator is fun!
|
||||
-- How to use:
|
||||
-- !calc <Operation>
|
||||
-- Example:
|
||||
-- !calc 1+1
|
||||
-- !calc sin(0.5)
|
||||
-- !calc speed of light / sin(0.5)
|
||||
|
||||
local socket = require("socket")
|
||||
local url = require("socket.url")
|
||||
local json = require("json")
|
||||
|
||||
plugin.calc = function (target, from, arg)
|
||||
local sb_env= {ipairs = ipairs,
|
||||
next = next,
|
||||
pairs = pairs,
|
||||
pcall = pcall,
|
||||
tonumber = tonumber,
|
||||
tostring = tostring,
|
||||
type = type,
|
||||
unpack = unpack,
|
||||
coroutine = { create = coroutine.create, resume = coroutine.resume,
|
||||
running = coroutine.running, status = coroutine.status,
|
||||
wrap = coroutine.wrap },
|
||||
string = { byte = string.byte, char = string.char, find = string.find,
|
||||
format = string.format, gmatch = string.gmatch, gsub = string.gsub,
|
||||
len = string.len, lower = string.lower, match = string.match,
|
||||
rep = string.rep, reverse = string.reverse, sub = string.sub,
|
||||
upper = string.upper },
|
||||
table = { insert = table.insert, maxn = table.maxn, remove = table.remove,
|
||||
sort = table.sort },
|
||||
math = { abs = math.abs, acos = math.acos, asin = math.asin,
|
||||
atan = math.atan, atan2 = math.atan2, ceil = math.ceil, cos = math.cos,
|
||||
cosh = math.cosh, deg = math.deg, exp = math.exp, floor = math.floor,
|
||||
fmod = math.fmod, frexp = math.frexp, huge = math.huge,
|
||||
ldexp = math.ldexp, log = math.log, log10 = math.log10, max = math.max,
|
||||
min = math.min, modf = math.modf, pi = math.pi, pow = math.pow,
|
||||
rad = math.rad, random = math.random, sin = math.sin, sinh = math.sinh,
|
||||
sqrt = math.sqrt, tan = math.tan, tanh = math.tanh },
|
||||
os = { clock = os.clock, difftime = os.difftime, time = os.time },}
|
||||
local func = load("return function() return "..arg.." end", "IIRC", "t", sb_env)
|
||||
local status, result
|
||||
if func then
|
||||
status, result = pcall(func())
|
||||
else
|
||||
status = true
|
||||
result = "INVALID CALL"
|
||||
end
|
||||
|
||||
local r
|
||||
if status then
|
||||
if not result then result = "nil" end
|
||||
r = arg .. " = " .. tostring(result)
|
||||
else
|
||||
r = "ERROR: " .. result
|
||||
end
|
||||
irc.say(target,r)
|
||||
end
|
64
plugin/google.lua
Normal file
64
plugin/google.lua
Normal file
|
@ -0,0 +1,64 @@
|
|||
-- The google plugin, just type:
|
||||
-- !google <stuff to search>
|
||||
|
||||
local urltool = require("socket.url")
|
||||
local json = require("json")
|
||||
local socket = require("socket")
|
||||
|
||||
local htmlEntities = {
|
||||
[" "] = " ",
|
||||
[" "] = " ",
|
||||
["""] = '"',
|
||||
["""] = '"',
|
||||
["'"] = "'",
|
||||
["'"] = "'",
|
||||
["&"] = "&",
|
||||
["&"] = "&",
|
||||
["<"] = "<",
|
||||
["<"] = "<",
|
||||
[">"] = ">",
|
||||
[">"] = ">",
|
||||
["¡"] = "¡",
|
||||
["¡"] = "¡",
|
||||
["´"] = "´",
|
||||
["´"] = "´",
|
||||
["Ñ"] = "Ñ",
|
||||
["Ñ"] = "Ñ",
|
||||
["ñ"] = "ñ",
|
||||
["ñ"] = "ñ",
|
||||
}
|
||||
|
||||
local function parseHtmlEntites(s)
|
||||
local ret =string.gsub(s,"&.-;", function(input) return htmlEntities[input] or "?" end)
|
||||
return ret
|
||||
end
|
||||
|
||||
plugin.google = function (target, from, arg)
|
||||
local search = urltool.escape(arg)
|
||||
local result, error, header = socket.http.request( 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q='..search.."&safe=off")
|
||||
|
||||
if error == 200 and result then
|
||||
local jsonTable = json.decode(result)
|
||||
if (jsonTable.responseData.results[1]) then
|
||||
--unicode hax
|
||||
content = string.gsub(urltool.unescape(jsonTable.responseData.results[1].content), "u(%x%x%x%x)",
|
||||
function(c)
|
||||
local status, result = pcall(string.char, "0x"..c)
|
||||
if status then
|
||||
return result
|
||||
else
|
||||
return "u"..c
|
||||
end
|
||||
end)
|
||||
--parse html tags to irc tags
|
||||
content = string.gsub(content,"(<b>)", "")
|
||||
content = string.gsub(content,"(</b>)", "")
|
||||
content = string.gsub(content,"(<u>)", "")
|
||||
content = string.gsub(content,"(</u>)", "")
|
||||
content = string.gsub(content,"(<i>)", "")
|
||||
content = string.gsub(content,"(</i>)", "")
|
||||
result = urltool.unescape(jsonTable.responseData.results[1].url).." "..content
|
||||
irc.say(target, parseHtmlEntites(result))
|
||||
end
|
||||
end
|
||||
end
|
47
plugin/twitch.lua
Normal file
47
plugin/twitch.lua
Normal file
|
@ -0,0 +1,47 @@
|
|||
-- Getting information out of Twitch
|
||||
|
||||
local json = require("json")
|
||||
local https = require("ssl.https")
|
||||
local ltn12 = require("ltn12")
|
||||
|
||||
local function fetch_data (endpoint)
|
||||
local response = {}
|
||||
local r,c,h = https.request{url = "https://api.twitch.tv/kraken/"..endpoint,
|
||||
headers = { accept = "application/vnd.twitchtv.v3+json"},
|
||||
sink = ltn12.sink.table(response)}
|
||||
return json.decode(table.concat(response))
|
||||
end
|
||||
|
||||
local function elapsed (datestring)
|
||||
local pattern = "(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+)Z"
|
||||
local year,month,day,hour,min,sec = datestring:match(pattern)
|
||||
local start = os.time({year = year, month = month, day = day, hour = hour, min = min, sec = sec, isdst = false })
|
||||
local utcnow = os.time(os.date("!*t"))
|
||||
local diff = utcnow-start
|
||||
local hours = math.floor(diff/3600)
|
||||
local mins = math.floor(diff/60 - hours*60)
|
||||
h = hours > 1 and " hours" or " hour"
|
||||
m = mins > 1 and " minutes" or " minute"
|
||||
if hours > 0 then
|
||||
return hours..h.." and "..mins..m
|
||||
else
|
||||
return mins..m
|
||||
end
|
||||
end
|
||||
|
||||
plugin.uptime = function (target, from, arg)
|
||||
local channel = string.sub(target, 2)
|
||||
if arg and arg ~= "" then
|
||||
channel = arg
|
||||
end
|
||||
local j = fetch_data("streams/"..channel)
|
||||
if j.stream then
|
||||
if j.stream ~= json.decode("null") then
|
||||
irc.say(target, j.stream.channel.display_name.." is streaming ["..j.stream.game.."] for "..elapsed(j.stream.created_at)..".")
|
||||
else
|
||||
irc.say(target, channel.." is not streaming anything right now.")
|
||||
end
|
||||
else
|
||||
irc.say(target, "Stream "..channel.." not found.")
|
||||
end
|
||||
end
|
22
plugin/youtube.lua
Normal file
22
plugin/youtube.lua
Normal file
|
@ -0,0 +1,22 @@
|
|||
local https = require("ssl.https")
|
||||
local json = require("json")
|
||||
local ltn12 = require("ltn12")
|
||||
|
||||
local function fetch_title (videoid)
|
||||
--local response = {}
|
||||
local r,c,h = https.request("https://www.googleapis.com/youtube/v3/videos?id="..videoid.."&key="..yt_api_key.."&part=snippet&fields=items(snippet(title))")
|
||||
local j = json.decode(r)
|
||||
if j then
|
||||
return j.items[1].snippet.title
|
||||
end
|
||||
end
|
||||
|
||||
callback.youtube = function (target, from, message)
|
||||
local ytid = message:match(".*https?://w?w?w?%.?youtube.com/watch%?v=(%g*)%s*.*")
|
||||
if ytid then
|
||||
local t = fetch_title(ytid)
|
||||
if t then
|
||||
irc.say(target, "Youtube video title: "..t)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue