Example #1
0
    def ascii_decode(self, event, text, base_to):
        "Display the values of each character in an ASCII string"

        base_to = self._parse_base(base_to)

        if len(text) > 2 and text[0] == text[-1] and text[0] in ("'", '"'):
            text = text[1:-1]

        output = u""
        for char in text:
            code_point = ord(char)
            if code_point > 255:
                output += u'U%s ' % self._in_base(code_point, base_to)
            else:
                output += self._in_base(code_point, base_to) + u" "

        output = output.strip()

        event.addresponse(u'That is %(result)s in %(base)s', {
            'result': output,
            'base': self._base_name(base_to),
        })

        if base_to == 64 and any(
                True for plugin in ibid.processors
                if 'base64' in getattr(plugin, 'features', [])):
            event.addresponse(
                u'If you want a base64 encoding, use the "base64" feature')
Example #2
0
    def ascii_decode(self, event, text, base_to):
        "Display the values of each character in an ASCII string"

        base_to = self._parse_base(base_to)

        if len(text) > 2 and text[0] == text[-1] and text[0] in ("'", '"'):
            text = text[1:-1]

        output = u""
        for char in text:
            code_point = ord(char)
            if code_point > 255:
                output += u'U%s ' % self._in_base(code_point, base_to)
            else:
                output += self._in_base(code_point, base_to) + u" "

        output = output.strip()

        event.addresponse(u'That is %(result)s in %(base)s', {
            'result': output,
            'base': self._base_name(base_to),
        })

        if base_to == 64 and any(True for plugin in ibid.processors
                if 'base64' in getattr(plugin, 'features', [])):
            event.addresponse(u'If you want a base64 encoding, use the "base64" feature')
Example #3
0
    def summon(self, event, who, source):
        if not source:
            source = self.default_source

        if source.lower() not in ibid.sources:
            event.addresponse(u"I'm afraid that I'm not connected to %s",
                              source)
            return

        account = event.session.query(Account) \
            .options(eagerload('identities')) \
            .join('identities') \
            .filter(
                or_(
                    and_(
                        Identity.identity == who,
                        Identity.source == event.source,
                    ),
                    Account.username == who,
                )) \
            .first()

        if account:
            for other_identity in [
                    id for id in account.identities
                    if id.source.lower() == source.lower()
            ]:
                if any(True for channel in ibid.channels[
                        other_identity.source].itervalues()
                       if other_identity.id in channel):
                    event.addresponse(
                        u'Your presence has been requested by '
                        u'%(who)s in %(channel)s on %(source)s.', {
                            'who': event.sender['nick'],
                            'channel':
                            (not event.public) and u'private' or event.channel,
                            'source': event.source,
                        },
                        target=other_identity.identity,
                        source=other_identity.source,
                        address=False)
                    event.addresponse(True)
                else:
                    event.addresponse(
                        u"Sorry %s doesn't appear to be available right now.",
                        who)
                return

        event.addresponse(
            u"Sorry, I don't know how to find %(who)s on %(source)s. "
            u'%(who)s must first link an identity on %(source)s.', {
                'who': who,
                'source': source,
            })
        return
Example #4
0
    def resolve_currency(self, name, rough=True, plural_recursion=False):
        "Return the canonical name for a currency"

        if not self.currencies:
            self._load_currencies()

        if name.upper() in self.currencies:
            return name.upper()

        # Strip leading dots (.TLD)
        m = re.match(r'^[\.\s]*(.+)$', name, re.UNICODE)
        if m is None:
            return False
        name = m.group(1).lower()

        # TLD:
        if rough and len(
                name) == 2 and name.upper() in self.country_currencies:
            return self.country_currencies[name.upper()]

        # Currency Name
        if name == u'dollar':
            return "USD"
        if name == u'pound':
            return "GBP"
        for code, (places, currency, units) in self.currencies.iteritems():
            if name == currency.lower():
                return code
            if name.title() in places:
                return code

        # There are also country names in country_codes:
        for code, place in self.country_codes.iteritems():
            if name == place.lower() and code in self.country_currencies:
                return self.country_currencies[code]

        # Second pass, not requiring exact match:
        if rough:
            for code, (places, currency, units) in self.currencies.iteritems():
                if name in currency.lower():
                    return code
                if any(name in place.lower() for place in places):
                    return code

            for code, place in self.country_codes.iteritems():
                if name in place.lower() and code in self.country_currencies:
                    return self.country_currencies[code]

        # Maybe it's a plural?
        if name.endswith('s') and not plural_recursion:
            return self.resolve_currency(name[:-1], rough, True)
        return False
Example #5
0
    def summon(self, event, who, source):
        if not source:
            source = self.default_source

        if source.lower() not in ibid.sources:
            event.addresponse(u"I'm afraid that I'm not connected to %s",
                              source)
            return

        account = event.session.query(Account) \
            .options(eagerload('identities')) \
            .join('identities') \
            .filter(
                or_(
                    and_(
                        Identity.identity == who,
                        Identity.source == event.source,
                    ),
                    Account.username == who,
                )) \
            .first()

        if account:
            for other_identity in [id for id
                    in account.identities
                    if id.source.lower() == source.lower()]:
                if any(True for channel
                        in ibid.channels[other_identity.source].itervalues()
                        if other_identity.id in channel):
                    event.addresponse(u'Your presence has been requested by '
                                      u'%(who)s in %(channel)s on %(source)s.',
                        {
                            'who': event.sender['nick'],
                            'channel': (not event.public)
                                    and u'private' or event.channel,
                            'source': event.source,
                        }, target=other_identity.identity,
                        source=other_identity.source, address=False)
                    event.addresponse(True)
                else:
                    event.addresponse(
                        u"Sorry %s doesn't appear to be available right now.",
                        who)
                return

        event.addresponse(
                u"Sorry, I don't know how to find %(who)s on %(source)s. "
                u'%(who)s must first link an identity on %(source)s.', {
                    'who': who,
                    'source': source,
        })
        return
Example #6
0
    def resolve_currency(self, name, rough=True, plural_recursion=False):
        "Return the canonical name for a currency"

        if not self.currencies:
            self._load_currencies()

        if name.upper() in self.currencies:
            return name.upper()

        # Strip leading dots (.TLD)
        m = re.match(r'^[\.\s]*(.+)$', name, re.UNICODE)
        if m is None:
            return False
        name = m.group(1).lower()

        # TLD:
        if rough and len(name) == 2 and name.upper() in self.country_currencies:
            return self.country_currencies[name.upper()]

        # Currency Name
        if name == u'dollar':
            return "USD"
        if name == u'pound':
            return "GBP"
        for code, (places, currency, units) in self.currencies.iteritems():
            if name == currency.lower():
                return code
            if name.title() in places:
                return code

        # There are also country names in country_codes:
        for code, place in self.country_codes.iteritems():
            if name == place.lower() and code in self.country_currencies:
                return self.country_currencies[code]

        # Second pass, not requiring exact match:
        if rough:
            for code, (places, currency, units) in self.currencies.iteritems():
                if name in currency.lower():
                    return code
                if any(name in place.lower() for place in places):
                    return code

            for code, place in self.country_codes.iteritems():
                if name in place.lower() and code in self.country_currencies:
                    return self.country_currencies[code]

        # Maybe it's a plural?
        if name.endswith('s') and not plural_recursion:
            return self.resolve_currency(name[:-1], rough, True)
        return False
Example #7
0
    def summon(self, event, who, source):
        if not source:
            source = self.default_source

        if source.lower() not in ibid.sources:
            event.addresponse(u"I'm afraid that I'm not connected to %s", source)
            return

        account = (
            event.session.query(Account)
            .options(eagerload("identities"))
            .join("identities")
            .filter(or_(and_(Identity.identity == who, Identity.source == event.source), Account.username == who))
            .first()
        )

        if account:
            for other_identity in [id for id in account.identities if id.source.lower() == source.lower()]:
                if any(
                    True
                    for channel in ibid.channels[other_identity.source].itervalues()
                    if other_identity.id in channel
                ):
                    event.addresponse(
                        u"Your presence has been requested by " u"%(who)s in %(channel)s on %(source)s.",
                        {
                            "who": event.sender["nick"],
                            "channel": (not event.public) and u"private" or event.channel,
                            "source": event.source,
                        },
                        target=other_identity.identity,
                        source=other_identity.source,
                        address=False,
                    )
                    event.addresponse(True)
                else:
                    event.addresponse(u"Sorry %s doesn't appear to be available right now.", who)
                return

        event.addresponse(
            u"Sorry, I don't know how to find %(who)s on %(source)s. "
            u"%(who)s must first link an identity on %(source)s.",
            {"who": who, "source": source},
        )
        return
Example #8
0
                    if (len(buf) == 2 and base_from == 16) or (
                            len(buf) == 3
                            and base_from == 8) or (len(buf) == 8
                                                    and base_from == 2):
                        output += process_buf(buf)
                        buf = u""

            if len(buf) > 0:
                output += process_buf(buf)
        except ValueError, e:
            event.addresponse(unicode(e))
            return

        event.addresponse(u'That is "%s"', output)
        if base_from == 64 and any(
                True for plugin in ibid.processors
                if 'base64' in getattr(plugin, 'features', [])):
            event.addresponse(
                u'If you want a base64 encoding, use the "base64" feature')


features['units'] = {
    'description': 'Converts values between various units.',
    'categories': ('convert', ),
}


class Units(Processor):
    usage = u'convert [<value>] <unit> to <unit>'
    features = ('units', )
    priority = 10
Example #9
0
 def match_operators(self, roperators, adjust):
     return any(re.match(r, adjust) for r in roperators)
Example #10
0
                        output += process_buf(buf)
                        buf = u""
                else:
                    buf += char
                    if (len(buf) == 2 and base_from == 16) or (len(buf) == 3 and base_from == 8) or (len(buf) == 8 and base_from == 2):
                        output += process_buf(buf)
                        buf = u""

            if len(buf) > 0:
                output += process_buf(buf)
        except ValueError, e:
            event.addresponse(unicode(e))
            return

        event.addresponse(u'That is "%s"', output)
        if base_from == 64 and any(True for plugin in ibid.processors
                if 'base64' in getattr(plugin, 'features', [])):
            event.addresponse(u'If you want a base64 encoding, use the "base64" feature')

features['units'] = {
    'description': 'Converts values between various units.',
    'categories': ('convert',),
}
class Units(Processor):
    usage = u'convert [<value>] <unit> to <unit>'
    features = ('units',)
    priority = 10

    units = Option('units', 'Path to units executable', 'units')

    temp_scale_names = {
        'fahrenheit': 'tempF',
Example #11
0
File: memo.py Project: shoosen/ibid
    def tell(self, event, how, who, memo):
        m = re.match(r'^on\s+(\S+?)\s+(.+)$', memo, re.I | re.U)
        source_specified = bool(m) and m.group(1).lower() in ibid.sources
        if source_specified:
            source = m.group(1).lower()
            memo = m.group(2)
        else:
            source = event.source

        if source.lower() == event.source and \
                any(True for name in ibid.config.plugins['core']['names']
                    if name.lower() == who.lower()):
            event.addresponse(u"I can't deliver messages to myself")
            return

        to = event.session.query(Identity) \
                  .filter_by(identity=who, source=source).first()

        if not to and not source_specified:
            account = event.session.query(Account) \
                    .filter_by(username=who).first()
            if account:
                for identity in account.identities:
                    if identity.source == source:
                        to = identity
                if not identity:
                    identity = account.identities[0]

        if not to and not source_specified:
            event.addresponse(
                    u"I don't know who %(who)s is. "
                    u"Say '%(who)s on %(source)s' and I'll take your word "
                    u'that %(who)s exists', {
                    'who': who,
                    'source': source,
            })
            return

        if not to:
            if source not in ibid.sources:
                event.addresponse(u'I am not connected to %s', source)
                return
            to = Identity(source, who)
            event.session.save(to)
            event.session.commit()

            log.info(u"Created identity %s for %s on %s", to.id, to.identity,
                     to.source)

        if permission(u'recvmemo', to.account and to.account.id or None,
                      to.source, event.session) != 'yes':
            event.addresponse(u'Just tell %s yourself', who)
            return

        memo = u' '.join((how, who, memo))

        memo = Memo(event.identity, to.id, memo,
                    how.lower() in (u'pm', u'privmsg', u'msg'))
        event.session.save_or_update(memo)

        event.session.commit()
        log.info(u"Stored memo %s for %s (%s) from %s (%s): %s",
                memo.id, to.id, who, event.identity, event.sender['connection'],
                memo.memo)
        event.memo = memo.id
        nomemos_cache.clear()
        notified_overlimit_cache.discard(to.id)

        event.addresponse(u"%(acknowledgement)s, I'll %(action)s "
                          u"%(recipient)s on %(source)s", {
            'acknowledgement': choice(('Okay', 'Righto', 'Sure', 'Got it')),
            'action': how.lower(),
            'recipient': to.identity,
            'source': to.source,
        })
Example #12
0
    def tell(self, event, how, who, memo):
        m = re.match(r'^on\s+(\S+?)\s+(.+)$', memo, re.I | re.U)
        source_specified = bool(m) and m.group(1).lower() in ibid.sources
        if source_specified:
            source = m.group(1).lower()
            memo = m.group(2)
        else:
            source = event.source

        if source.lower() == event.source and \
                any(True for name in ibid.config.plugins['core']['names']
                    if name.lower() == who.lower()):
            event.addresponse(u"I can't deliver messages to myself")
            return

        to = event.session.query(Identity) \
                  .filter_by(identity=who, source=source).first()

        if not to and not source_specified:
            account = event.session.query(Account) \
                    .filter_by(username=who).first()
            if account:
                for identity in account.identities:
                    if identity.source == source:
                        to = identity
                if not identity:
                    identity = account.identities[0]

        if not to and not source_specified:
            event.addresponse(
                    u"I don't know who %(who)s is. "
                    u"Say '%(who)s on %(source)s' and I'll take your word "
                    u'that %(who)s exists', {
                    'who': who,
                    'source': source,
            })
            return

        if not to:
            if source not in ibid.sources:
                event.addresponse(u'I am not connected to %s', source)
                return
            to = Identity(source, who)
            event.session.add(to)
            event.session.commit()

            log.info(u"Created identity %s for %s on %s", to.id, to.identity,
                     to.source)

        if permission(u'recvmemo', to.account and to.account.id or None,
                      to.source, event.session) != 'yes':
            event.addresponse(u'Just tell %s yourself', who)
            return

        memo = u' '.join((how, who, memo))

        memo = Memo(event.identity, to.id, memo,
                    how.lower() in (u'pm', u'privmsg', u'msg'))
        event.session.add(memo)

        event.session.commit()
        log.info(u"Stored memo %s for %s (%s) from %s (%s): %s",
                memo.id, to.id, who, event.identity, event.sender['connection'],
                memo.memo)
        event.memo = memo.id
        nomemos_cache.clear()
        notified_overlimit_cache.discard(to.id)

        event.addresponse(u"%(acknowledgement)s, I'll %(action)s "
                          u"%(recipient)s on %(source)s", {
            'acknowledgement': choice(('Okay', 'Righto', 'Sure', 'Got it')),
            'action': how.lower(),
            'recipient': to.identity,
            'source': to.source,
        })
Example #13
0
File: karma.py Project: vhata/ibid
 def match_operators(self, roperators, adjust):
     return any(re.match(r, adjust) for r in roperators)