Esempio n. 1
0
    def _handle_bits(message, amount):
        regexp = re.search(BITS_REGEXP.format(amount), message['text'])
        emote = regexp.group(2)
        emote_smile = '{}{}'.format(emote, amount)

        if amount >= 10000:
            color = 'red'
        elif amount >= 5000:
            color = 'blue'
        elif amount >= 1000:
            color = 'green'
        elif amount >= 100:
            color = 'purple'
        else:
            color = 'gray'

        message['bits'] = {
            'bits': emote_smile,
            'amount': amount,
            'theme': BITS_THEME,
            'type': BITS_TYPE,
            'color': color,
            'size': 4
        }
        message['text'] = message['text'].replace(
            emote_smile, EMOTE_FORMAT.format(emote_smile))
Esempio n. 2
0
    def _process_message(self, message):
        try:
            self.duplicates.index(message['id'])
        except ValueError:
            comp = {'source': self.source,
                    'source_icon': SOURCE_ICON,
                    'user': message['from']['name'],
                    'text': message['text'],
                    'emotes': [],
                    'type': 'message'}
            if message['to'] is not None:
                comp['to'] = message['to']['name']
                if comp['to'] == self.channel_name:
                    if self.chat_module.conf_params()['config']['config'].get('show_pm'):
                        comp['pm'] = True
            else:
                comp['to'] = None

            smiles_array = re.findall(SMILE_REGEXP, comp['text'])
            for smile in smiles_array:
                for smile_find in self.smiles:
                    if smile_find['code'] == smile.lower():
                        if self.allow_smile(smile_find, message['store']['subscriptions']):
                            comp['text'] = comp['text'].replace(SMILE_FORMAT.format(smile),
                                                                EMOTE_FORMAT.format(smile))
                            comp['emotes'].append({'emote_id': smile, 'emote_url': smile_find['url']})

            self.duplicates.append(message['id'])
            if len(self.duplicates) > self.bufferForDup:
                self.duplicates.pop(0)
            self._send_message(comp)
Esempio n. 3
0
 def _post_process_emotes(self, message):
     for word in message.text.split():
         if word in self.smiles:
             message.text = re.sub(
                 SMILE_REGEXP.format(re.escape(word)),
                 r'\1{}\3'.format(EMOTE_FORMAT.format(word)), message.text)
             message.emotes.append(
                 Emote(word, CDN_URL.format(self.smiles[word])))
Esempio n. 4
0
 def process_smiles(self, smiles):
     smiles_array = re.findall(SMILE_REGEXP, self._text)
     for smile in smiles_array:
         for smile_find in smiles:
             if smile_find['code'] == smile.lower():
                 if allow_smile(smile_find, self._subscriptions):
                     self._text = self._text.replace(SMILE_FORMAT.format(smile),
                                                     EMOTE_FORMAT.format(smile))
                     self._emotes.append(Emote(smile, smile_find['url']))
Esempio n. 5
0
    def _process_smiles(self, comp, msg):
        smiles_array = re.findall(SMILE_REGEXP, comp['text'])
        for smile in smiles_array:
            if smile in self.smiles:
                smile_info = self.smiles.get(smile)
                allow = False
                gif = False
                if msg['data']['user_rights'] >= 40:
                    allow = True
                elif msg['data']['user_rights'] >= 20 \
                        and (smile_info['channel_id'] == '0' or smile_info['channel_id'] == '10603'):
                    allow = True
                elif smile_info['channel_id'] == '0' or smile_info[
                        'channel_id'] == '10603':
                    if not smile_info['is_premium']:
                        if smile_info['donate_lvl'] == 0:
                            allow = True
                        elif smile_info['donate_lvl'] <= int(
                                msg['data']['payments']):
                            allow = True
                    else:
                        if msg['data']['premium']:
                            allow = True

                for premium in msg['data']['premiums']:
                    if smile_info['channel_id'] == str(premium):
                        if smile_info['is_premium']:
                            allow = True
                            gif = True

                if allow:
                    comp['text'] = comp['text'].replace(
                        SMILE_FORMAT.format(smile), EMOTE_FORMAT.format(smile))
                    if smile not in comp['emotes']:
                        if gif and smile_info['urls']['gif']:
                            comp['emotes'][smile] = {
                                'emote_url': smile_info['urls']['gif']
                            }
                        else:
                            comp['emotes'][smile] = {
                                'emote_url': smile_info['urls']['big']
                            }
        emotes_list = []
        for emote, data in comp['emotes'].iteritems():
            emotes_list.append({
                'emote_id': emote,
                'emote_url': data['emote_url']
            })
        comp['emotes'] = emotes_list
Esempio n. 6
0
    def process_smiles(self, smiles, rights, premium, prems, payments):
        emotes = {}
        smiles_array = re.findall(SMILE_REGEXP, self._text)
        for smile in smiles_array:
            if smile in smiles:
                smile_info = smiles.get(smile)
                allow = False
                gif = False
                if rights >= 40:
                    allow = True
                elif rights >= 20 \
                        and (smile_info['channel_id'] == '0' or smile_info['channel_id'] == '10603'):
                    allow = True
                elif smile_info['channel_id'] == '0' or smile_info[
                        'channel_id'] == '10603':
                    if not smile_info['is_premium']:
                        if smile_info['donate_lvl'] == 0:
                            allow = True
                        elif smile_info['donate_lvl'] <= int(payments):
                            allow = True
                    else:
                        if premium:
                            allow = True

                for premium_item in prems:
                    if smile_info['channel_id'] == str(premium_item):
                        if smile_info['is_premium']:
                            allow = True
                            gif = True

                if allow:
                    self.text = self.text.replace(SMILE_FORMAT.format(smile),
                                                  EMOTE_FORMAT.format(smile))
                    if smile not in emotes:
                        if gif and smile_info['urls']['gif']:
                            emotes[smile] = {
                                'emote_url': smile_info['urls']['gif']
                            }
                        else:
                            emotes[smile] = {
                                'emote_url': smile_info['urls']['big']
                            }
        self._emotes = [
            Emote(emote, data['emote_url']) for emote, data in emotes.items()
        ]
Esempio n. 7
0
    def _post_process_emotes(message):
        conveyor_emotes = []
        for emote in message['emotes']:
            for position in emote['positions']:
                start, end = position.split('-')
                conveyor_emotes.append({
                    'emote_id': emote['emote_id'],
                    'start': int(start),
                    'end': int(end)
                })
        conveyor_emotes = sorted(conveyor_emotes,
                                 key=lambda k: k['start'],
                                 reverse=True)

        for emote in conveyor_emotes:
            message['text'] = u'{start}{emote}{end}'.format(
                start=message['text'][:emote['start']],
                end=message['text'][emote['end'] + 1:],
                emote=EMOTE_FORMAT.format(emote['emote_id']))
Esempio n. 8
0
 def _post_process_bttv_emotes(message):
     for emote, data in message['bttv_emotes'].iteritems():
         message['text'] = message['text'].replace(
             emote, EMOTE_FORMAT.format(emote))
         message['emotes'].append(data)
Esempio n. 9
0
 def _post_process_bttv_emotes(message):
     for emote, data in message.bttv_emotes.iteritems():
         message.text = message.text.replace(emote,
                                             EMOTE_FORMAT.format(emote))
         message.emotes.append(data)
Esempio n. 10
0
def process_emotes(emotes):
    return [{
        'id': EMOTE_FORMAT.format(emote.id),
        'url': emote.url
    } for emote in emotes]