Markup change, whitespace and typo fixes
This commit is contained in:
parent
6fae85c32a
commit
f14667cdd6
1 changed files with 25 additions and 18 deletions
|
|
@ -40,18 +40,23 @@ IRC_MAGENTA = "13"
|
||||||
IRC_DGREY = "14"
|
IRC_DGREY = "14"
|
||||||
IRC_GRAY = "15"
|
IRC_GRAY = "15"
|
||||||
|
|
||||||
# test:
|
# obsolete test:
|
||||||
# {rred {ggreen {yyellow {bblue {mmagenta {ccyan {wwhite {xdgrey
|
# {rred {ggreen {yyellow {bblue {mmagenta {ccyan {wwhite {xdgrey
|
||||||
# {Rdred {Gdgreen {Ydyellow {Bdblue {Mdmagenta {Cdcyan {Wlgrey {Xblack
|
# {Rdred {Gdgreen {Ydyellow {Bdblue {Mdmagenta {Cdcyan {Wlgrey {Xblack
|
||||||
# {[rredbg {[ggreenbg {[yyellowbg {[bbluebg {[mmagentabg {[ccyanbg {[wlgreybg {[xblackbg
|
# {[rredbg {[ggreenbg {[yyellowbg {[bbluebg {[mmagentabg {[ccyanbg {[wlgreybg {[xblackbg
|
||||||
|
|
||||||
|
# test:
|
||||||
|
# |rred |ggreen |yyellow |bblue |mmagenta |ccyan |wwhite |xdgrey
|
||||||
|
# |Rdred |Gdgreen |Ydyellow |Bdblue |Mdmagenta |Cdcyan |Wlgrey |Xblack
|
||||||
|
# |[rredbg |[ggreenbg |[yyellowbg |[bbluebg |[mmagentabg |[ccyanbg |[wlgreybg |[xblackbg
|
||||||
|
|
||||||
IRC_COLOR_MAP = dict([
|
IRC_COLOR_MAP = dict([
|
||||||
# obs - {-type colors are deprecated but still used in many places.
|
# obs - {-type colors are deprecated but still used in many places.
|
||||||
(r'{n', IRC_RESET), # reset
|
(r'{n', IRC_RESET), # reset
|
||||||
(r'{/', ""), # line break
|
(r'{/', ""), # line break
|
||||||
(r'{-', " "), # tab
|
(r'{-', " "), # tab
|
||||||
(r'{_', " "), # space
|
(r'{_', " "), # space
|
||||||
(r'{*', ""), # invert
|
(r'{*', ""), # invert
|
||||||
(r'{^', ""), # blinking text
|
(r'{^', ""), # blinking text
|
||||||
|
|
||||||
(r'{r', IRC_COLOR + IRC_RED),
|
(r'{r', IRC_COLOR + IRC_RED),
|
||||||
|
|
@ -69,7 +74,7 @@ IRC_COLOR_MAP = dict([
|
||||||
(r'{B', IRC_COLOR + IRC_DBLUE),
|
(r'{B', IRC_COLOR + IRC_DBLUE),
|
||||||
(r'{M', IRC_COLOR + IRC_DMAGENTA),
|
(r'{M', IRC_COLOR + IRC_DMAGENTA),
|
||||||
(r'{C', IRC_COLOR + IRC_DCYAN),
|
(r'{C', IRC_COLOR + IRC_DCYAN),
|
||||||
(r'{W', IRC_COLOR + IRC_GRAY), # light grey
|
(r'{W', IRC_COLOR + IRC_GRAY), # light grey
|
||||||
(r'{X', IRC_COLOR + IRC_BLACK), # pure black
|
(r'{X', IRC_COLOR + IRC_BLACK), # pure black
|
||||||
|
|
||||||
(r'{[r', IRC_COLOR + IRC_NORMAL + "," + IRC_DRED),
|
(r'{[r', IRC_COLOR + IRC_NORMAL + "," + IRC_DRED),
|
||||||
|
|
@ -79,14 +84,14 @@ IRC_COLOR_MAP = dict([
|
||||||
(r'{[m', IRC_COLOR + IRC_NORMAL + "," + IRC_DMAGENTA),
|
(r'{[m', IRC_COLOR + IRC_NORMAL + "," + IRC_DMAGENTA),
|
||||||
(r'{[c', IRC_COLOR + IRC_NORMAL + "," + IRC_DCYAN),
|
(r'{[c', IRC_COLOR + IRC_NORMAL + "," + IRC_DCYAN),
|
||||||
(r'{[w', IRC_COLOR + IRC_NORMAL + "," + IRC_GRAY), # light grey background
|
(r'{[w', IRC_COLOR + IRC_NORMAL + "," + IRC_GRAY), # light grey background
|
||||||
(r'{[x', IRC_COLOR + IRC_NORMAL + "," + IRC_BLACK), # pure black background
|
(r'{[x', IRC_COLOR + IRC_NORMAL + "," + IRC_BLACK), # pure black background
|
||||||
|
|
||||||
# |-type formatting is the thing to use.
|
# |-type formatting is the thing to use.
|
||||||
(r'|n', IRC_RESET), # reset
|
(r'|n', IRC_RESET), # reset
|
||||||
(r'|/', ""), # line break
|
(r'|/', ""), # line break
|
||||||
(r'|-', " "), # tab
|
(r'|-', " "), # tab
|
||||||
(r'|_', " "), # space
|
(r'|_', " "), # space
|
||||||
(r'|*', ""), # invert
|
(r'|*', ""), # invert
|
||||||
(r'|^', ""), # blinking text
|
(r'|^', ""), # blinking text
|
||||||
|
|
||||||
(r'|r', IRC_COLOR + IRC_RED),
|
(r'|r', IRC_COLOR + IRC_RED),
|
||||||
|
|
@ -104,7 +109,7 @@ IRC_COLOR_MAP = dict([
|
||||||
(r'|B', IRC_COLOR + IRC_DBLUE),
|
(r'|B', IRC_COLOR + IRC_DBLUE),
|
||||||
(r'|M', IRC_COLOR + IRC_DMAGENTA),
|
(r'|M', IRC_COLOR + IRC_DMAGENTA),
|
||||||
(r'|C', IRC_COLOR + IRC_DCYAN),
|
(r'|C', IRC_COLOR + IRC_DCYAN),
|
||||||
(r'|W', IRC_COLOR + IRC_GRAY), # light grey
|
(r'|W', IRC_COLOR + IRC_GRAY), # light grey
|
||||||
(r'|X', IRC_COLOR + IRC_BLACK), # pure black
|
(r'|X', IRC_COLOR + IRC_BLACK), # pure black
|
||||||
|
|
||||||
(r'|[r', IRC_COLOR + IRC_NORMAL + "," + IRC_DRED),
|
(r'|[r', IRC_COLOR + IRC_NORMAL + "," + IRC_DRED),
|
||||||
|
|
@ -114,12 +119,13 @@ IRC_COLOR_MAP = dict([
|
||||||
(r'|[m', IRC_COLOR + IRC_NORMAL + "," + IRC_DMAGENTA),
|
(r'|[m', IRC_COLOR + IRC_NORMAL + "," + IRC_DMAGENTA),
|
||||||
(r'|[c', IRC_COLOR + IRC_NORMAL + "," + IRC_DCYAN),
|
(r'|[c', IRC_COLOR + IRC_NORMAL + "," + IRC_DCYAN),
|
||||||
(r'|[w', IRC_COLOR + IRC_NORMAL + "," + IRC_GRAY), # light grey background
|
(r'|[w', IRC_COLOR + IRC_NORMAL + "," + IRC_GRAY), # light grey background
|
||||||
(r'|[x', IRC_COLOR + IRC_NORMAL + "," + IRC_BLACK) # pure black background
|
(r'|[x', IRC_COLOR + IRC_NORMAL + "," + IRC_BLACK) # pure black background
|
||||||
])
|
])
|
||||||
RE_IRC_COLOR = re.compile(r"|".join([re.escape(key) for key in viewkeys(IRC_COLOR_MAP)]), re.DOTALL)
|
RE_IRC_COLOR = re.compile(r"|".join([re.escape(key) for key in viewkeys(IRC_COLOR_MAP)]), re.DOTALL)
|
||||||
RE_MXP = re.compile(r'\{lc(.*?)\{lt(.*?)\{le', re.DOTALL)
|
RE_MXP = re.compile(r'\|lc(.*?)\|lt(.*?)\|le', re.DOTALL)
|
||||||
RE_ANSI_ESCAPES = re.compile(r"(%s)" % "|".join(("{{", "%%", "\\\\")), re.DOTALL)
|
RE_ANSI_ESCAPES = re.compile(r"(%s)" % "|".join(("{{", "%%", "\\\\")), re.DOTALL)
|
||||||
|
|
||||||
|
|
||||||
def sub_irc(ircmatch):
|
def sub_irc(ircmatch):
|
||||||
"""
|
"""
|
||||||
Substitute irc color info. Used by re.sub.
|
Substitute irc color info. Used by re.sub.
|
||||||
|
|
@ -133,6 +139,7 @@ def sub_irc(ircmatch):
|
||||||
"""
|
"""
|
||||||
return IRC_COLOR_MAP.get(ircmatch.group(), "")
|
return IRC_COLOR_MAP.get(ircmatch.group(), "")
|
||||||
|
|
||||||
|
|
||||||
def parse_irc_colors(string):
|
def parse_irc_colors(string):
|
||||||
"""
|
"""
|
||||||
Parse {-type syntax and replace with IRC color markers
|
Parse {-type syntax and replace with IRC color markers
|
||||||
|
|
@ -156,9 +163,10 @@ def parse_irc_colors(string):
|
||||||
|
|
||||||
# IRC bot
|
# IRC bot
|
||||||
|
|
||||||
|
|
||||||
class IRCBot(irc.IRCClient, Session):
|
class IRCBot(irc.IRCClient, Session):
|
||||||
"""
|
"""
|
||||||
An IRC bot that tracks actitivity in a channel as well
|
An IRC bot that tracks activity in a channel as well
|
||||||
as sends text to it when prompted
|
as sends text to it when prompted
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
@ -246,14 +254,14 @@ class IRCBot(irc.IRCClient, Session):
|
||||||
self.sendLine("NAMES %s" % self.channel)
|
self.sendLine("NAMES %s" % self.channel)
|
||||||
|
|
||||||
def irc_RPL_NAMREPLY(self, prefix, params):
|
def irc_RPL_NAMREPLY(self, prefix, params):
|
||||||
"Handles IRC NAME request returns (nicklist)"
|
""""Handles IRC NAME request returns (nicklist)"""
|
||||||
channel = params[2].lower()
|
channel = params[2].lower()
|
||||||
if channel != self.channel.lower():
|
if channel != self.channel.lower():
|
||||||
return
|
return
|
||||||
self.nicklist += params[3].split(' ')
|
self.nicklist += params[3].split(' ')
|
||||||
|
|
||||||
def irc_RPL_ENDOFNAMES(self, prefix, params):
|
def irc_RPL_ENDOFNAMES(self, prefix, params):
|
||||||
"Called when the nicklist has finished being returned."
|
"""Called when the nicklist has finished being returned."""
|
||||||
channel = params[1].lower()
|
channel = params[1].lower()
|
||||||
if channel != self.channel.lower():
|
if channel != self.channel.lower():
|
||||||
return
|
return
|
||||||
|
|
@ -271,7 +279,6 @@ class IRCBot(irc.IRCClient, Session):
|
||||||
"""
|
"""
|
||||||
self.data_in(text="", type="ping", user="server", channel=self.channel, timing=time)
|
self.data_in(text="", type="ping", user="server", channel=self.channel, timing=time)
|
||||||
|
|
||||||
|
|
||||||
def data_in(self, text=None, **kwargs):
|
def data_in(self, text=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Data IRC -> Server.
|
Data IRC -> Server.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue