Commit 2fe28465 authored by awe's avatar awe
Browse files

Fixed unintended bugs and some broken regexes

Thanks Alkanor & Impuls for reporting the bugs :)
parent 3d6b3051
# docker build . -t ircbot:latest
# docker run -itd --restart=always -v $PWD:/home/ircbot --name ircbot ircbot:latest
From alpine
From alpine:3.10
LABEL maintainer "awe"
RUN apk update && apk upgrade
RUN apk add python3 python3-dev gcc musl-dev libffi-dev openssl-dev capstone py3-capstone py3-lxml py2-httplib2 py-requests
RUN apk add python3 python3-dev gcc musl-dev libffi-dev openssl-dev capstone py3-capstone py3-lxml py3-pip py3-httplib2 py-requests
RUN adduser -s /usr/sbin/nologin -k /dev/null -D -H -h /home/ircbot ircbot
RUN pip3 install TwitterAPI
......
......@@ -123,15 +123,16 @@ class IrcBot:
continue
# Received a ctcp command
pattern = "^:(.+)!.+ PRIVMSG " + self.name + " :" + chr(0x01)
pattern += "(.+)" + chr(0x01)
pattern = "^:(.+)!.+ PRIVMSG " + self.name + " :" + chr(0x01) + "(.+)" + chr(0x01)
m = re.search(pattern, data)
if m is not None:
self.ctcp(m.group(2), m.group(1))
continue
# Received a private message
if data.find("PRIVMSG") != -1:
m = re.search("^:(.+)![^ ]+ PRIVMSG ([^ ]+)(?:\s+):(.*)$", data)
if m is not None:
t = Parsemsg(self.server, self.name, data)
t.start()
if t.join_thread():
......
......@@ -25,6 +25,7 @@ from irc.ircaction import recordIrcAction
from datetime import datetime
import time
import socket
import string
import ssl
import console.term as term
import sys
......@@ -178,6 +179,14 @@ class IrcServer:
if self.bypassLog(content):
return
charset = string.ascii_letters + string.digits + '#-_.'
if any(c not in charset for c in self.server):
return
if any(c not in charset for c in file):
return
try:
f = None
......
......@@ -18,6 +18,7 @@
# You should have received a copy of the GNU General Public License
# along with W3-BoT. If not, see <http://www.gnu.org/licenses/>.
import string
from plugins.command import Command, USAGE
......@@ -57,17 +58,19 @@ class Rot(Command):
If nomod is set to 1, then usual modulo 26 is not performed.
"""
charset = string.ascii_letters + string.digits + string.punctuation + ' '
res = ""
for c in text:
ch = c
if nomod:
res += chr((ord(c) + n) % 127)
else:
if c >= 'a' and c <= 'z':
res += chr(ord('a') + (ord(c) - ord('a') + n) % 26)
elif c >= 'A' and c <= 'Z':
res += chr(ord('A') + (ord(c) - ord('A') + n) % 26)
else:
res += c
ch = chr((ord(c) + n) % 127)
elif c >= 'a' and c <= 'z':
ch = chr(ord('a') + (ord(c) - ord('a') + n) % 26)
elif c >= 'A' and c <= 'Z':
ch = chr(ord('A') + (ord(c) - ord('A') + n) % 26)
res += ch if ch in charset else repr(ch)[1:-1]
return res
@classmethod
......
......@@ -37,7 +37,7 @@ class Chuck(Command):
txt = response.read().decode()
regex = '<div class="factbody">(?:\s+)([^<]+)<div class="vote">'
regex = '<div class="card-body bg-light rounded">(?:\s+)<p class="card-text">([^<]+)</p>(?:\s+)</div>'
m = re.search(regex, txt)
if not m:
......
......@@ -40,7 +40,7 @@ class Vdm(Command):
txt = response.content.decode()
regex = '<div class="article-contents">\s*<a class="article-link" href="[^"]+">\s*([^\n]+)\s*</a>'
regex = '<a href="[^"]+" class="block text-[^"]+">\s*([^\n]+)\s*</a>'
m = re.search(regex, txt)
if m:
res = self.remove_html_tags("Aujourd'hui, %s" % m.group(1))
......
Supports Markdown
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