mirror of
https://github.com/lubuntu-team/lugito.git
synced 2025-03-10 06:31:09 +00:00
Improve the logic.
Summary: Bot now connects to the IRC server only once, responds to ping requests, and reconnects in case of failure. Test Plan: Test in prod Reviewers: tsimonq2 Reviewed By: tsimonq2 Subscribers: tsimonq2 Differential Revision: https://phab.lubuntu.me/D1
This commit is contained in:
parent
1c1cc3f828
commit
9020af538a
3
.arcconfig
Normal file
3
.arcconfig
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"phabricator.uri" : "https://phab.lubuntu.me/"
|
||||
}
|
65
lugito
65
lugito
@ -4,6 +4,7 @@ import http
|
||||
import hmac
|
||||
import json
|
||||
import socket
|
||||
import threading
|
||||
from flask import Flask, request
|
||||
from pprint import pprint
|
||||
from hashlib import sha256
|
||||
@ -15,33 +16,17 @@ phab = Phabricator(host=website+"/api/", token="API KEY")
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
def isnewtask(task):
|
||||
modified = None
|
||||
|
||||
for data in task:
|
||||
if modified != None:
|
||||
if data["dateCreated"] == data["dateModified"] and data["dateCreated"] == modified:
|
||||
modified = data["dateCreated"]
|
||||
newtask = True
|
||||
else:
|
||||
newtask = False
|
||||
break
|
||||
else:
|
||||
modified = data["dateCreated"]
|
||||
|
||||
return newtask
|
||||
|
||||
def sendnotice(message):
|
||||
username = "lugito"
|
||||
server = "irc.freenode.net"
|
||||
port = 6667
|
||||
channel = "#lubuntu-devel"
|
||||
global username
|
||||
username = "lugito"
|
||||
server = "irc.freenode.net"
|
||||
port = 6667
|
||||
channel = "#lubuntu-devel"
|
||||
|
||||
def connecttoirc():
|
||||
global conn, username
|
||||
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
conn.connect((server, port))
|
||||
|
||||
setup = False
|
||||
|
||||
usersuffix = 0
|
||||
while setup == False:
|
||||
response = conn.recv(512).decode("utf-8")
|
||||
@ -64,6 +49,22 @@ def sendnotice(message):
|
||||
if "366" in response:
|
||||
setup = True
|
||||
|
||||
def isnewtask(task):
|
||||
modified = None
|
||||
for data in task:
|
||||
if modified != None:
|
||||
if data["dateCreated"] == data["dateModified"] and data["dateCreated"] == modified:
|
||||
modified = data["dateCreated"]
|
||||
newtask = True
|
||||
else:
|
||||
newtask = False
|
||||
break
|
||||
else:
|
||||
modified = data["dateCreated"]
|
||||
|
||||
return newtask
|
||||
|
||||
def sendnotice(message):
|
||||
conn.send("NOTICE {} :{}\r\n".format(channel, message).encode("utf-8"))
|
||||
|
||||
def ircmessage(objectstr, who, body, link):
|
||||
@ -80,6 +81,18 @@ def ircmessage(objectstr, who, body, link):
|
||||
# Aaaaand, send it off!
|
||||
sendnotice(message)
|
||||
|
||||
def listenirc():
|
||||
while 1:
|
||||
ircmsg = conn.recv(512)
|
||||
if len(ircmsg) == 0:
|
||||
print("Connection lost, reconnecting!")
|
||||
connecttoirc()
|
||||
continue
|
||||
ircmsg = ircmsg.decode("UTF-8").strip('\n\r')
|
||||
print(ircmsg)
|
||||
if ircmsg.find("PING :") != -1:
|
||||
conn.send(bytes("PONG :pingis\n", "UTF-8"))
|
||||
|
||||
@app.route("/", methods=["POST"])
|
||||
def main():
|
||||
data = request.data
|
||||
@ -173,4 +186,8 @@ def main():
|
||||
return "OK"
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=5000)
|
||||
connecttoirc()
|
||||
t = threading.Thread(target=listenirc)
|
||||
t.daemon = True
|
||||
t.start()
|
||||
app.run(host="0.0.0.0", port=5000)
|
Loading…
x
Reference in New Issue
Block a user