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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import asyncdispatch, telebot, httpclient, os, times, tables
const codes = {
"1xx": ("Informational response", false),
"100": ("Continue", true),
"101": ("Switching Protocols", true),
"102": ("Processing", false),
"103": ("Checkpoint", false),
"2xx": ("Success", false),
"200": ("Ok", true),
"201": ("Created", true),
"202": ("Accepted", true),
"203": ("Non-Authoritative Information", false),
"204": ("No Content", true),
"205": ("Reset Content", false),
"206": ("Partial Content", true),
"207": ("Multi-Status", true),
"208": ("Already Reported", false),
"218": ("This is fine", false),
"226": ("IM Used", false),
"3xx": ("Redirection", false),
"300": ("Multiple Choices", true),
"301": ("Moved Permanently", true),
"302": ("Found (Moved Temporarily)", true),
"303": ("See Other", true),
"304": ("Not Modified", true),
"305": ("Use Proxy", true),
"306": ("Switch Proxy", false),
"307": ("Temporary Redirect", true),
"308": ("Permanent Redirect", false),
"4xx": ("Client errors", false),
"400": ("Bad Request", true),
"401": ("Unauthorized", true),
"402": ("Payment Required", true),
"403": ("Forbidden", true),
"404": ("Not Found", true),
"405": ("Method Not Allowed", true),
"406": ("Not Acceptable", true),
"407": ("Proxy Authentication Required", false),
"408": ("Request Timeout", true),
"409": ("Conflict", true),
"410": ("Gone", true),
"411": ("Length Required", true),
"412": ("Precondition Failed", true),
"413": ("Request Entity Too Large", true),
"414": ("URI Too Long", true),
"415": ("Unsupported Media Type", true),
"416": ("Requested range not satisfiable", true),
"417": ("Expectation Failed", true),
"418": ("I’m a teapot", true),
"419": ("Page Expired", false),
"420": ("Enhance Your Calm", true),
"421": ("Misdirected Request", true),
"422": ("Unprocessable Entity", true),
"423": ("Locked", true),
"424": ("Failed Dependency", true),
"425": ("Unordered Collection", true),
"426": ("Upgrade Required", true),
"428": ("Precondition Required", false),
"429": ("Too Many Requests", true),
"431": ("Request Header Fields Too Large", true),
"440": ("Login Time-out", false),
"444": ("No Response", true),
"449": ("The request should be retried after doing the appropriate action", false),
"450": ("Blocked by Windows Parental Controls", true),
"451": ("Unavailable For Legal Reasons", true),
"494": ("Request header too large", false),
"495": ("SSL Certificate Error", false),
"496": ("SSL Certificate Required", false),
"497": ("HTTP Request Sent to HTTPS Port", false),
"499": ("Client Closed Request ", false),
"5xx": ("Server errors", false),
"500": ("Internal Server Error", true),
"501": ("Not Implemented", false),
"502": ("Bad Gateway", true),
"503": ("Service Unavailable", true),
"504": ("Gateway Timeout", true),
"505": ("HTTP Version not supported", false),
"506": ("Variant Also Negotiates", true),
"507": ("Insufficient Storage", true),
"508": ("Loop Detected", true),
"509": ("Bandwidth Limit Exceeded", true),
"510": ("Not Extended", true),
"511": ("Network Authentication Required", true),
"520": ("Unknown Error", false),
"521": ("Web Server Is Down", false),
"522": ("Connection Timed Out", false),
"523": ("Origin Is Unreachable", false),
"524": ("A Timeout Occurred", false),
"525": ("SSL Handshake Failed", false),
"526": ("Invalid SSL Certificate", false),
"527": ("Railgun Error", false),
"530": ("Site is frozen/Origin DNS Error", false),
"598": ("(Informal convention) Network read timeout error", false),
"599": ("Network connect timeout error", true),
"666": ("Number of the Beast", false),
"7xx": ("Other", false),
"70x": ("Inexcusable", false),
"701": ("Meh", false),
"702": ("Emacs", false),
"703": ("Explosion", false),
"704": ("Goto Fail", false),
"705": ("I wrote the code and missed the necessary validation by an oversight (see 795)", false),
"706": ("Delete Your Account", false),
"707": ("Can’t quit vi", false),
"71x": ("Novelty Implementations", false),
"710": ("PHP", false),
"711": ("Convenience Store", false),
"712": ("NoSQL", false),
"718": ("I am not a teapot", false),
"719": ("Haskell", false),
"72x": ("Edge Cases", false),
"720": ("Unpossible", false),
"721": ("Known unknowns", false),
"722": ("Unknown unknowns", false),
"723": ("Tricky", false),
"724": ("This line should be unreachable", false),
"725": ("It works on my machine", false),
"726": ("It’s a feature, not a bug", false),
"727": ("32 bits is plenty", false),
"728": ("It works in my timezone", false),
"73x": ("Fucking", false),
"730": ("Fucking npm", false),
"731": ("Fucking Rubygems", false),
"732": ("Fucking Unic�de", false),
"733": ("Fucking Deadlocks", false),
"734": ("Fucking Deferreds", false),
"735": ("Fucking IE", false),
"736": ("Fucking Race Conditions", false),
"737": ("FuckThreadsing ", false),
"738": ("Fucking Exactly-once Delivery", false),
"739": ("Fucking Windows", false),
"74x": ("Reserved for meritocracy related bullshit", false),
"75x": ("Syntax Errors", false),
"750": ("Didn’t bother to compile it", false),
"753": ("Syntax Error", false),
"754": ("Too many semi-colons", false),
"755": ("Not enough semi-colons", false),
"756": ("Insufficiently polite", false),
"757": ("Excessively polite", false),
"759": ("Unexpected \"T_PAAMAYIM_NEKUDOTAYIM\"", false),
"76x": ("Substance-Affected Developer", false),
"761": ("Hungover", false),
"762": ("Stoned", false),
"763": ("Under-Caffeinated", false),
"764": ("Over-Caffeinated", false),
"765": ("Railscamp", false),
"766": ("Sober", false),
"767": ("Drunk", false),
"768": ("Accidentally Took Sleeping Pills Instead Of Migraine Pills During Crunch Week", false),
"77x": ("Predictable Problems", false),
"771": ("Cached for too long", false),
"772": ("Not cached long enough", false),
"773": ("Not cached at all", false),
"774": ("Why was this cached?", false),
"775": ("Out of cash", false),
"776": ("Error on the Exception", false),
"777": ("Coincidence", false),
"778": ("Off By One Error", false),
"779": ("Off By Too Many To Count Error", false),
"78x": ("Somebody Else’s Problem", false),
"780": ("Project owner not responding", false),
"781": ("Operations", false),
"782": ("QA", false),
"783": ("It was a customer request, honestly", false),
"784": ("Management, obviously", false),
"785": ("TPS Cover Sheet not attached", false),
"786": ("Try it now", false),
"787": ("Further Funding Required", false),
"788": ("Designer’s final designs weren’t", false),
"789": ("Not my department", false),
"79x": ("Internet crashed", false),
"791": ("The Internet shut down due to copyright restrictions", false),
"792": ("Climate change driven catastrophic weather event", false),
"793": ("Zombie Apocalypse", false),
"794": ("Someone let PG near a REPL", false),
"795": ("#heartbleed (see 705)", false),
"796": ("Some DNS fuckery idno", false),
"797": ("This is the last page of the Internet. Go back", false),
"798": ("I checked the db backups cupboard and the cupboard was bare", false),
"799": ("End of the world", false),
"9xx": ("Proprietary Error", false)
}.toTable
proc httpstatuscodeCommand* (bot: Telebot, command: Command): Future[bool] {.async.} =
let code = codes.getOrDefault(command.params, ("I don't know about this status code", false))
if code[1]: # hazcat
discard existsOrCreateDir(getEnv("DATA_PATH") & "/tmp")
var tmpFile = getEnv("DATA_PATH") & "/tmp/" & $(toUnix(getTime())) & ".jpg"
var httpClient = newAsyncHttpClient()
await httpClient.downloadFile("https://http.cat/" & command.params & ".jpg", tmpFile)
discard await bot.sendPhoto(command.message.chat.id, "file://" & tmpFile, replyToMessageId = command.message.messageId)
removeFile(tmpFile)
discard await bot.sendMessage(command.message.chat.id, code[0])
else:
discard await bot.sendMessage(command.message.chat.id, code[0], replyToMessageId = command.message.messageId)