Commit d758dbce authored by Mindiell's avatar Mindiell

Added tests; Using 'cite' column as a flag

parent dc796362
Pipeline #21 skipped
wantzel.ini
config.py
*.pyc
db.sqlite3
db*.sqlite3
wantzel.log
ve*/
......@@ -2,3 +2,4 @@
pylint
coverage
nose
mock
This diff is collapsed.
......@@ -231,7 +231,7 @@ class Wantzel(object):
channel = user
# Help command, specific
if "wantzel" in msg and ("help" in msg or "aide" in msg):
self.help(channel, msg)
self.help(user, channel, msg)
# Find known command
command = re.search("[!~](rp[acp]*|status|kill|help|stats|admin)", msg)
Utils.debug("Command: %s" % command)
......@@ -291,20 +291,22 @@ class Wantzel(object):
if not url:
return
# Managing flags
# LQdN is quoted
if "c" in command:
cite += 1
# the article speak about LQdN
if command.count("p") > 1:
cite += 2
# Archive this article
if "a" in command:
cite += 4
# Looking for such an article in database
cursor = get_cursor()
cursor.execute("SELECT id, note, provenance FROM presse WHERE url = %s", (url, ))
rows = cursor.fetchall()
if not rows:
# LQdN is quoted
if "c" in command:
cite += 2
# the article speak about LQdN
if command.count("p") > 1:
cite += 2
# Archive this article
if "a" in command:
note = -2
Utils.debug("Adding an article by %s: %s" % (user, url))
cursor.execute(
"""INSERT INTO presse SET
......@@ -344,21 +346,25 @@ class Wantzel(object):
# Looking for such an article in database
cursor = get_cursor()
cursor.execute("""
SELECT cite, published, nid, screenshot, fetched, seemscite, note
SELECT cite, nid, note
FROM presse
WHERE url = %s""", (url, ))
rows = cursor.fetchall()
if not rows:
self.send_message(channel, messages["status_unknown_article"] % user)
else:
message = "%s: note %s / " % (user, rows[0][6])
if rows[0][0] != "0":
message += "cite lqdn / "
if rows[0][1] == 1:
published = "publié (noeud %s) / " % rows[0][2]
message = "%s: note %s / " % (user, rows[0][2])
if rows[0][0] & 1:
message += "cite LQdN / "
if rows[0][0] & 2:
message += "parle de LQdN / "
if rows[0][0] & 4:
message += "archivé / "
if rows[0][1] > 0:
message += "publié (https://laquadrature.net/node/%s) / " % rows[0][1]
else:
published = "non publié / "
self.send_message(channel, message[:-2])
message += "non publié / "
self.send_message(channel, message[:-3])
def kill(self, user, channel, msg):
"""
......@@ -395,7 +401,6 @@ class Wantzel(object):
notes = [0, 3, 4]
notnull = 0
somethingatall = 0
result = ""
for note in notes:
notnull = 0
period_result = ""
......@@ -413,10 +418,9 @@ class Wantzel(object):
notnull = 1
somethingatall = 1
if notnull:
result = result + "note>=%s: " % note + period_result[:-2] + "\n"
self.send_message(channel, "note>=%s: " % note + period_result[:-2])
if somethingatall == 0:
result = messages["stats_bravo"] % periods[-1]
self.send_message(channel, result)
self.send_message(channel, messages["stats_bravo"] % periods[-1])
def admin(self, user, channel, msg):
"""
......@@ -447,7 +451,7 @@ class Wantzel(object):
names = []
for row in connection.execute("SELECT name FROM moderator"):
names.append(row[0].encode("utf-8"))
self.send_message(channel, messages["admin_list"] % ", ".join(names))
self.send_message(channel, messages["admin_list"] % ", ".join(sorted(names)))
else:
self.send_message(channel, messages["not_moderator"])
......@@ -462,7 +466,7 @@ class Wantzel(object):
connection = sqlite3.connect(config.sqlite_db)
result = re.search("~admin add (([^,]+, ?)+)?(.*)", msg)
if result.group(1):
names = [name for name in result.group(1).split(", ") if name != ""]
names = [name.strip() for name in result.group(1).split(",") if name.strip() != ""]
names.append(result.group(3))
# Do not add actual moderators
moderators = []
......@@ -492,7 +496,7 @@ class Wantzel(object):
names = []
result = re.search("~admin del (([^,]+, ?)+)?(.*)", msg)
if result.group(1):
names = [name for name in result.group(1).split(", ") if name != ""]
names = [name.strip() for name in result.group(1).split(",") if name.strip() != ""]
names.append(result.group(3))
names = list(set(names))
Utils.debug(names)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment