Exemple #1
0
    def _send_mail(self, mail_text: str, session: InboundMessageSession):
        if len(mail_text) > self.MAIL_MAX_LEN:
            session.reply('{} Your message is too burdensome! '
                          'Send a concise version instead. '
                          '({}/{})'.format(gen_roar(), len(mail_text),
                                           self.MAIL_MAX_LEN))
            return

        try:
            platform_name = session.get_platform_name()

            username = '******'.format(session.message['username'],
                                         session.message['user_id'] or '',
                                         platform_name)
            self._database.put_mail(username, mail_text,
                                    session.message['channel'])
        except SenderOutboxFullError:
            session.reply('{} How embarrassing! Your outbox is full!'.format(
                gen_roar()))
        except MailbagFullError:
            session.reply(
                '{} Incredulous! My mailbag is full! Read one instead!'.format(
                    gen_roar()))
        else:
            session.reply('Tremendous! I will deliver this mail to the next '
                          'recipient without fail! {}'.format(gen_roar()))
Exemple #2
0
 def _wow_command(self, session: InboundMessageSession):
     if self._tellnext_generator:
         platform_name = session.get_platform_name()
         max_len = 500 if platform_name == 'discord' else 400
         session.say('> {}'.format(
             self._censor_text(
                 session, self._tellnext_generator.get_paragraph(max_len))),
                     multiline=True)
     else:
         session.reply('{} Feature not available!'.format(gen_roar()))
Exemple #3
0
    def _censor_text(self,
                     session: InboundMessageSession,
                     text: str,
                     extra_censor: bool = False) -> str:
        if session.get_platform_name() == 'discord':
            text = chatbot383.censor.censor_text(text).replace(
                '***', '\\*\\*\\*')
        if extra_censor:
            text = chatbot383.censor.censor_link(text)

        return text
Exemple #4
0
    def _raccattack_command(self, session: InboundMessageSession):
        text = session.match.group(1).strip() or session.message['nick']
        text = text.lstrip("!/.$`")

        extra = _random.choice([
            '', '!' * random.randint(1, 3), '?' * random.randint(1, 3),
            '.' * random.randint(2, 5)
        ])

        if _random.randint(0, 1):
            formatted_text = ' {} RaccAttack {}'.format(text, extra)
        else:
            formatted_text = 'RaccAttack {} {}'.format(extra, text)

        if session.get_platform_name() == 'discord':
            formatted_text = formatted_text.replace(
                'RaccAttack', '<:RaccAttack:273584139469324299>')

        self._try_say_or_reply_too_long(formatted_text, session)
Exemple #5
0
    def _try_say_or_reply_too_long(self, formatted_text,
                                   session: InboundMessageSession):
        platform_name = session.get_platform_name()

        if platform_name == 'twitch' and self._bot.twitch_char_limit:
            max_length = 500
            max_byte_length = 1800
        elif platform_name == 'discord':
            max_length = 2000
            max_byte_length = max_length * 4
        else:
            max_length = 400
            max_byte_length = 400

        if len(formatted_text) > max_length or self.is_too_long(
                formatted_text, max_byte_length):
            session.reply(self.TOO_LONG_TEXT_TEMPLATE.format(gen_roar()))
            return False
        else:
            session.say(formatted_text)
            return True
Exemple #6
0
    def _read_mail(self, session: InboundMessageSession):
        platform_name = session.get_platform_name()

        if _random.random() < 0.95:
            skip_username = session.message['username']
            skip_user_id = '{}@{}'.format(session.message['user_id'],
                                          platform_name)
        else:
            skip_username = None
            skip_user_id = None

        channel = None

        if session.message['channel'] in self._config.get(
                'mail_restricted_channels', ()):
            channel = session.message['channel']
            _logger.debug('Restricting mail to channel %s', channel)

        mail_info = None

        if _random.random() < 0.3:
            mail_info = self._database.get_old_mail(
                skip_username=skip_username,
                skip_user_id=skip_user_id,
                channel=channel)

        if not mail_info:
            mail_info = self._database.get_mail(skip_username=skip_username,
                                                skip_user_id=skip_user_id)

            if not mail_info and _random.random() < 0.6:
                mail_info = self._database.get_old_mail()

        if not mail_info:
            session.reply(
                '{} Outlandish! There is no new mail! You should send some!'.
                format(gen_roar()))
        else:
            # From Discord proxy, space is escaped to \s and
            # lowercase to |s via IRC rules
            username = mail_info['username'].split('!', 1)[0]\
                .replace('|s', ' ').title()
            username_extra = ''
            sender_platform = mail_info['username'].partition(
                '@')[-1] or 'twitch'

            if platform_name != sender_platform:
                username_extra = ' ({})'.format(sender_platform.title())

            session.reply(
                '{roar} I am delivering mail! '
                'Here it is, {date}, from {username}{username_extra}: {msg}'.
                format(roar=gen_roar(),
                       username=username,
                       username_extra=username_extra,
                       date=arrow.get(mail_info['timestamp']).humanize(),
                       msg=self._censor_text(
                           session,
                           mail_info['text'],
                           extra_censor=True if channel else False)),
                multiline=True,
                escape_links=True,
            )