From 4bc8bc3c125c5be4b5dc5aab116eaf01afb88423 Mon Sep 17 00:00:00 2001 From: nemunaire Date: Tue, 7 Jul 2015 12:34:00 +0200 Subject: [PATCH] Dusting modules --- modules/bonneannee.py | 4 ++-- modules/cve.py | 42 ++++++++++++++++++++---------------------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/modules/bonneannee.py b/modules/bonneannee.py index d1eef72..a00efe0 100644 --- a/modules/bonneannee.py +++ b/modules/bonneannee.py @@ -9,7 +9,7 @@ from nemubot.event import ModuleEvent from nemubot.hooks import hook from nemubot.tools.countdown import countdown_format -nemubotversion = 3.4 +nemubotversion = 4.0 from more import Response @@ -54,7 +54,7 @@ def cmd_newyear(msg, yr): @hook("cmd_rgxp", data=yrn, regexp="^[0-9]{4}$") def cmd_timetoyear(msg, cur): - yr = int(msg.cmds[0]) + yr = int(msg.cmd) if yr == cur: return None diff --git a/modules/cve.py b/modules/cve.py index bc4e58c..fd28181 100644 --- a/modules/cve.py +++ b/modules/cve.py @@ -1,35 +1,33 @@ -import urllib.request from bs4 import BeautifulSoup +from urllib.parse import quote + from nemubot.hooks import hook +from nemubot.tools.web import getURLContent from more import Response -nemubotversion = 3.4 +"""CVE description""" -def help_tiny(): - return "CVE description" +nemubotversion = 4.0 -def help_full(): - return "No help " +BASEURL_MITRE = 'http://cve.mitre.org/cgi-bin/cvename.cgi?name=' +def get_cve(cve_id): + search_url = BASEURL_MITRE + quote(cve_id.upper()) + + soup = BeautifulSoup(getURLContent(search_url)) + desc = soup.body.findAll('td') + + return desc[17].text.replace("\n", " ") + " Moar at " + search_url + @hook("cmd_hook", "cve") def get_cve_desc(msg): - DESC_INDEX = 17 - BASEURL_MITRE = 'http://cve.mitre.org/cgi-bin/cvename.cgi?name=' + res = Response(channel=msg.channel) - cve_id = '' + for cve_id in msg.args: + if cve_id[:3].lower() != 'cve': + cve_id = 'cve-' + cve_id - if msg.cmds[1][:3].lower() == 'cve': - cve_id = msg.cmds[1] + res.append_message(get_cve(cve_id)) - else: - cve_id = 'cve-' + msg.cmds[1] - - search_url = BASEURL_MITRE + cve_id.upper() - - url = urllib.request.urlopen(search_url) - soup = BeautifulSoup(url) - - desc = soup.body.findAll('td') - - return Response(desc[DESC_INDEX].text.replace("\n", " ") + " Moar at " + search_url, msg.channel) + return res