kpcyrd/chaturbate-chat
function run()
local room = getopt('room')
if not room then
return 'You need to set a room to monitor'
end
local session = http_mksession()
local req = http_request(session, 'GET', 'https://chaturbate.com/', {})
local r = http_fetch(req)
if last_err() then return end
req = http_request(session, 'GET', 'https://chaturbate.com/', {})
local csrf = req['cookies']['csrftoken']
headers = {}
headers['Referer'] = 'https://chaturbate.com/' .. room .. '/'
headers['X-CSRFToken'] = csrf
req = http_request(session, 'POST', 'https://chaturbate.com/api/getchatuserlist/', {
headers=headers,
form={
sort_by='a',
private='false',
roomname=room,
},
})
local r = http_fetch(req)
local m = regex_find_all(',([^,]+?)\\|', r['text'])
debug('found users: ' .. #m)
for i=1, #m do
local user = m[i][2]
local id = db_select('account', 'chaturbate.com/' .. user)
if id then
local now = sn0int_time()
debug('found in ' .. room .. ': ' .. user)
db_add('account', {
service='chaturbate.com',
username=user,
last_seen=now,
})
db_activity({
topic='kpcyrd/chaturbate-chat:' .. user,
time=now,
content={
room=room,
},
})
end
end
end