示例#1
0
文件: irc.py 项目: kamaal44/Code
    def checkbans(self, channel):
        if not self.chan[channel][self.nick]['op']:
            return

        time.sleep(2)
        bans = []
        for mask in self.bans[channel]:
            mask = re.sub(r'(?i)^\${1,2}\:', '', mask)
            mask = re.sub(r'(?i)\#[A-Za-z]{1,2}$', '', mask)
            if mask != '*!*@*':
                bans.append(mask)

        re_bans = [convertmask(x) for x in bans]
        matchlist = []
        for nick in self.chan[channel]:
            ident, host = self.chan[channel][nick]['ident'], self.chan[
                channel][nick]['host']
            user = '******'.format(nick, ident, host)
            match = [
                True if re.match(mask, user) else False for mask in re_bans
            ]
            if True in match:
                matchlist.append([channel, nick])

        for channel, nick in matchlist:
            self.write(['KICK', channel, nick],
                       'Matching ban mask in %s' % channel)
            time.sleep(0.5)
示例#2
0
文件: admin.py 项目: HeyMan7/Code
def unignore(code, input):
    """ unignore <mask> - Removes <mask> from ignore list. """
    mask = matchmask(input.group(2))
    if not mask:
        return code.say('Invalid mask! For more info, see: https://github.com/Liamraystanley/Code/wiki/Masks')
    blocks = database.get(code.nick, 'ignore', [])
    if mask not in blocks:
        return code.say('%s doesn\'t exist in the ignore list!' % mask)
    del blocks[blocks.index(mask)]
    code.blocks = blocks
    code.blocks = [convertmask(x) for x in blocks]
    database.set(code.nick, blocks, 'ignore')
    return code.say('Successfully removed %s from the ignore list.' % mask)
示例#3
0
文件: admin.py 项目: HeyMan7/Code
def ignore(code, input):
    """ ignore <mask> - Makes code ignore anyone matching <mask> """
    mask = matchmask(input.group(2))
    if not mask:
        return code.say('Invalid mask! For more info, see: https://github.com/Liamraystanley/Code/wiki/Masks')
    blocks = database.get(code.nick, 'ignore', [])
    if mask not in blocks:
        blocks.append(mask)
    else:
        return code.say('%s is already in the ignorelist!' % mask)
    code.blocks = blocks
    code.re_blocks = [convertmask(x) for x in blocks]
    database.set(code.nick, blocks, 'ignore')
    return code.say('Successfully added %s to the ignore list.' % mask)
示例#4
0
def unignore(code, input):
    """ unignore <mask> - Removes <mask> from ignore list. """
    mask = matchmask(input.group(2))
    if not mask:
        return code.say(
            'Invalid mask! For more info, see: https://github.com/lrstanley/Code/wiki/Masks'
        )
    blocks = database.get(code.nick, 'ignore', [])
    if mask not in blocks:
        return code.say('%s doesn\'t exist in the ignore list!' % mask)
    del blocks[blocks.index(mask)]
    code.blocks = blocks
    code.blocks = [convertmask(x) for x in blocks]
    database.set(code.nick, blocks, 'ignore')
    return code.say('Successfully removed %s from the ignore list.' % mask)
示例#5
0
def ignore(code, input):
    """ ignore <mask> - Makes code ignore anyone matching <mask> """
    mask = matchmask(input.group(2))
    if not mask:
        return code.say(
            'Invalid mask! For more info, see: https://github.com/lrstanley/Code/wiki/Masks'
        )
    blocks = database.get(code.nick, 'ignore', [])
    if mask not in blocks:
        blocks.append(mask)
    else:
        return code.say('%s is already in the ignorelist!' % mask)
    code.blocks = blocks
    code.re_blocks = [convertmask(x) for x in blocks]
    database.set(code.nick, blocks, 'ignore')
    return code.say('Successfully added %s to the ignore list.' % mask)
示例#6
0
文件: irc.py 项目: kamaal44/Code
    def __init__(self,
                 nick,
                 name,
                 user,
                 channels,
                 server_password=None,
                 debug=False):
        asynchat.async_chat.__init__(self)
        self.set_terminator('\n')
        self.buffer = ''
        self.id = 0
        self.nick = nick
        self.default = nick
        self.name = name
        self.user = user
        self.irc_timeout = 45
        self.server_options = {}
        self.server_password = server_password
        self.channels = channels or list()
        self.stack = list()
        self.muted = False
        self.debug = debug
        self.lastping = int(time.time())
        self.chan = {}
        self.bans = {}
        self.logs = {'bot': [], 'channel': {}}
        self.special_chars = {
            'white': '\x0300',
            'black': '\x0301',
            'blue': '\x0302',
            'navy': '\x0302',
            'green': '\x0303',
            'red': '\x0304',
            'brown': '\x0305',
            'maroon': '\x0305',
            'purple': '\x0306',
            'orange': '\x0307',
            'olive': '\x0307',
            'gold': '\x0307',
            'yellow': '\x0308',
            'lightgreen': '\x0309',
            'lime': '\x0309',
            'teal': '\x0310',
            'cyan': '\x0311',
            'lightblue': '\x0312',
            'royal': '\x0312',
            'lightpurple': '\x0313',
            'pink': '\x0313',
            'fuchsia': '\x0313',
            'grey': '\x0314',
            'gray': '\x0314',
            'lightgrey': '\x0315',
            'silver': '\x0315',
            # Even more special...
            'bold': '\x02',
            'b': '\x02',
            'italic': '\x1d',
            'i': '\x1d',
            'reset': '\x0f',
            'r': '\x0f',
            'clear': '\x03',
            'c': '\x03',
            'reverse': '\x16',
            'underline': '\x1f',
            'u': '\x1f'
        }

        # Load ignorelist
        self.blocks = database.get(self.nick, 'ignore', [])
        self.re_blocks = [convertmask(x) for x in self.blocks]

        self.sending = threading.RLock()