-
Notifications
You must be signed in to change notification settings - Fork 0
/
sender.lua
executable file
·78 lines (68 loc) · 2.23 KB
/
sender.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
require "bililive.config"
require "bililive.roominfo"
local notice = hs.notify.new()
notice:hasActionButton(false)
local function urlEncode(s)
s = string.gsub(s, "([^%w%.%- ])", function(c)
return string.format("%%%02X", string.byte(c)) end)
return string.gsub(s, " ", "+")
end
local function onSendSucceed(msg)
notice:title("发送成功")
notice:subTitle(msg)
end
local function onSendFailed()
notice:title("发送失败")
notice:subTitle("请检查配置信息或者网络状况")
end
local function sendDanmuku(msg)
local content, num = urlEncode(msg)
local link = "https://api.live.bilibili.com/msg/send"
.. "?color=16777215&fontsize=25&mode=1&msg=" .. content
.. "&rnd=" .. userRND
.. "&roomid=" .. roomID
.. "&bubble=0"
.. "&csrf_token=".. userCSRF
.. "&csrf=".. userCSRF
hs.http.asyncPost(link, nil,
{
["Accpet"] = "application/json, text/javascript, */*; q=0.01",
["Accept-Encoding"] = "gzip, deflate, br",
["User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36",
["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8",
["Cookie"] = userCookie
},
function(http_code, body, headers)
result = hs.json.decode(body)
if (http_code == 200 and result.code == 0) then
onSendSucceed(msg)
else
onSendFailed()
end
notice:send()
end
)
end
local chooser = hs.chooser.new(function(choice)
if choice ~= nil then
print(choice.msg)
sendDanmuku(choice.msg)
end
end)
chooser:queryChangedCallback(function(string)
local choices = {
{
["text"] = "发送弹幕:" .. string,
["subText"] = "到直播间 " .. roomName .. " (" .. roomID .. ")",
["msg"] = string
}
}
chooser:choices(choices)
end)
function showDanmukuSender()
chooser:show()
end
chooser:rows(1)
chooser:bgDark(true)
chooser:searchSubText(false)
hs.hotkey.bind({"cmd", "ctrl"}, "-", nil, function() chooser:show() end)