...
 
Commits (3)
......@@ -9,7 +9,7 @@ messages = {
"""Bonjour, je suis le bot de la Quadrature du Net, vous pouvez me demander de l'aide si besoin. (wantzel help)""",
"help":
"""Mes commandes sont : ~help ~rp(cpa) ~status ~kill ~stats et ~admin.
"""Mes commandes sont : ~help ~rp(cpa) ~status ~flag ~kill ~stats et ~admin.
Pour plus d'informations, voir ici: https://wiki.laquadrature.net/Wantzel
Pour obtenir de l'aide sur une commande en particulier, il suffit de taper ~help <commande>""",
......@@ -25,6 +25,10 @@ messages = {
"""Cette commande sert à retrouver les informations concernant un article ajouté à la Revue de Presse (https://wiki.laquadrature.net/Revue_de_presse)
L'utilisation se fait sous la forme: ~status <url de l'article>""",
"help_flag":
"""Cette commande sert à modifier les flags d'un article ajouté à la Revue de Presse (https://wiki.laquadrature.net/Revue_de_presse)
L'utilisation se fait sous la forme: ~flag <url de l'article> <flag>. La liste des flags est accessible sur https://wiki.laquadrature.net/Wantzel""",
"help_stats":
"""Cette commande permet de fournir quelques statistiques sur la Revue de Presse (https://wiki.laquadrature.net/Revue_de_presse)
Les statistiques sont calculées sur des notes supérieurs ou égales à 0, 3, et 4. Et sur les 1, 3, 7, et 15 derniers jours.""",
......@@ -131,5 +135,9 @@ messages = {
"master_rp_taken_article":
"""Merci %s ! L'article est prêt pour la revue de presse !""",
"flag_update_done":
"%s a changé de flags",
"unknown_flag":
"Ce flag n'est pas supporté",
}
......@@ -167,6 +167,21 @@ class TestWantzel(unittest.TestCase):
"test: note 1 / publié (https://laquadrature.net/node/%s)" % i
)
def testFlagCommandForAnUnknownArticle(self):
self.wantzel.on_privmsg("test!test.me", "#test_channel", "~flag http://test.me/article p")
self.wantzel.send_message.assert_called_with(
"#test_channel",
messages["status_unknown_article"] % "test"
)
def testFlagCommandForAKnownArticle(self):
self.wantzel.on_privmsg("test!test.me", "#test_channel", "~rp http://test.me/article")
self.wantzel.on_privmsg("test!test.me", "#test_channel", "~flag http://test.me/article a")
self.wantzel.send_message.assert_called_with(
"test",
"test: note 1 / archivé / non publié"
)
def testStatsCommandWithNoArticle(self):
self.wantzel.on_privmsg("test!test.me", "#test_channel", "~stats")
self.wantzel.send_message.assert_called_with(
......
......@@ -368,7 +368,7 @@ class Wantzel(object):
if "wantzel" in msg and ("help" in msg or "aide" in msg):
self.help(user, channel, msg)
# Find known command
command = re.search("[!~](rp[acp]*|status|kill|help|stats|admin)", msg)
command = re.search("[!~](rp[acp]*|status|kill|help|stats|admin|flag)", msg)
Utils.debug("Command: %s" % command)
if command:
Utils.debug("group(0): %s" % command.group(0))
......@@ -383,6 +383,9 @@ class Wantzel(object):
elif command == "help":
Utils.debug("Calling self.help")
self.help(user, channel, msg)
elif command == "flag":
Utils.debug("Calling self.flag")
self.flag(command, user, channel, msg)
elif command == "kill":
Utils.debug("Calling self.kill")
self.kill(user, channel, msg)
......@@ -416,7 +419,7 @@ class Wantzel(object):
"""
Utils.debug("help command")
# Searching for a command after help keyword
command = re.search("[!~]help (help|rp|status|stats|kill|admin)", msg)
command = re.search("[!~]help (help|rp|status|flag|stats|kill|admin)", msg)
if command:
command = command.group(1)
self.send_message(user, messages["help_"+command])
......@@ -609,6 +612,74 @@ class Wantzel(object):
message += "non publié / "
self.send_message(channel, message[:-3])
def flag(self, command, user, channel, msg):
"""
Edit the article's flags
"""
Utils.debug("rp command : %s" % command)
Utils.debug("rp user : %s" % user)
Utils.debug("rp channel : %s" % channel)
Utils.debug("rp msg : %s" % msg)
url = get_url(msg)
Utils.debug("url: %s" % url)
if not url:
return
# Looking for such an article in database
cursor = get_cursor()
# We need to be able to retrieve an url with "http" or "https"
if url.startswith("https"):
url2 = "http" + url[5:]
else:
url2 = "https" + url[4:]
cursor.execute("""
SELECT id, cite
FROM presse
WHERE url = %s
OR url = %s""",
(url, url2)
)
rows = cursor.fetchall()
if not rows:
self.send_message(channel, messages["status_unknown_article"] % user)
return
flag = msg[-1]
flag_score = 0
# Matching each flag to its integer value
# LQdN is quoted
if flag == "c":
flag_score = 1
# the article speak about LQdN
if flag == "p":
flag_score = 2
# Archive this article
if flag == "a":
flag_score = 4
# Check if flag is known. m is 0, so not here.
if flag in ["c", "p", "a"]:
if flag_score & rows[0][1]:
Utils.debug("Removing the %s flag" % flag)
new_flag = rows[0][1] - flag_score
else:
Utils.debug("Adding the %s flag" % flag)
new_flag = rows[0][1] + flag_score
Utils.debug("New flag score: %s" % new_flag)
cursor.execute("""
UPDATE presse
SET cite=%s
WHERE id=%s""",
(new_flag, rows[0][0])
)
self.send_message(channel, messages["flag_update_done"] % url)
# Send flags to user in a private message
self.status("status", user, user, msg)
else:
Utils.debug("Unknown flag")
self.send_message(channel, messages["unknown_flag"])
def kill(self, user, channel, msg):
"""
Kill an article by setting its score to -100.
......