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)