<commit_before>from unicodedata import east_asian_width

from slackbot.bot import respond_to


def _message_length(message):
    """
    メッセージの長さを返す
    """
    length = 0
    for char in message:
        width = east_asian_width(char)
        if width == 'W':
            length += 2
        elif width == 'Na':
            length += 1

    return length

@respond_to('^suddendeath$')
@respond_to('^suddendeath\s+(.*)')
def suddendeath(message, words='突然の死'):
    """
    突然の死のメッセージを返す
    """
    if words == 'help':
        return

    length = _message_length(words)

    header = '＿' + '人' * (length // 2 + 2) + '＿'
    footer = '￣' + 'Y^' * (length // 2) + 'Y￣'
    middle = "＞　" + words + "　＜"

    message.send("\n".join([header, middle, footer]))

@respond_to('^suddendeath\s+help')
def suddendeath_help(message):
    message.send('''- `$suddendeath`: 突然の死のメッセージを返す
- `$suddendeath words`: words を使って突然の死のメッセージを返す
''')<commit_msg>SAR-1407 fix width for suddendeath words<commit_after>from unicodedata import east_asian_width

from slackbot.bot import respond_to


def _message_length(message):
    """
    メッセージの長さを返す
    """
    length = 0
    for char in message:
        width = east_asian_width(char)
        if width in ('W', 'F', 'A'):
            length += 2
        elif width in ('Na', 'H'):
            length += 1

    return length

@respond_to('^suddendeath$')
@respond_to('^suddendeath\s+(.*)')
def suddendeath(message, words='突然の死'):
    """
    突然の死のメッセージを返す
    """
    if words == 'help':
        return

    length = _message_length(words)

    header = '＿' + '人' * (length // 2 + 2) + '＿'
    footer = '￣' + 'Y^' * (length // 2) + 'Y￣'
    middle = "＞　" + words + "　＜"

    message.send("\n".join([header, middle, footer]))

@respond_to('^suddendeath\s+help')
def suddendeath_help(message):
    message.send('''- `$suddendeath`: 突然の死のメッセージを返す
- `$suddendeath words`: words を使って突然の死のメッセージを返す
''')
{'fraction_non_alphanumeric': 0.16943866943866945, 'fraction_numerical': 0.008316008316008316, 'mean_word_length': 2.85, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7299701', 'n_tokens_mistral': 817, 'n_tokens_neox': 789, 'n_words': 150}