sentenceAnalyser.js
//parse message to find which reply function to use
parse message to find which reply function to use
parse message to find which reply function to use
function parser (message) {
  const {first_name} = message.from
  const {text} = message
  var clean = text.toLowerCase()
  const split  = clean.split(' ')
  const commandWithName = split[0]
  const command = commandWithName.split('@')[0] 
  m.logIfSaved(message)
  if ((command !== null) && h.matchWordFromListWithSymbols(command, c.commands.concat(c.secretCommands), true)) {
    clean = clean.replace(commandWithName, '') 
    console.log('Command: ' + command)
    switch (command) {
      case '/talk':
      return noCommand();
      case '/owo':
      return r.owo(clean);
      case '/eight':
      return h.pickRandom(l.eightball);
      case '/music':
      return 'I don\'t know music yet';
      case '/conspiracy':
      return r.conspiracy();
      case '/fact':
      return r.fact(first_name);
      case '/help':
      return r.help();
      case '/about':
      return r.about(first_name);
      case '/who':
      return r.who(clean, first_name);
      case '/navy':
      return r.navy();
      case '/yiff':
      return r.yiff(clean);
      case '/bork':
      return r.bork(clean, 5);
      case '/norsk':
      return r.lufReplace(clean);
      case '/brainfuck':
      return b.brainfuck(clean);
      case '/brainfuckencode':
      return b.encode(clean)
      case '/echo':
      return r.echoMsg(message)
      case '/latin':
      return p.encode(clean)
      case '/latindecode':
      return p.decode(clean)
      case '/remember':
      return m.remember(message)
      case '/forget':
      return m.forget(message)
      case '/shrug':
      return "¯\\_(ツ)_/¯"
      case '/secrets':
      return r.secrets()
      default:
      h.err("Command unknown: " + command)
      return "I don't know the command: " + command + ", but I should";
    }
  }
  else {
    return noCommand();
  }
  function question() {
    if (h.matchWord(clean, 'who')) {
      return r.who(clean, first_name);
    }
    else if (h.matchWordFromList(clean, l.yesNoWords)) {
      return h.pickRandom(l.eightball)
    }
    else if (h.substringMatchInOrder(clean, ['chat', 'id'])) {
      return 'Our lovely chat has the ID: ' + message.chat.id
    }
    else {
      return r.default(first_name)
    }
  }
  function noCommand() {
    if (h.substringMatch(clean, '?')) {
      return question()
    }
    if (h.substringMatchInOrder(clean, c.action)) {
      return r.asteriskAction(clean, first_name)
    }
    if (h.substringMatchAny(clean, c.beep)){
      return r.beep(clean)
    }
    if (h.matchWordFromList(clean, c.fake)){
      return r.fake(clean)
    }
    if (h.substringMatchAny(clean, c.fact)){
      return r.fact(first_name)
    }
    if (h.substringMatch(clean, 'who')) {
      if (h.substringMatch(clean, 'there')){
        return 'Ball!'
      }
      else if (h.substringMatch(clean, 'ball')){
        return 'BallIEVE it or not, I’m walking on air!'
      }
    }
    else if (h.substringMatch(clean, 'good wisdom')) {
      return 'Thanks, I also know a few knock knock jokes'
    }
    else if (h.substringMatch(clean, 'love')) {
      return 'I love ' + first_name + '! ...on the inside anyway'
    }
    else if (h.substringMatch(clean, 'good bot')) {
      return 'Likewise, ' + first_name + ' you\'d make an excellent automaton'
    }
    else if (h.substringMatch(clean, 'knock knock')) {
      return 'Who\' there?'
    }
    else if (h.substringMatch(clean, 'who dares')) {
      return 'It\'s me, the ' + first_name + '. I dispense wisdom from my mighty wisdom stack'
    }
    else if (h.substringMatch(clean, 'wisdom')) {
      return 'Here is my wisdom: If a script is too large for your server, it\'s not yours'
    }
    else if (h.matchWordFromList(clean, l.positive)){
      return r.good(first_name)
    }
    else if (h.matchWordFromList(clean, l.negative)){
      return r.bad(first_name)
    }
    else if (h.matchWordFromList(clean, l.greetings)){
      return 'Hello, ' + first_name + ', how are you?'
    }  
    return r.default(first_name)
  }
}
function parser ( message ) { const { first_name } = message . from const { text } = message var clean = text . toLowerCase ( ) const split = clean . split ( ' ' ) const commandWithName = split [ 0 ] const command = commandWithName . split ( '@' ) [ 0 ] m . logIfSaved ( message ) if ( ( command !== null ) && h . matchWordFromListWithSymbols ( command , c . commands . concat ( c . secretCommands ) , true ) ) { clean = clean . replace ( commandWithName , '' ) console . log ( 'Command: ' + command ) switch ( command ) { case '/talk' : return noCommand ( ) ; case '/owo' : return r . owo ( clean ) ; case '/eight' : return h . pickRandom ( l . eightball ) ; case '/music' : return 'I don\'t know music yet' ; case '/conspiracy' : return r . conspiracy ( ) ; case '/fact' : return r . fact ( first_name ) ; case '/help' : return r . help ( ) ; case '/about' : return r . about ( first_name ) ; case '/who' : return r . who ( clean , first_name ) ; case '/navy' : return r . navy ( ) ; case '/yiff' : return r . yiff ( clean ) ; case '/bork' : return r . bork ( clean , 5 ) ; case '/norsk' : return r . lufReplace ( clean ) ; case '/brainfuck' : return b . brainfuck ( clean ) ; case '/brainfuckencode' : return b . encode ( clean ) case '/echo' : return r . echoMsg ( message ) case '/latin' : return p . encode ( clean ) case '/latindecode' : return p . decode ( clean ) case '/remember' : return m . remember ( message ) case '/forget' : return m . forget ( message ) case '/shrug' : return "¯\\_(ツ)_/¯" case '/secrets' : return r . secrets ( ) default : h . err ( "Command unknown: " + command ) return "I don't know the command: " + command + ", but I should" ; } } else { return noCommand ( ) ; } function question ( ) { if ( h . matchWord ( clean , 'who' ) ) { return r . who ( clean , first_name ) ; } else if ( h . matchWordFromList ( clean , l . yesNoWords ) ) { return h . pickRandom ( l . eightball ) } else if ( h . substringMatchInOrder ( clean , [ 'chat' , 'id' ] ) ) { return 'Our lovely chat has the ID: ' + message . chat . id } else { return r . default ( first_name ) } } function noCommand ( ) { if ( h . substringMatch ( clean , '?' ) ) { return question ( ) } if ( h . substringMatchInOrder ( clean , c . action ) ) { return r . asteriskAction ( clean , first_name ) } if ( h . substringMatchAny ( clean , c . beep ) ) { return r . beep ( clean ) } if ( h . matchWordFromList ( clean , c . fake ) ) { return r . fake ( clean ) } if ( h . substringMatchAny ( clean , c . fact ) ) { return r . fact ( first_name ) } if ( h . substringMatch ( clean , 'who' ) ) { if ( h . substringMatch ( clean , 'there' ) ) { return 'Ball!' } else if ( h . substringMatch ( clean , 'ball' ) ) { return 'BallIEVE it or not, I’m walking on air!' } } else if ( h . substringMatch ( clean , 'good wisdom' ) ) { return 'Thanks, I also know a few knock knock jokes' } else if ( h . substringMatch ( clean , 'love' ) ) { return 'I love ' + first_name + '! ...on the inside anyway' } else if ( h . substringMatch ( clean , 'good bot' ) ) { return 'Likewise, ' + first_name + ' you\'d make an excellent automaton' } else if ( h . substringMatch ( clean , 'knock knock' ) ) { return 'Who\' there?' } else if ( h . substringMatch ( clean , 'who dares' ) ) { return 'It\'s me, the ' + first_name + '. I dispense wisdom from my mighty wisdom stack' } else if ( h . substringMatch ( clean , 'wisdom' ) ) { return 'Here is my wisdom: If a script is too large for your server, it\'s not yours' } else if ( h . matchWordFromList ( clean , l . positive ) ) { return r . good ( first_name ) } else if ( h . matchWordFromList ( clean , l . negative ) ) { return r . bad ( first_name ) } else if ( h . matchWordFromList ( clean , l . greetings ) ) { return 'Hello, ' + first_name + ', how are you?' } return r . default ( first_name ) } }
parse message to find which reply function to use
parse message to find which reply function to use
//because it might be /command@lufbot //if command is in list //we don't want the name //find actual command //QUESTION //QUESTION //ACTION //BEEP //FAKE/GAY //FACT //good //bad //greetings //default