This is a text based game powered by a slack bot and the Coveo Cloud V2 platform
This project was to combine all my previous projects together and make one in my field of study. I used my last projects to quickly created a web source and parse a website full of mosnters. The website contained random monsters from DnD 5e. Then when generating the map of the game, I do a randomized call to the source to get a random monster. It works pretty well.
This is a pretty long setup. Running a "Local setup" might be a pain, but here goes.
- Create a new app in your team
- Add a bot user in the app
- Install the app in your team, keep the
Bot User OAuth Access Tokenfor later
- Download the following requirements
pip install pyyamlpip install slackclient
- Rename
example-config.ymltoconfig.yml- Inside the new
config.yml, change the values of the variables monsters_urlto the url of where your org livesmonster_api_keyto a new API key with the following enabledSearch > Execute queries
- Inside the new
- Next we need to get the ID of the bot
- Go here and navigate to the
Obtaining Our Bot’s IDsection - Change the line
os.environ.get('SLACK_BOT_TOKEN')to just put your bot's token - Run the script and save the output for later
- Go here and navigate to the
- Now we need to setup the enviroment variables. This step maybe be different depending on how you run your script. Since I ran mine off VSCode, I'll do those steps
- Go to your
launch.json - Find the python instance type that you run, usually
Python - Under the
envvariable, add the following keys and values:"SLACK_BOT_TOKEN": "Bot User OAuth Access Token FROM EARLIER""BOT_ID": "Bot ID FROM EARLIER"
- After changing to the right values, your bot should be up and running
- Go to your
- Create a Web Source called
Monsters- Under site url, put
http://chisaipete.github.io/bestiary/ - Under advanced settings, put
Maximum crawling depthto1 - Under Web Scraping, add the following config
- After adding the config, save but don't rebuild
- Add all the extensions in the Extensions section to the source, there should be 3 total.
- Under site url, put
- Build the Web source and wait
- There should be 51 valid monster in the source when it's done (Aug 4th, 2017)
Done! I may have missed a step, as I did this README after completing this project...
[
{
"for": {
"urls": [
".*"
]
},
"exclude": [
{
"type": "CSS",
"path": ".tag-list"
},
{
"type": "CSS",
"path": ".site-footer"
},
{
"type": "CSS",
"path": ".rss-subscribe"
},
{
"type": "XPATH",
"path": "//a[@href=\"#top\"]"
},
{
"type": "XPATH",
"path": "//*[@id=\"sortBy\"]"
},
{
"type": "XPATH",
"path": "//*[@id=\"creatureSearch\"]"
},
{
"type": "CSS",
"path": ".site-header"
}
],
"metadata": {
"ac": {
"type": "XPATH",
"path": "//p[contains(., 'Armor Class')]/text()"
},
"hp": {
"type": "XPATH",
"path": "//p[contains(., 'Hit Points')]/text()"
},
"challenge": {
"type": "XPATH",
"path": "//p[contains(., 'Challenge')]/text()"
},
"name": {
"type": "CSS",
"path": ".post-title"
}
}
}
]Post-conversion
from random import randint
document.add_meta_data({
"magic": randint(1000000,10000000)
})Pre-conversion
try:
hp = document.get_meta_data_value('challenge')[0]
hp = hp.split(' ')
if hp[0] == '0' or hp[0] == '1/8':
pass
else:
document_api.v1.reject()
except:
document_api.v1.reject()Pre-conversion
try:
hp = document.get_meta_data_value('hp')[0]
if hp == '':
document_api.v1.reject()
except:
document_api.v1.reject()Simply run the script, then scroll to the bottom of your user list of your slack team and click the add button.
Search for your app and click on View. Then you can type start game to start a game.
The game itself should take about 15 minutes to complete, maybe even less depending on luck.
- A slack team with a valid slack
- Python 2.7 with the following libraries
pip install pyyamlpip install slackclient
- A Coveo cloud V2 org
https://www.fullstackpython.com/blog/build-first-slack-bot-python.html
Peter McCormick (Malpp)