<commit_before><?php
/**
 * This runs the bot on a timer (CRON JOB)
 * User: billythekid
 */
namespace BTK;
ini_set('display_errors', 1);
include_once(__DIR__.'/config.php');
include_once(__DIR__.'/TriviaBot.php');
include_once(__DIR__.'/db.php');
$game = \Game::first();
$timestamp = time();
if (($game->last_asked + $game->delay) <= $timestamp)
{
    $game->last_asked = $timestamp;
    $game->save();
    $bot = new TriviaBot("Trivia Bot");

    //check if there's a question being asked
    $question = $bot->getCurrentQuestion();
    if (!empty($question))
    {
        $hint = "*Hint {$question->current_hint}*: "; //this will hold our hint
        //get the (first) possible answer
        $answer = unserialize($question->answer)[0];
        $letters = str_split($answer);
        $previousLetter = " ";// the letter after a space are always shown pretend we're starting with one

        //show first letter of each word
        if ($question->current_hint == 1)
        {
            foreach ($letters as $letter)
            {
                if ($previousLetter == " " || $letter == " ")
                {
                    $hint .= $letter;
                } else
                {
                    $hint .= "*";
                }
                $previousLetter = $letter;
            }
        } //show first 3 letters of first word
        elseif ($question->current_hint == 2)
        {
            foreach ($letters as $key => $letter)
            {
                if ($previousLetter == " " || $letter == " " || $key <= 3)
                {
                    $hint .= $letter;
                } else
                {
                    $hint .= "*";
                }
                $previousLetter = $letter;
            }
        } //show all vowels
        elseif ($question->current_hint == 3)
        {
            foreach ($letters as $key => $letter)
            {
                if ($previousLetter == " " || $letter == " " || $key <= 3 || stripos("aeiou", $letter))
                {
                    $hint .= $letter;
                } else
                {
                    $hint .= "*";
                }
                $previousLetter = $letter;
            }
        } else //by this time we just want to see the answer - no more clues!
        {
            $hint = "*Nobody got it!* The answer was _{$answer}_";
            $hint .= "\nNext question coming up...";

            $question->current_hint = -1; // this gets incremented by 1 (to 0 - off) after these conditionals
            if ($game->stopping == 1)
            {
                $game->started = 0;
                $game->stopping = 0;
                $game->save();
                $hint .= "\n *GAME STOPPED*";
            } else
            {
                //set up the next question
                $bot->start(); //this sets a random question's current_hint to 1
            }
        }
        $question->current_hint = $question->current_hint + 1;
        $question->save();

        //send the question and hint/answer to channel

        $message = "{$question->question}\n{$hint}";
        echo "Messsage: $message";
        $url = SLACK_INCOMING_WEBHOOK_URL;
        $data = ['payload'=>$bot->sendMessageToChannel($message)];

        // use key 'http' even if you send the request to https://...
        $options = array(
            'http' => array(
                'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
                'method'  => 'POST',
                'content' => http_build_query($data),
            ),
        );
        $context  = stream_context_create($options);
        file_get_contents($url, false, $context);
    }
    else {
        $bot->start();
    }
}<commit_msg>message bug<commit_after><?php
/**
 * This runs the bot on a timer (CRON JOB)
 * User: billythekid
 */
namespace BTK;
ini_set('display_errors', 1);
include_once(__DIR__.'/config.php');
include_once(__DIR__.'/TriviaBot.php');
include_once(__DIR__.'/db.php');
$game = \Game::first();
$timestamp = time();
if (($game->last_asked + $game->delay) <= $timestamp)
{
    $game->last_asked = $timestamp;
    $game->save();
    $bot = new TriviaBot("Trivia Bot");

    //check if there's a question being asked
    $question = $bot->getCurrentQuestion();
    if (!empty($question))
    {
        $hint = "*Hint {$question->current_hint}*: "; //this will hold our hint
        //get the (first) possible answer
        $answer = unserialize($question->answer)[0];
        $letters = str_split($answer);
        $previousLetter = " ";// the letter after a space are always shown pretend we're starting with one

        //show first letter of each word
        if ($question->current_hint == 1)
        {
            foreach ($letters as $letter)
            {
                if ($previousLetter == " " || $letter == " ")
                {
                    $hint .= $letter;
                } else
                {
                    $hint .= "*";
                }
                $previousLetter = $letter;
            }
        } //show first 3 letters of first word
        elseif ($question->current_hint == 2)
        {
            foreach ($letters as $key => $letter)
            {
                if ($previousLetter == " " || $letter == " " || $key <= 3)
                {
                    $hint .= $letter;
                } else
                {
                    $hint .= "*";
                }
                $previousLetter = $letter;
            }
        } //show all vowels
        elseif ($question->current_hint == 3)
        {
            foreach ($letters as $key => $letter)
            {
                if ($previousLetter == " " || $letter == " " || $key <= 3 || stripos("aeiou", $letter))
                {
                    $hint .= $letter;
                } else
                {
                    $hint .= "*";
                }
                $previousLetter = $letter;
            }
        } else //by this time we just want to see the answer - no more clues!
        {
            $hint = "*Nobody got it!* The answer was _{$answer}_";

            $question->current_hint = -1; // this gets incremented by 1 (to 0 - off) after these conditionals
            if ($game->stopping == 1)
            {
                $game->started = 0;
                $game->stopping = 0;
                $game->save();
                $hint .= "\n *GAME STOPPED*";
            } else
            {
                $hint .= "\nNext question coming up...";
                //set up the next question
                $bot->start(); //this sets a random question's current_hint to 1
            }
        }
        $question->current_hint = $question->current_hint + 1;
        $question->save();

        //send the question and hint/answer to channel

        $message = "{$question->question}\n{$hint}";
        echo "Messsage: $message";
        $url = SLACK_INCOMING_WEBHOOK_URL;
        $data = ['payload'=>$bot->sendMessageToChannel($message)];

        // use key 'http' even if you send the request to https://...
        $options = array(
            'http' => array(
                'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
                'method'  => 'POST',
                'content' => http_build_query($data),
            ),
        );
        $context  = stream_context_create($options);
        file_get_contents($url, false, $context);
    }
    else {
        $bot->start();
    }
}
{'fraction_non_alphanumeric': 0.1456, 'fraction_numerical': 0.004266666666666667, 'mean_word_length': 1.421239509360878, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 61, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '3979950', 'n_tokens_mistral': 2153, 'n_tokens_neox': 2006, 'n_words': 529}