Forgot to add IRCBuffer.py when I renamed it from IRCLog.py. oops.
This commit is contained in:
parent
4045c55ba3
commit
5535bac4c7
1 changed files with 43 additions and 0 deletions
43
IRCBuffer.py
Normal file
43
IRCBuffer.py
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
import re
|
||||||
|
|
||||||
|
class BufferLine(object):
|
||||||
|
def __init__(self, sender, message, action, from_self):
|
||||||
|
self.sender = sender
|
||||||
|
self.message = message
|
||||||
|
self.action = action
|
||||||
|
self.from_self = from_self
|
||||||
|
|
||||||
|
class Buffer(object):
|
||||||
|
def __init__(self, bot):
|
||||||
|
self.lines = []
|
||||||
|
self.max_lines = 64
|
||||||
|
self._skip_next = False
|
||||||
|
def add_line(self, sender, message, action, from_self=False):
|
||||||
|
if not self._skip_next:
|
||||||
|
line = BufferLine(sender, message, action, from_self)
|
||||||
|
self.lines.insert(0, line)
|
||||||
|
if len(self.lines) > self.max_lines:
|
||||||
|
self.lines.pop()
|
||||||
|
self._skip_next = False
|
||||||
|
def get(self, index=0, **kwargs):
|
||||||
|
from_self = kwargs.get("from_self", True)
|
||||||
|
for line in self.lines:
|
||||||
|
if line.from_self and not from_self:
|
||||||
|
continue
|
||||||
|
return line
|
||||||
|
def find(self, pattern, **kwargs):
|
||||||
|
from_self = kwargs.get("from_self", True)
|
||||||
|
for_user = kwargs.get("for_user", "")
|
||||||
|
for_user = for_user.lower() if for_user else None
|
||||||
|
not_pattern = kwargs.get("not_pattern", None)
|
||||||
|
for line in self.lines:
|
||||||
|
if line.from_self and not from_self:
|
||||||
|
continue
|
||||||
|
elif re.search(pattern, line.message):
|
||||||
|
if not_pattern and re.search(not_pattern, line.message):
|
||||||
|
continue
|
||||||
|
if for_user and not line.sender.lower() == for_user:
|
||||||
|
continue
|
||||||
|
return line
|
||||||
|
def skip_next(self):
|
||||||
|
self._skip_next = True
|
Loading…
Reference in a new issue