<commit_before>from leaguebot import app
import leaguebot.models.map as screepmap
import leaguebot.services.screeps as screeps
import leaguebot.services.slack as slack
import re
import datetime
import pytz


def sendBattleMessage(battleinfo):
    message = getBattleMessageText(battleinfo)
    sendToSlack(message)


def getBattleMessageText(battleinfo):
    room_name = battleinfo['_id']
    room_owner = screepmap.getRoomOwner(room_name)
    pvp_time = str(battleinfo['lastPvpTime'])
    history_link = '<https://screeps.com/a/#!/history/' + room_name + '?t=' + pvp_time + '|' + pvp_time + '>'
    message = history_link + ' - Battle: ' + '<https://screeps.com/a/#!/room/' + room_name + '|' + room_name + '>'
    if not room_owner:
        return message

    room_level = screepmap.getRoomLevel(room_name)

    if room_level and room_level > 0:
        message += ' RCL ' + str(room_level)

    message += ', defender ' + '<https://screeps.com/a/#!/profile/' + room_owner + '|' + room_owner + '>'
    room_alliance = screepmap.getUserAlliance(room_owner)
    if room_alliance:
        message += ' (' + room_alliance + ')'

    return message


def sendNukeMessage(nukeinfo):
    message = getNukeMessageText(nukeinfo)
    sendToSlack(message)


def getNukeMessageText(nukeinfo):
    tick = screeps.get_time()
    eta = nukeinfo['landTime']-tick
    room_name = nukeinfo['room']
    room_owner = screepmap.getRoomOwner(room_name)
    message = str(tick) + ' - Nuke: ' + '<https://screeps.com/a/#!/room/' + room_name + '|' + room_name + '>' + ' in ' + str(eta) + ' ticks'

    eta_seconds = eta * 3
    diff = eta_seconds * 0.01
    eta_early = eta_seconds - diff
    eta_late = eta_seconds + diff

    now = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
    date_early = now + datetime.timedelta(seconds = eta_early)
    date_late = now + datetime.timedelta(seconds = eta_late)

    message += ' ( between ' + date_early.strftime("%Y-%m-%d %H:%M") + ' to ' + date_late.strftime("%Y-%m-%d %H:%M %Z") + ')'

    if not room_owner:
        message += ', abandoned'
    else:
        room_alliance = screepmap.getUserAlliance(room_owner)
        message += ', defender ' + '<https://screeps.com/a/#!/profile/' + room_owner + '|' + room_owner + '>'<commit_msg>message formatting<commit_after>from leaguebot import app
import leaguebot.models.map as screepmap
import leaguebot.services.screeps as screeps
import leaguebot.services.slack as slack
import re
import datetime
import pytz


def sendBattleMessage(battleinfo):
    message = getBattleMessageText(battleinfo)
    sendToSlack(message)


def getBattleMessageText(battleinfo):
    room_name = battleinfo['_id']
    room_owner = screepmap.getRoomOwner(room_name)
    pvp_time = str(battleinfo['lastPvpTime'])
    history_link = '<https://screeps.com/a/#!/history/' + room_name + '?t=' + pvp_time + '|' + pvp_time + '>'
    message = history_link + ' - Battle: ' + '<https://screeps.com/a/#!/room/' + room_name + '|' + room_name + '>'
    if not room_owner:
        return message

    room_level = screepmap.getRoomLevel(room_name)

    if room_level and room_level > 0:
        message += ' RCL ' + str(room_level)

    message += ', defender ' + '<https://screeps.com/a/#!/profile/' + room_owner + '|' + room_owner + '>'
    room_alliance = screepmap.getUserAlliance(room_owner)
    if room_alliance:
        message += ' (' + room_alliance + ')'

    return message


def sendNukeMessage(nukeinfo):
    message = getNukeMessageText(nukeinfo)
    sendToSlack(message)


def getNukeMessageText(nukeinfo):
    tick = screeps.get_time()
    eta = nukeinfo['landTime']-tick
    room_name = nukeinfo['room']
    room_owner = screepmap.getRoomOwner(room_name)
    message = str(tick) + ' - Nuke: ' + '<https://screeps.com/a/#!/room/' + room_name + '|' + room_name + '>' + ' in ' + str(eta) + ' ticks'

    eta_seconds = eta * 3
    diff = eta_seconds * 0.01
    eta_early = eta_seconds - diff
    eta_late = eta_seconds + diff

    now = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
    date_early = now + datetime.timedelta(seconds = eta_early)
    date_late = now + datetime.timedelta(seconds = eta_late)

    message += ' (between ' + date_early.strftime("%Y-%m-%d %H:%M") + ' to ' + date_late.strftime("%Y-%m-%d %H:%M %Z") + ')'

    if not room_owner:
        message += ', abandoned'
    else:
        room_alliance = screepmap.getUserAlliance(room_owner)
        message += ', defender ' + '<https://screeps.com/a/#!/profile/' + room_owner + '|' + room_owner + '>'
{'fraction_non_alphanumeric': 0.14872021182700795, 'fraction_numerical': 0.002206531332744925, 'mean_word_length': 3.5014895729890765, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 10, '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': '507390', 'n_tokens_mistral': 1661, 'n_tokens_neox': 1579, 'n_words': 285}