forked from AlliedEnvy/leroy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
replies.lua
56 lines (48 loc) · 1.58 KB
/
replies.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
local replies = {}
local json = require 'json'
function replies.ping(prefix, rest)
irc_client:pong(rest)
db_client:ping()
local base_url = "http://www.reddit.com"
local response, status_code, headers, status = http.request(base_url .. "/r/MechanicalKeyboards/new/.json?limit=10")
if status_code == 200 then
response = json.decode(response)
local posts = response.data.children
for i,post_container in ipairs(posts) do
local post = post_container.data
local new = db_client:hsetnx("irc:reddit:new_posts", post.id, post.created)
if new then
local text = "New post: '" .. post.title:match "^%s*(.-)%s*$" .. "' by " .. post.author
text = text .. " @ http://redd.it/" .. post.id
for _,nick in ipairs(db_client:smembers("irc:reddit:subscribed_users")) do
irc_client:privmsg(nick, text)
end
irc_client:privmsg("#Mechboards", text)
end
end
end
end
function replies.privmsg(prefix, rest)
local chan = rest:match('(%S+)')
local msg = rest:match(':(.*)')
local nick = prefix:match('(%S+)!')
local host = prefix:match('@(%S+)')
local cmd, args = msg:match('^!(%S+)(.*)')
if cmd then
cmd = cmd:lower()
args = args:split(" ")
end
if not chan:find('^#') then
chan = nick
end
db_client:sadd("irc:users:nicks", nick)
if type(commands[cmd]) == "function" then
local success, message = pcall(commands[cmd],chan, nick, args)
if not success then print(message) end
end
end
-- rpl_endofmotd
replies["376"] = function(prefix, rest)
irc_client:join("#Mechboards")
end
return replies