-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpcodes.py
More file actions
64 lines (57 loc) · 1.96 KB
/
Copy pathhttpcodes.py
File metadata and controls
64 lines (57 loc) · 1.96 KB
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
# -*- coding: utf-8 -*-
"""
http status codes
"""
import logging
from telegram import Bot, Update
import requests
import core
LOGGER = logging.getLogger("HTTP codes")
CODES = requests.get(
"https://github.com/for-GET/know-your-http-well/raw/master/json/status-codes.json").json()
MESSAGE = """
%(code)s - %(phrase)s
%(spec_title)s
%(description)s
Link to specification:%(spec_href)s
"""
PLUGINVERSION = 2
# Always name this variable as `plugin`
# If you dont, module loader will fail to load the plugin!
plugin = core.Plugin()
def getcode(code):
for code_info in CODES:
if code == code_info["code"]:
return code_info
raise NameError("No such code")
@plugin.command(command="/httpcode",
description="Sends information about specific http status code",
inline_supported=True,
required_args=1,
hidden=False)
def get_code(_: Bot, __: Update, ___, args): # pylint: disable=W0613
"""
Example usage:
User: /httpcode 451
Bot:451 - Unavailable For Legal Reasons
draft-ietf-httpbis-legally-restricted-status
"This status code indicates that the server is denying access to the resource in response to a legal demand."
Link to specification:https://tools.ietf.org/html/draft-ietf-httpbis-legally-restricted-status
"""
if len(args[0]) == 3:
try:
code = getcode(args[0])
except NameError:
return core.message("Cant find " + args[0], failed=True)
else:
return core.message(MESSAGE % code)
else:
return core.message("Invalid code passed:" + args[0], failed=True)
@plugin.ai("octobot.httpcode")
def ai_httpcode(bot, update, aidata):
try:
code = getcode(aidata["result"]["parameters"]["number"])
except NameError:
return core.message("I dont think it is a valid HTTP code at all...", failed=True)
else:
return core.message(aidata["result"]["fulfillment"]["speech"] % code)