示例#1
0
def file_name_to_valid_string(file_name):
    """
        Demoji the file name if it's contain emoji
    """
    if emoji.emoji_count(file_name):  # type: ignore
        return emoji.demojize(file_name)  # type: ignore
    return file_name
示例#2
0
def check_message_content(message_content):
    """Check for correct content to add.

    This check is need to exclude any unreleated messages, such as
    commands for bots, messages with emojis, @everyone/@here mentions
    and links. They can possibly break up something, so it's better to prevent
    them from passing through

    Args:
        message_content (str): Extracted content from message

    Returns:
        bool: State of check
    """
    check = True
    for word in PREFIXES:
        if message_content.startswith(word):
            check = False
            break
    for word in BAN_WORDS:
        if message_content.find(word) >= 0:
            check = False
            break
    if emoji.emoji_count(message_content) > 0:
        check = False
    if "@everyone" in message_content or "@here" in message_content:
        check = False
    if re.findall(REGEX_RULE, message_content):
        check = False
    if not check:
        markov_delay_handler("update")
    return check
def export_all_lines_csv(input_txt_file, export_filename):

    file = import_file(input_txt_file)
    results = []
    for line in file:
        full_message = extract_message(line)
        emoji_count = e.emoji_count(full_message)
        emojiless_message = strip_emoji(full_message)
        if len(emojiless_message) > 0:
            word_count = len(emojiless_message.split())
        else:
            word_count = 0
        results.append(
            build_line(extract_date(line), extract_hour(line),
                       extract_name(line), full_message, word_count,
                       emoji_count, 1))
    fields_to_write_to_csv = [
        "date", "hour", "name", "message", "word_count", "emoji_count",
        "message_count"
    ]
    with open(export_filename, mode='w') as csv_file:
        writer = csv.DictWriter(csv_file, fieldnames=fields_to_write_to_csv)

        writer.writeheader()
        for line in results:
            writer.writerow(line)
def test_emoji_handling_in_file_name():
    file_names_package = ['Fwd for you 😍', 'Hi all', '', '🐝🤣🇮🇱👨🏽‍🚀🧟‍♂🧞‍♂🧚🏼‍♀', '🧔🤸🏻‍♀🥩🧚😷🍙👻']

    for file_name in file_names_package:
        demojized_file_name = file_name_to_valid_string(file_name)
        assert demojized_file_name == emoji.demojize(file_name)
        assert not emoji.emoji_count(file_name_to_valid_string(demojized_file_name))
示例#5
0
async def _set_pref(message):
    """Sets a user's preference for their reaction emoji.

    Takes the emoji within a message and sets that to be the user's preferred 
    emoji for reactions.

    Args:
        message: A discord.Message object with contents of 
            format "!Autoreact.set {emoji}".

    Returns:
        None
    """

    emoji = message.content[15:16]
    if em.emoji_count(emoji) == 1:
        await _set_emoji(message.author, emoji)
        bot_logger.debug(
            (f"Set {message.author}'s ({message.author.id}) emoji "
             f'preference as {emoji}.'))
    elif not (await _needs_cooldown(message.author.id, 30)):
        await message.author.send(f'"{emoji}" is not an emoji!')
        last_message[message.author.id] = dt.datetime.now()
        bot_logger.debug((f"{message.author} sent invalid emoji '{emoji}' "
                          "in attempting to set their emoji. No emoji set."))
示例#6
0
def strip_emoji(text):

    print(emoji.emoji_count(text))

    new_text = re.sub(emoji.get_emoji_regexp(), r"", text)

    return new_text
示例#7
0
 def filter(self, message):
     if not message.text:
         return False
     if not check_ban_state(message.chat_id, BanMessageType.EMOJI):
         return False
     if emoji_count(message.text):
         return True
     return False
示例#8
0
def strIsUnicodeEmoji(c: str) -> bool:
    """Decide whether a given string contrains a single unicode emoji.

    :param str c: The string to test
    :return: True if c contains exactly one character, and that character is a unicode emoji. False otherwise.
    :rtype: bool
    """
    return len(c) <= MAX_EMOJI_LEN and (emoji.emoji_count(c) == 1
                                        or c.rstrip(VAR_SELECTOR)
                                        in REGIONAL_INDICATORS)
示例#9
0
def smiles(text):

    emoji_len = 0
    full_len = 0
    for elem in text:
        if elem['in'] == True:
            emoji_len += int(emoji.emoji_count(elem['text']))
            full_len += float(len(elem['text'].split()))

    return (emoji_len / full_len) * 623.0
示例#10
0
def ungroup_emoji(toks: Collection):
    "Ungroup emojis"
    res = []
    for tok in toks:
        if emoji.emoji_count(tok) == len(tok):
            for char in tok:
                res.append(char)
        else:
            res.append(tok)
    return res
示例#11
0
 def __init__(self, message, settings) -> None:
     """
     Main constructor of CheckMessage class.
     :param message: Message to check.
     :param settings: Object of Settings class.
     """
     self.__message = message
     self.__settings = settings
     self.__emojicnt = emoji.emoji_count(self.__message.text)
     self.__scorers = self.__find_methods('check')
示例#12
0
def handlePhoto(update, context, isGroup):
    """Handle a photo sent in by user"""
    message = update.message
    user = update.effective_user
    usableCaption = message.caption or ''
    if len(usableCaption):
        usableCaption = usableCaption.strip()
    if (isGroup):
        if not usableCaption or not len(
                usableCaption) >= 8 or not usableCaption[:8] == '/sticker':
            return
        usableCaption = message.caption[8:].strip()
        setName = 'set_' + str(update.effective_chat.id).replace('-', 'm')
        setTitle = update.effective_chat.title + ' pack'
        setOwnerId = HARCODED_USER_ID_TODO_REPLACE
        member = context.bot.getChatMember(update.effective_chat.id,
                                           setOwnerId)
        if member.status not in ["member", "creator", "administrator"]:
            return
    else:
        setName = 'set_' + str(user.id).replace('-', 'm')
        setTitle = user.first_name + ' pack'
        setOwnerId = user.id

    if len(usableCaption) > 50:
        return update.message.reply_text('caption too long (max 50)')
    if message.photo and len(message.photo):
        # get full size photo
        filePath = getImageFromImageMessage(update, context)
        imgPath = resize.resize(filePath)
        stickerEmoji = DEFAULT_EMOJI
        if usableCaption and emoji.emoji_count(usableCaption[0]) == 1:

            stickerEmoji = usableCaption[0]
            usableCaption = usableCaption[1:].strip()
        #add caption
        if usableCaption:
            drawOnBottom = len(usableCaption) > 1 and usableCaption[0] == '-'
            if (drawOnBottom):
                usableCaption = usableCaption[1:].strip()
            imgPath = drawText.draw(imgPath, usableCaption, drawOnBottom)

        sticker = stickerModule.createSticker(context.bot, setOwnerId, imgPath,
                                              setName, setTitle, stickerEmoji)
        if sticker:
            update.message.reply_sticker(sticker.file_id)
        else:
            update.message.reply_text('error creating sticker')
        #remove tmp files
        os.remove(filePath)
        os.remove(filePath.split('.')[0] + '_r.png')

    else:
        update.message.reply_text('error')
def file_name_to_valid_string(file_name):
    try:
        # In case the user uses Demisto version < 5.0 and the new docker image will not be automatically changed
        import emoji

        if emoji.emoji_count(file_name):  # type: ignore
            return emoji.demojize(file_name)  # type: ignore
    except Exception:
        pass

    return file_name
示例#14
0
def has_x_or_more_emojis(bot: discord.Client, guild: discord.Guild, text: str,
                         limit: int):
    n = emoji.emoji_count(text)

    if n >= limit:
        return True

    if "<" in text:  # No need to run a regex if no custom emoji can be present
        n += len(list(re.finditer(EMOJI_RE, text)))

    return n >= limit
def ungroup_emoji(toks: Collection[str]) -> List[str]:  #from pythainlp
    """
    Ungroup Zero Width Joiner (ZVJ) Emojis
    See https://emojipedia.org/emoji-zwj-sequence/
    """
    res = []
    for tok in toks:
        if emoji.emoji_count(tok) == len(tok):
            res.extend(list(tok))
        else:
            res.append(tok)
    return res
示例#16
0
    async def send_makar_message(self, ctx, *, arg=None):
        """Send famous (maybe) sentence.

        Args:
            ctx (commands.context.Context): Context object to execute functions
            arg (Union[str, None]): String with custom name or user mention
        """
        if not arg:
            try:
                r_user = await users.get_random_user(ctx.message)
            except UsersNotFound as warning:
                await ctx.reply(f"Произошла ошибка: {warning}!")
                return
            user = users.get_members_name(r_user)
            await ctx.reply(f"Улыбок тебе дед {user[::-1]}")
        else:
            if emoji.emoji_count(ctx.message.content) > 0:
                await ctx.reply(
                    "К сожалению, отзеркаливание смайлов не имеет смысла",
                    delete_after=self.delay_time,
                )
                await asyncio.sleep(self.delay_time)
                await ctx.message.delete()
            elif arg.startswith("<@&"):
                await ctx.reply(
                    "К сожалению, я не могу обработать это",
                    delete_after=self.delay_time,
                )
                await asyncio.sleep(self.delay_time)
                await ctx.message.delete()
            elif arg.startswith("<:"):
                await ctx.reply(
                    "К сожалению, отзеркаливание эмодзи не имеет смысла...",
                    delete_after=self.delay_time,
                )
                await asyncio.sleep(self.delay_time)
                await ctx.message.delete()
            elif "@everyone" in arg or "@here" in arg:
                await ctx.reply(
                    "Похоже вы пытаетесь передать "
                    "`@here` или `@everyone`, что может вызвать ошибку",
                    delete_after=self.delay_time,
                )
                await asyncio.sleep(self.delay_time)
                await ctx.message.delete()
            else:
                if arg.startswith("<@!"):
                    custom_member = await ctx.guild.fetch_member(
                        arg[3:len(arg) - 1])
                    user = users.get_members_name(custom_member)
                else:
                    user = arg
                await ctx.reply(f"Улыбок тебе дед {user[::-1]}")
示例#17
0
def ungroup_emoji(toks):
    "Ungroup emojis"

    res = []
    for tok in toks:
        if emoji.emoji_count(tok) == len(tok):
            for char in tok:
                res.append(char)
        else:
            res.append(tok)

    return res
示例#18
0
def tweet_cleaning_for_sentiment_analysis(tweet):
    translator = Translator()

    #Escaping HTML characters

    tweet = BeautifulSoup(tweet).get_text()

    #Deal with emoticons
    words = tweet.split()
    reformed = [SMILEY[word] if word in SMILEY else word for word in words]
    tweet = " ".join(reformed)

    #Special case not handled previously.
    tweet = tweet.replace('\x92', "")
    tweet = tweet.replace('\x85', "")

    #Removal of hastags/account
    tweet = ' '.join(re.sub("(@[A-Za-z0-9]+)", " user ",
                            tweet).split())  #verificare posizione nel testo
    tweet = ' '.join(re.sub("#", "", tweet).split())

    #|(#[A-Za-z0-9]+)
    #Removal of address
    tweet = ' '.join(
        re.sub("(\w+:\/\/\S+)", " url ",
               tweet).split())  #valutare cancellezione url se a fine frase

    #Removal of Punctuation
    tweet = ' '.join(re.sub("[\.\,\!\?\:\;\-\=\]", " ",
                            tweet).split())  #rimuovere << oppure ""

    #CONTRACTIONS source: https://en.wikipedia.org/wiki/Contraction_%28grammar%29
    tweet = tweet.replace("’", " ")

    # Standardizing words
    tweet = ''.join(''.join(s)[:2] for _, s in itertools.groupby(tweet))

    number = emoji.emoji_count(tweet)

    #Deal with emojis

    tweet = emoji.demojize(tweet, use_aliases=False, delimiters=("", ""))
    tweet = tweet.replace("_", " ")

    tweet = tweet.replace(":", " ")
    if number != 0:
        tweet = translator.translate(tweet, src='en', dest='it').text

    tweet = ' '.join(tweet.split())

    #Lower case
    tweet = tweet.lower()
    return tweet
示例#19
0
    async def post(self, request: Request, data: dict) -> Response:
        """Handle the POST request for registration."""
        hass = request.app["hass"]

        webhook_id = secrets.token_hex()

        if hass.components.cloud.async_active_subscription():
            data[
                CONF_CLOUDHOOK_URL
            ] = await hass.components.cloud.async_create_cloudhook(webhook_id)

        data[CONF_WEBHOOK_ID] = webhook_id

        if data[ATTR_SUPPORTS_ENCRYPTION] and supports_encryption():
            data[CONF_SECRET] = secrets.token_hex(SecretBox.KEY_SIZE)

        data[CONF_USER_ID] = request["hass_user"].id

        if slugify(data[ATTR_DEVICE_NAME], separator=""):
            # if slug is not empty and would not only be underscores
            # use DEVICE_NAME
            pass
        elif emoji.emoji_count(data[ATTR_DEVICE_NAME]):
            # If otherwise empty string contains emoji
            # use descriptive name of the first emoji
            data[ATTR_DEVICE_NAME] = emoji.demojize(
                emoji.emoji_lis(data[ATTR_DEVICE_NAME])[0]["emoji"]
            ).replace(":", "")
        else:
            # Fallback to DEVICE_ID
            data[ATTR_DEVICE_NAME] = data[ATTR_DEVICE_ID]

        await hass.async_create_task(
            hass.config_entries.flow.async_init(
                DOMAIN, data=data, context={"source": "registration"}
            )
        )

        remote_ui_url = None
        try:
            remote_ui_url = hass.components.cloud.async_remote_ui_url()
        except hass.components.cloud.CloudNotAvailable:
            pass

        return self.json(
            {
                CONF_CLOUDHOOK_URL: data.get(CONF_CLOUDHOOK_URL),
                CONF_REMOTE_UI_URL: remote_ui_url,
                CONF_SECRET: data.get(CONF_SECRET),
                CONF_WEBHOOK_ID: data[CONF_WEBHOOK_ID],
            },
            status_code=HTTP_CREATED,
        )
示例#20
0
 def __init__(self, line: str):
     self.sender = None
     self.content = ""
     self.date = None
     self.emojis = list()
     self.group_event = False
     try:
         self.date = datetime.date(int(line[6:10]), int(line[3:5]), int(line[0:2]))
         pattern = " \".[^\"]*\""
         if re.sub(pattern, "", line[19:]).__contains__(":"):
             offset = line[19:].index(":") + 19
             self.sender = line[19: offset]
             self.content = line[offset + 2:]
         else:  # is a group event line
             self.group_event = True
             if line.__contains__("removeu"): #TODO ver o fomrtado da remoção
                 offset = line.index("removeu") - 1
                 self.sender = line[19:offset]
                 offset = offset + 1
                 self.content = line[offset:]
             elif line.__contains__("adicionou"):#TODO ver o formato de adicionar
                 offset = line.index("adicionou") - 1
                 self.sender = line[19:offset]
                 offset = offset + 1
                 self.content = line[offset:]
             elif line.__contains__("saiu"): #TODO ver o formato de sair
                 offset = line.index("saiu") - 1
                 self.sender = line[19:offset]
                 self.content = "saiu"
             elif line.__contains__("mudou o nome de"):
                 offset = line.index("mudou o nome de") - 1
                 self.sender = line[19:offset]
                 offset = offset + 1
                 self.content = line[offset:]
             elif line.__contains__("mudou a imagem"):
                 offset = line.index("mudou a imagem") - 1
                 self.sender = line[19:offset]
                 offset = offset + 1
                 self.content = line[offset:]
             elif line.__contains__("apagou a imagem"):
                 offset = line.index("apagou a imagem") - 1
                 self.sender = line[19:offset]
                 offset = offset + 1
                 self.content = line[offset:]
         if emoji.emoji_count(self.content) > 0:
             self.emojis = emoji.emoji_lis(line)
     except Exception as e:
         print(e)
     if self.sender == "Você":
         self.sender = MY_WHATSAPP_USERNAME
示例#21
0
	def clean(self):

		cleaned_data = super(SignupForm, self).clean()
		new_password = cleaned_data.get("pwd")
		confirm_password = cleaned_data.get("cpwd")

		if new_password != confirm_password:
			self.add_error("cpwd", "Password and Confirm Password do not match!")

		# Make sure the aren't any emojis in the password
		if emoji.emoji_count(new_password):
			self.add_error("pwd", "Your password cannot contain any emojis. 💥BOOOM!!!...")

		return cleaned_data
示例#22
0
    def find_token_matches(self, tweet_tokens):
        """
        calculates the occurence of positive and negative words
        in a given tweet and returns a list of assigned scores
        +1 means that a token is positive, -1 that a token is 
        negative, 0 that the token was not found in the lexicon

	    Parameters
	    ----------
	    tweet_tokens : List
		     list of preprocessed Tweet tokens (cleaning, etc.)

	    Returns
	    -------
	    scores : List
		    list of scores (sentiment values) derived from matches
		    between the tokenized tweets and the opinion lexicon
        """
        scores = []
        token_pos = 1
        token_neg = -1
        token_neutral = 0

        # sometimes one token holds more than one emoji -> these need
        # to split too by using the emoji Python library
        tmp = []
        for ii in range(len(tweet_tokens)):
            token = tweet_tokens[ii]
            if emoji.emoji_count(token) <= 1:
                tmp.append(token)
                continue
            emoji_tokens = self.split_mutliple_emojis(token)
            tmp = list(chain(tmp, emoji_tokens))

        # loop over the tokens in a tweet and assign the sentiment
        # depending on the match to the lexicon -> it is necessary to
        # call the load_lexicon method first
        for token in tweet_tokens:
            if (token in self.pos):
                scores.append(token_pos)
            elif (token in self.neg):
                scores.append(token_neg)
            else:
                scores.append(token_neutral)
            # endif
        # endfor
        return scores
示例#23
0
 def __init__(self, line: str, user_typed: bool):
     self.user_typed = user_typed
     self.sender = None
     self.content = ""
     self.date = None
     self.emojis = list()
     self.group_event = False
     try:
         if line[0] == "[":
             self.date = datetime.date(int(line[7:11]), int(line[4:6]), int(line[1:3]))
             pattern = " \".[^\"]*\""
             if re.sub(pattern, "", line[22:]).__contains__(":"):
                 offset = line[22:].index(":") + 22
                 self.sender = line[22: offset]
                 self.content = line[offset + 2:]
             else: #is a group event line
                 self.group_event = True
                 if line.__contains__("removeu"):
                     offset = line.index("removeu") - 1
                     self.sender = line[22:offset]
                     offset = offset + 1
                     self.content = line[offset:]
                 elif line.__contains__("adicionou"):
                     offset = line.index("adicionou") - 1
                     self.sender = line[22:offset]
                     offset = offset + 1
                     self.content = line[offset:]
                 elif line.__contains__("saiu"):
                     offset = line.index("saiu") - 1
                     self.sender = line[22:offset]
                     self.content = "saiu"
                 elif line.__contains__("mudou o nome do grupo para"):
                     offset = line.index("mudou o nome do grupo para") - 1
                     self.sender = line[22:offset]
                     offset = offset + 1
                     self.content = line[offset:]
                 elif line.__contains__("mudou a imagem"):
                     offset = line.index("mudou a imagem") - 1
                     self.sender = line[22:offset]
                     offset = offset + 1
                     self.content = line[offset:]
             if emoji.emoji_count(self.content) > 0:
                 self.emojis = emoji.emoji_lis(line)
     except Exception as e:
         print(e)
     if self.sender == "Você":
         self.sender = MY_WHATSAPP_USERNAME
示例#24
0
def give_gift(command, channel):
    """Gives a dog or emoji to someone."""
    attachments = None
    splt = command.replace(" a ", " ").split(" ")
    recipient = splt[1]
    reward = emoji.emojize(f":{splt[2]}:", use_aliases=True)
    if recipient.startswith("<@") and (emoji.emoji_count(reward) > 0):
        text = f"{recipient} you deserved a {reward}"
        if splt[2] == "dog":
            text = ""
            attachments = [{
                "title": f"dog for {recipient}",
                "image_url": random_dog_url()
            }]
    else:
        text = "No."
    post_message(channel=channel, text=text, attachments=attachments)
示例#25
0
def ungroup_emoji(toks: Collection[str]) -> Collection[str]:
    """
    Ungroup Zero Width Joiner (ZVJ) Emojis
    See https://emojipedia.org/emoji-zwj-sequence/
    :param Collection[str] toks: list of tokens
    :return: list of tokens where emojis are ungrouped
    :rtype: Collection[str]
    :Example:
        >>> toks = []
        >>> ungroup_emoji(toks)
        []
    """
    res = []
    for tok in toks:
        if emoji.emoji_count(tok) == len(tok):
            res.extend(list(tok))
        else:
            res.append(tok)
    return res
示例#26
0
    async def __custom_ship(self, ctx, args):
        """Ship with two custom names from user.

        This function runs ship with two custom names from arguments,
        rather ship with random users

        Args:
            ctx (commands.context.Context): Context object to execute functions
            args (list): List of arguments (Custom names for ship)
        """
        if emoji.emoji_count(ctx.message.content):
            await ctx.reply(
                "К сожалению, шип смайлов не имеет смысла",
                delete_after=self.delete_time,
            )
            await asyncio.sleep(self.delete_time)
            await ctx.message.delete()
        elif "<@&" in args:
            await ctx.reply("К сожалению, я не могу обработать это",
                            delete_after=self.delete_time)
            await asyncio.sleep(self.delete_time)
            await ctx.message.delete()
        elif "<:" in args:
            await ctx.reply("К сожалению, шип эмодзи не имеет смысла",
                            delete_after=self.delete_time)
            await asyncio.sleep(self.delete_time)
            await ctx.message.delete()
        elif "@everyone" in args or "@here" in args:
            await ctx.reply(
                "Похоже вы пытаетесь передать `@here` или `@everyone`, "
                "что может вызвать ошибку",
                delete_after=self.delete_time,
            )
            await asyncio.sleep(self.delete_time)
            await ctx.message.delete()
        else:
            first_user_info = await self.__get_user_info(ctx, args[0])
            second_user_info = await self.__get_user_info(ctx, args[1])
            first_username_part = first_user_info[0][:first_user_info[1]]
            second_username_part = second_user_info[0][second_user_info[1]:]
            final_name = first_username_part + second_username_part
            await ctx.reply(
                f"Данная парочка смело бы называлась - **{final_name}**")
示例#27
0
	def clean(self):

		cleaned_data = super(AccountSecurityForm, self).clean()
		old_password = cleaned_data.get("opwd")
		new_password = cleaned_data.get("npwd")
		confirm_password = cleaned_data.get("cpwd")

		# Check if the new password and confirm password match
		if new_password != confirm_password:
			self.add_error("cpwd", "New Password and Confirm Password do not match!")

		# Make sure the new password and old password aren't the same
		if new_password == old_password:
			self.add_error("npwd", "Your new password is the same as the old one. We won't change it. Try a different password.")

		# Make sure the aren't any emojis in the password
		if emoji.emoji_count(new_password):
			self.add_error("npwd", "Your password cannot contain any emojis.")

		return cleaned_data
示例#28
0
 def process(self, tweet_text):
     num_emoji = emoji.emoji_count(tweet_text)
     self.emoji_counter += num_emoji
     #print(num_emoji)
     tweet_text = tweet_text.lower()  # convert text to lower-case
     tweet_text = re.sub('((www\.[^\s]+)|(https?://[^\s]+))', 'URL',
                         tweet_text)  # remove URLs
     tweet_text = re.sub('@[^\s]+', 'AT_USER',
                         tweet_text)  # remove usernames
     tweet_text = re.sub(r'#([^\s]+)', r'\1',
                         tweet_text)  # remove the # in #hashtag
     tweet_text = emoji.demojize(tweet_text)  # repace emoji icon by word
     tweet_text = re.sub(':', ' ', tweet_text)  # :emoji word
     tweet_text = word_tokenize(self.replace(
         tweet_text))  # replace abbrev. and perform tokenization
     # remove repeated characters (helloooooooo into hello) and stopwords
     return [
         self.replace_repeatwords(word) for word in tweet_text
         if word not in self._stopwords
     ]
示例#29
0
def _set_text(user_session: UserSession,
              message: Optional[str]) -> Sequence[Answer]:
    """
    Проверяет правильность присланного текста для стикера, обновляет текст в
    экземпляре пользовательской сессии
    """
    alias = _set_text.alias
    if message is None:
        return (Answer(text=get_message(step=alias)), )
    if message in USER_COMMANDS['SERVICE_COMMANDS']:
        return (Answer(
            text=get_message(step=alias, message_type='unsupported_command')),
                )
    if emoji_count(message) > 0:
        return (Answer(
            text='Текст стикера не может содержать в себе смайлики, '
            'пришлите текст без смайликов'), )

    user_session.data_class.text = message
    handler.update_current_step(user_session)
    return handler.handle_session(user_session)
示例#30
0
def emojify(inp):
    split_text = inp.split()

    index = 0
    last_one_was_an_emoji = False
    for word in split_text:
        if emoji.emoji_count(word) > 0 or last_one_was_an_emoji:
            last_one_was_an_emoji = False
            index += 1
            continue

        emoji_for_word = emoji_found_for(word)

        if emoji_for_word is not None:
            last_one_was_an_emoji = True
            split_text[index] += emoji_for_word

        index += 1

    reconstructed_with_emoji = " ".join(split_text)

    return reconstructed_with_emoji
示例#31
0
def has_x_or_more_emojis(bot: discord.Client, guild: discord.Guild, text: str,
                         limit: int):
    n = emoji.emoji_count(text)

    if n >= limit:
        return True

    if "<" not in text:  # No need to run a regex if no custom emoji can be present
        return False

    for m in re.finditer(EMOJI_RE, text):
        emoji_id = int(m.group(1))

        if discord.utils.get(guild.emojis, id=emoji_id):
            n += 1
        else:
            if discord.utils.get(bot.emojis, id=emoji_id):
                n += 1

        if n == limit:
            return True

    return False