-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sender.rb
128 lines (120 loc) · 3.34 KB
/
Sender.rb
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
require "json"
require "net/http"
require 'net/https'
require "uri"
def sendData(url, data)
uri = URI.parse(url)
req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
req.body = data
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true, :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
http.request(req)
end
return res
end
def setStatus(res)
case res.code.to_i
when 200
@status.text = "Sent!"
when 301
@status.text = "The resource has moved."
when 400
@status.text = "Error: Bad Request"
_data = JSON.parse(res.body)
_statusText = "";
if _data.has_key? 'icon_url'
_statusText += "\nIcon URL Error\n#{_data["icon_url"][0]}"
end
if _data.has_key? 'attachments'
_dt = _data['attachments'][0]
if _dt.include? 'color'
_statusText += "\nInvalid Color Value"
end
if _dt.include? 'footer_icon'
_statusText += "\nInvalid Footer Icon Value"
end
if _dt.include? 'author_icon'
_statusText += "\nInvalid Author Icon Value"
end
if _dt.include? 'author_link'
_statusText += "\nInvalid Author Link Value"
end
end
if _data.has_key? 'message'
_statusText += "\n#{_data['message']}"
end
@status.text = _statusText
when 401
@status.text = "Error: Unauthorized"
when 404
@status.text = "The resource wasn't found."
when 405
@status.text = "Error: The method isn't allowed."
when 429
@status.text = "Ratelimited. Try again later."
else
@status.text = "Error while sending request: #{res.code}."
end
end
Shoes.app width: 400, height: 600, resizable: false, title: "Webhook Sender" do
stack do
flow do
@url = edit_line "Webhook URL"
@url.style(width: 0.5)
@send = button "Send" do
@data = {
"username" => @username.text(),
"icon_url" => @icon_url.text(),
"text" => @text.text(),
"attachments" => [
{
"color" => @color.text(),
"title" => @title.text(),
"pretext" => @pretext.text(),
"author_name" => @author_name.text(),
"author_link" => @author_link.text(),
"author_icon" => @author_icon.text(),
"footer" => @footer.text(),
"footer_icon" => @footer_icon.text(),
"text" => @attachment_text.text()
}
]
}
@status.text = "Sending"
@k = sendData(@url.text(), @data.to_json)
setStatus(@k)
end
@send.style(width: 0.5)
end
flow do
@metaStack = stack do
@username = edit_line "Username"
@icon_url = edit_line "Icon URL"
end
@text = edit_box "Text"
@metaStack.style(width: 0.5)
@text.style(width: 0.5, height: 56)
end
title "Attachments", align: "center"
flow do
@attachmentStack = stack do
@color = edit_line "Color"
@title = edit_line "Title"
@pretext = edit_line "Pretext"
@author_name = edit_line "Author Name"
@author_link = edit_line "Author Link"
@author_icon = edit_line "Author Icon"
@footer = edit_line "Footer"
@footer_icon = edit_line "Footer Icon"
end
@attachment_text = edit_box "Text"
@attachmentStack.style(width: 0.5)
@attachment_text.style(width: 0.5, height: 224)
end
@status = para "Waiting..."
@status.style(align: "center", margin_top: 25)
flow do
@licence = para("Made by ", l = link('Mackan', click: "http://github.com/Sven65"))
@licence.style(bottom: 5, margin_top: 150, margin_right: 5, align: "right")
end
end
end