Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

Commit

Permalink
implement issue creation command
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Liao committed Jul 13, 2021
1 parent c878d97 commit baffad2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Binary file added __pycache__/chatbot.cpython-38.pyc
Binary file not shown.
11 changes: 10 additions & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@

def handler(room):
def _inner(activity):
if room != rid: return
if "e" in activity:
for x in activity["e"]:
if x["user_id"] == 281362 and x["content"] == "!!/swap-rooms":
send("I am now leaving this room. Goodbye!")
swap()
send("Hello! I am now operating in this room.")
if x["event_type"] == 1 and x["room_id"] == room:
if x["user_id"] == 296403: return
try:
Expand Down Expand Up @@ -46,8 +51,12 @@ def _inner(activity):

rid = 106764

def swap():
global rid
rid = 106765 - rid

rooms = {
k: chatbot.joinRoom(k, handler(k)) for k in [rid]
k: chatbot.joinRoom(k, handler(k)) for k in [1, 106764]
}

def send(message):
Expand Down
20 changes: 20 additions & 0 deletions webhook-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,26 @@ def receive_message():
- To evaluate Vyxal code, use "(execute|run|run code|evaluate)", followed by code, flags, and inputs inside inline code blocks (multiline code is not supported; provide multiline input in multiple code blocks)
- To ping everyone, use "hyperping" or "ping every(body|one)"
""")
match = re.match(r"^issue\s+((.+?)\s+)?<b>(.+?)</b>\s*(.*?)(\s+<code>.+?</code>)+$", without_ping)
if match:
_, repo, title, body, tags = match.groups()
repo = repo or "Vyxal"
tags = re.findall("<code>(.+?)</code>", without_ping)
r = requests.post(f"https://api.github.com/repos/Vyxal/{repo}/issues", headers = {
"Authorization": "token " + STORAGE["token"],
"Accept": "application/vnd.github.v3+json"
}, data = json.dumps({
"title": title,
"body": body,
"labels": tags
}))
if r.status_code == 404:
return f"{reply} failed to create the issue (404); make sure you have spelled the repository name correctly"
elif r.status_code != 201:
return f"{reply} failed to create the issue ({r.status_code}): {r.json()['message']}"
return ""
if re.match(r"^issue", without_ping):
return f"{reply} " + r"`!!/issue repository **title** body \`label\` \`label\`` - if the repository is not specified, it assumes `Vyxal/Vyxal`; the body can be omitted but it is recommended that you write a description; at least one label is required"
return ""

@app.route("/repo", methods = ["POST"])
Expand Down

0 comments on commit baffad2

Please sign in to comment.