<commit_before># triviabot
Trivia bot that runs in a Slack channel.

To install run `composer require btk/triviabot dev-master`.

It's strongly recommended to make the root of your webserver/subdomain the folder triviabot/src/webroot as this will keep your db and config files etc away from prying eyes.

Things you'll need to set up if you want this to run:

* Incoming web hook integration in slack (put these details in config.php)
* Outgoing web hook in slack (put these details in config.php)
* DB details (put these in config.php)
* A way of running a script at an interval (e.g. CRON) (you want to run vendor/btk/triviabot/src/run.php as often as you can stomach)

Your web server should ideally use a sub domain where the web root is the folder /vendor/btk/triviabot/src/webroot/ so your outgoing web hook URL can be, e.g. http://triviabot.example.com/endpoint.php

###Example CRON Settings.

I use a 10 second delay between running the scripts. I've tested this with over 30,000 questions loaded in the bot and it works fine for me.
Cron however, only uses minutes as it's minimum time increment. So I set mine up like this...


    * * * * * php /var/www/triviabot/vendor/btk/triviabot/src/run.php  
    * * * * * sleep 10; php /var/www/triviabot/vendor/btk/triviabot/src/run.php
    * * * * * sleep 20; php /var/www/triviabot/vendor/btk/triviabot/src/run.php
    * * * * * sleep 30; php /var/www/triviabot/vendor/btk/triviabot/src/run.php
    * * * * * sleep 40; php /var/www/triviabot/vendor/btk/triviabot/src/run.php
    * * * * * sleep 50; php /var/www/triviabot/vendor/btk/triviabot/src/run.php

The minimum delay between questions/hints (the output of the run.php file) is 20 seconds so this should give more than we need.

###Database setup.

In the vendor/btk/triviabot/ folder there is a triviabot.sql file that you can import into your database to set up your tables for the bot properly.

###Loading Questions

Question files should be placed in the questions folder. An example question file is included for reference. To load this in the bot type the command `!trivia load example.txt` in your slack trivia channel.
You should receive a response from the bot saying your file is loaded.
Loading large files may require your PHP max_execution_time is set to a larger number, 30 seconds is the default. A value of 300 allowed me to load a 350,000 question strong file.

I have included a file named questions.sql.zip which can be inserted into your database should you wish a pre-populated list of over 160,000 questions to kick you off. This includes the example.txt questions. **Load this file via MySQL not via the** `!trivia load [file]` **command**<commit_msg>Minor readme update<commit_after># triviabot
Trivia bot that runs in a Slack channel.

To install run `composer require btk/triviabot dev-master`.

It's strongly recommended to make the root of your webserver/subdomain the folder triviabot/src/webroot as this will keep your db and config files etc away from prying eyes.

Things you'll need to set up if you want this to run:

* Incoming web hook integration in slack (put these details in config.php)
* Outgoing web hook in slack (put these details in config.php)
* DB details (put these in config.php)
* A way of running a script at an interval (e.g. CRON) (you want to run vendor/btk/triviabot/src/run.php as often as you can stomach)

Your web server should ideally use a sub domain where the web root is the folder /vendor/btk/triviabot/src/webroot/ so your outgoing web hook URL can be, e.g. http://triviabot.example.com/endpoint.php

###Example CRON Settings

I use a 10 second delay between running the scripts. I've tested this with over 30,000 questions loaded in the bot and it works fine for me.
Cron however, only uses minutes as it's minimum time increment. So I set mine up like this...


    * * * * * php /var/www/triviabot/vendor/btk/triviabot/src/run.php  
    * * * * * sleep 10; php /var/www/triviabot/vendor/btk/triviabot/src/run.php
    * * * * * sleep 20; php /var/www/triviabot/vendor/btk/triviabot/src/run.php
    * * * * * sleep 30; php /var/www/triviabot/vendor/btk/triviabot/src/run.php
    * * * * * sleep 40; php /var/www/triviabot/vendor/btk/triviabot/src/run.php
    * * * * * sleep 50; php /var/www/triviabot/vendor/btk/triviabot/src/run.php

The minimum delay between questions/hints (the output of the run.php file) is 20 seconds so this should give more than we need.

###Database Setup

In the vendor/btk/triviabot/ folder there is a triviabot.sql file that you can import into your database to set up your tables for the bot properly.

###Loading Questions

Question files should be placed in the questions folder. An example question file is included for reference. To load this in the bot type the command `!trivia load example.txt` in your slack trivia channel.
You should receive a response from the bot saying your file is loaded.
Loading large files may require your PHP max_execution_time is set to a larger number, 30 seconds is the default. A value of 300 allowed me to load a 350,000 question strong file.

I have included a file named questions.sql.zip which can be inserted into your database should you wish a pre-populated list of over 160,000 questions to kick you off. This includes the example.txt questions. **Load this file via MySQL not via the** `!trivia load [file]` **command**
{'fraction_non_alphanumeric': 0.07738095238095238, 'fraction_numerical': 0.013392857142857142, 'mean_word_length': 3.7541998231653406, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 12, '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': '1902363', 'n_tokens_mistral': 1751, 'n_tokens_neox': 1596, 'n_words': 753}