Re-implement the previous commit in a much better way.

pull/1/head
Simon Quigley 6 years ago
parent fa063eec73
commit adcfa174e3

@ -82,15 +82,11 @@ def ircmessage(objectstr, who, body, link):
# Aaaaand, send it off!
sendnotice(message)
def ircbot(message):
message = message.split(" :" + username + ": info")[1]
def gettaskinfo(task):
sendmessage = ""
for item in message.split():
if item.startswith("T"):
try:
# We only need the task number.
taskinfo = phab.maniphest.info(task_id=int(item.split("T")[1]))
taskinfo = phab.maniphest.info(task_id=int(task.split("T")[1]))
sendmessage = sendmessage + "\x033[\x03"
@ -124,7 +120,22 @@ def ircbot(message):
sendnotice(sendmessage)
# If someone wrote something like "Tblah", obviously that's not right.
except ValueError:
sendnotice("\x034Error: " + item.strip() + "is an invalid task reference.\x03")
sendnotice("\x034Error: " + task.strip() + "is an invalid task reference.\x03")
return None
def ircbot(message, msgtype):
if msgtype == "info":
message = message.split(" :" + username + ": info")[1]
for item in message.split():
if item.startswith("T"):
gettaskinfo(item.strip())
elif msgtype == "link":
for item in message.split("https://phab.lubuntu.me/"):
if item.split()[0].strip().startswith("T"):
gettaskinfo(item.split()[0].strip())
else:
sendnotice("\x034Error: unknown command.\x03")
return None
def listenirc():
while True:
@ -137,10 +148,10 @@ def listenirc():
print(ircmsg)
if ircmsg.find("PING :") != -1:
conn.send(bytes("PONG :pingis\n", "UTF-8"))
elif ircmsg.find(" :" + username + ": ") != -1:
ircbot(ircmsg)
elif ircmsg.find(" :" + username + ": info") != -1:
ircbot(ircmsg, "info")
elif ircmsg.find("https://phab.lubuntu.me/T") != -1:
ircbot(ircmsg.split("https://phab.lubuntu.me/")[1])
ircbot(ircmsg, "link")
@app.route("/", methods=["POST"])
def main():

Loading…
Cancel
Save