<commit_before>import { GameMap, Player, GameTypes, GameType } from 'hive-api';
import { ChangeType } from "../updater/TeamUpdater";
import { TwitterHandleProvider } from "./TwitterHandleProvider";
import { MessageProvider } from "./MessageProvider";
import { UniquePlayerUpdater } from "../updater/UniquePlayerUpdater";
import { NotificationTypes } from "./NotificationTypes";
import { TwitterBot as _TwitterBot } from "lergins-bot-framework";
import { notificationSender } from "../main";

const sendWorldNameGameTypes = [GameTypes.BED.id, GameTypes.SKY.id, GameTypes.GNT.id];

export class TwitterBot extends _TwitterBot {
  tweetNotification: boolean = false;
  
  constructor(settings){
    super(settings);
    
    if (settings.tweetNotification) this.tweetNotification = true;
  }

  update(key: string, data: any) {
    switch (key) {
      case NotificationTypes.NEW_MAP:
        return this.sendNewMap(data);
      case NotificationTypes.TEAM_CHANGE:
        return this.sendTeamChange(data.player, data.type);
      case NotificationTypes.COUNT:
        return this.sendCount(data.type, data.count);
    }
  }

  async send(message, sendNotification=true) {
    let a = super.send(message);

    try {
      if (this.tweetNotification && sendNotification){
        let data = await a.then(res => res.data).catch(console.error);
      
        notificationSender().send(NotificationTypes.TWEET, data);
      }
    } catch(err) {
      console.log(err);
    }
  }

  async sendNewMap(map: GameMap) {
    let message = `There is a new ${map.gameType.name} map on @theHiveMC!\n\n`
    
    if(map.mapName && map.mapName !== "UnknownMap"){
      if (sendWorldNameGameTypes.indexOf(map.gameType.id) === -1) {
        message += map.mapName;
      }else{
        message += `${map.mapName} (${map.worldName})`;
      }
    }else{
      message += map.worldName;
    }

    if (map.author && map.author !== "UnknownAuthor") {
      // load the twitter handles of the creators
      let twitterHandles: Map<string, string> = new Map();

      await Promise.all(
        getNamesFromMapAuthor(map.author)
          .map(async name => twitterHandles.set(name, await TwitterHandleProvider.get(new Player(name))))
      );

      let author: string = map.author;

      // replace the names by the handles
      [...twitterHandles.entries()].forEach(([name, handle]) => {
        let replaceName = name;

        if (handle === name) {
          replaceName = `@${name}`;
        } else if (handle) {
          replaceName = `${name} (@${handle})`;
        }

        author = author.replace(name, replaceName);
      });
      
      message += ` by ${author}`;
    }

    let adv = `\nhttps://hive.lergin.de/maps`

    if (message.length + adv.length <= 140) {
      message += adv;
    }

    this.send(message, false);
  }

  async sendTeamChange(player: Player, type: ChangeType) {
    let message = "";
    let twitterHandle = await TwitterHandleProvider.get(player);

    if (twitterHandle === player.name) {
      message = `.@${player.name} `;
    } else if (twitterHandle) {
      message = `${player.name} (@${twitterHandle}) `;
    } else {
      message = `${player.name} `;
    }

    switch (type) {
      case ChangeType.MODERATOR_ADD:
        message += `is now a Moderator on @theHiveMC 🙂`;
        break;
      case ChangeType.MODERATOR_REMOVE:
        message += `is no longer a Moderator on @theHiveMC ☹️`;
        break;
      case ChangeType.SENIOR_MODERATOR_ADD:
        message += `is now a Senior Moderator on @theHiveMC 😃`;
        break;
      case ChangeType.SENIOR_MODERATOR_REMOVE:
        message += `is no longer a Senior Moderator on @theHiveMC 😢`;
        break;
      case ChangeType.DEVELOPER_ADD:
        message = `🎉 ${message} is now a Developer on @theHiveMC 🎉`;
        break;
      case ChangeType.DEVELOPER_REMOVE:
        message += `is no longer a Developer on @theHiveMC 😭`;
        break;
      case ChangeType.OWNER_ADD:
        message = `🎉🎉🎉 ${message} is now an Owner on @theHiveMC 🎉🎉🎉`;
        break;
      case ChangeType.OWNER_REMOVE:
        message += `is no longer an Owner on @theHiveMC 😱`;
        break;
      case ChangeType.NECTAR_ADD:
        message = `${message} is now a part of @TeamNectar 😀`;
        break;
      case ChangeType.NECTAR_REMOVE:
        message += `is no longer active on @TeamNectar ☹️`;
        break;
      default:
        message += `is now something else on @theHiveMC but we don't know what 🤔`;
        break;
    }<commit_msg>updated spacing in twitter messages<commit_after>import { GameMap, Player, GameTypes, GameType } from 'hive-api';
import { ChangeType } from "../updater/TeamUpdater";
import { TwitterHandleProvider } from "./TwitterHandleProvider";
import { MessageProvider } from "./MessageProvider";
import { UniquePlayerUpdater } from "../updater/UniquePlayerUpdater";
import { NotificationTypes } from "./NotificationTypes";
import { TwitterBot as _TwitterBot } from "lergins-bot-framework";
import { notificationSender } from "../main";

const sendWorldNameGameTypes = [GameTypes.BED.id, GameTypes.SKY.id, GameTypes.GNT.id];

export class TwitterBot extends _TwitterBot {
  tweetNotification: boolean = false;
  
  constructor(settings){
    super(settings);
    
    if (settings.tweetNotification) this.tweetNotification = true;
  }

  update(key: string, data: any) {
    switch (key) {
      case NotificationTypes.NEW_MAP:
        return this.sendNewMap(data);
      case NotificationTypes.TEAM_CHANGE:
        return this.sendTeamChange(data.player, data.type);
      case NotificationTypes.COUNT:
        return this.sendCount(data.type, data.count);
    }
  }

  async send(message, sendNotification=true) {
    let a = super.send(message);

    try {
      if (this.tweetNotification && sendNotification){
        let data = await a.then(res => res.data).catch(console.error);
      
        notificationSender().send(NotificationTypes.TWEET, data);
      }
    } catch(err) {
      console.log(err);
    }
  }

  async sendNewMap(map: GameMap) {
    let message = `There is a new ${map.gameType.name} map on @theHiveMC!\n\n`
    
    if(map.mapName && map.mapName !== "UnknownMap"){
      if (sendWorldNameGameTypes.indexOf(map.gameType.id) === -1) {
        message += map.mapName;
      }else{
        message += `${map.mapName} (${map.worldName})`;
      }
    }else{
      message += map.worldName;
    }

    if (map.author && map.author !== "UnknownAuthor") {
      // load the twitter handles of the creators
      let twitterHandles: Map<string, string> = new Map();

      await Promise.all(
        getNamesFromMapAuthor(map.author)
          .map(async name => twitterHandles.set(name, await TwitterHandleProvider.get(new Player(name))))
      );

      let author: string = map.author;

      // replace the names by the handles
      [...twitterHandles.entries()].forEach(([name, handle]) => {
        let replaceName = name;

        if (handle === name) {
          replaceName = `@${name}`;
        } else if (handle) {
          replaceName = `${name} (@${handle})`;
        }

        author = author.replace(name, replaceName);
      });
      
      message += ` by ${author}`;
    }

    let adv = `\nhttps://hive.lergin.de/maps`

    if (message.length + adv.length <= 140) {
      message += adv;
    }

    this.send(message, false);
  }

  async sendTeamChange(player: Player, type: ChangeType) {
    let message = "";
    let twitterHandle = await TwitterHandleProvider.get(player);

    if (twitterHandle === player.name) {
      message = `.@${player.name}`;
    } else if (twitterHandle) {
      message = `${player.name} (@${twitterHandle})`;
    } else {
      message = `${player.name}`;
    }

    switch (type) {
      case ChangeType.MODERATOR_ADD:
        message += ` is now a Moderator on @theHiveMC 🙂`;
        break;
      case ChangeType.MODERATOR_REMOVE:
        message += ` is no longer a Moderator on @theHiveMC ☹️`;
        break;
      case ChangeType.SENIOR_MODERATOR_ADD:
        message += ` is now a Senior Moderator on @theHiveMC 😃`;
        break;
      case ChangeType.SENIOR_MODERATOR_REMOVE:
        message += ` is no longer a Senior Moderator on @theHiveMC 😢`;
        break;
      case ChangeType.DEVELOPER_ADD:
        message = `🎉 ${message} is now a Developer on @theHiveMC 🎉`;
        break;
      case ChangeType.DEVELOPER_REMOVE:
        message += ` is no longer a Developer on @theHiveMC 😭`;
        break;
      case ChangeType.OWNER_ADD:
        message = `🎉🎉🎉 ${message} is now an Owner on @theHiveMC 🎉🎉🎉`;
        break;
      case ChangeType.OWNER_REMOVE:
        message += ` is no longer an Owner on @theHiveMC 😱`;
        break;
      case ChangeType.NECTAR_ADD:
        message = `${message} is now a part of @TeamNectar 😀`;
        break;
      case ChangeType.NECTAR_REMOVE:
        message += ` is no longer active on @TeamNectar ☹️`;
        break;
      default:
        message += ` is now something else on @theHiveMC but we don't know what 🤔`;
        break;
    }
{'fraction_non_alphanumeric': 0.1286265857694429, 'fraction_numerical': 0.000882515168229454, 'mean_word_length': 2.6148325358851676, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3722154', 'n_tokens_mistral': 2875, 'n_tokens_neox': 2837, 'n_words': 714}