@@ -0,0 +1,33 @@ | |||||
# Dota 2 Random - Alexa Skill | |||||
Skill is now available from the [Alexa Skill Store](https://www.amazon.com/binhonglee-Dota2-Random/dp/B073W4GDLS)! | |||||
#### Dependency | |||||
- alexa-sdk | |||||
- node.js | |||||
## Documentations | |||||
### Intents | |||||
| Intents | Description | | |||||
|:---------|:------------| | |||||
| `LaunchRequest` | Introduction to the skill. | | |||||
| `AnyRequest` | Random any hero | | |||||
| `RequestIntent` | Takes in 1 ROLE_TYPES as limitation for random | | |||||
| `RequestTwoIntent` | Takes in 2 ROLE_TYPES as limitation for random | | |||||
| `RequestThreeIntent` | Takes in 3 ROLE_TYPES as limitation for random | | |||||
| `AMAZON.HelpIntent` | Provide examples on how to use the skill | | |||||
| `Stop` | Stop the skill | | |||||
### ROLE_TYPES (Custom slot) | |||||
- melee | |||||
- ranged | |||||
- carry | |||||
- support | |||||
- strength | |||||
- intelligence | |||||
- agility | |||||
- nuker | |||||
- initiator | |||||
- escape |
@@ -1,4 +0,0 @@ | |||||
melee | |||||
ranged | |||||
carry | |||||
support |
@@ -2,23 +2,40 @@ | |||||
"intents": [ | "intents": [ | ||||
{ | { | ||||
"intent": "RequestIntent", | "intent": "RequestIntent", | ||||
"slot": [ | |||||
"slots": [ | |||||
{ | { | ||||
"name": "Category", | |||||
"type": "CustomSlot" | |||||
"name": "Role", | |||||
"type": "ROLE_TYPES" | |||||
} | } | ||||
] | ] | ||||
}, | }, | ||||
{ | { | ||||
"intent": "RequestTwoIntent", | "intent": "RequestTwoIntent", | ||||
"slot": [ | |||||
"slots": [ | |||||
{ | { | ||||
"name": "Category1", | |||||
"type": "CustomSlot" | |||||
"name": "RoleOne", | |||||
"type": "ROLE_TYPES" | |||||
}, | }, | ||||
{ | { | ||||
"name": "Category2", | |||||
"type": "CustomSlot" | |||||
"name": "RoleTwo", | |||||
"type": "ROLE_TYPES" | |||||
} | |||||
] | |||||
}, | |||||
{ | |||||
"intent": "RequestThreeIntent", | |||||
"slots": [ | |||||
{ | |||||
"name": "RoleOne", | |||||
"type": "ROLE_TYPES" | |||||
}, | |||||
{ | |||||
"name": "RoleTwo", | |||||
"type": "ROLE_TYPES" | |||||
}, | |||||
{ | |||||
"name": "RoleThree", | |||||
"type": "ROLE_TYPES" | |||||
} | } | ||||
] | ] | ||||
}, | }, | ||||
@@ -0,0 +1,10 @@ | |||||
melee | |||||
ranged | |||||
carry | |||||
support | |||||
strength | |||||
intelligence | |||||
agility | |||||
nuker | |||||
initiator | |||||
escape |
@@ -1,15 +1,23 @@ | |||||
RequestIntent random {Category} | |||||
RequestIntent random {Category} hero | |||||
RequestIntent random any {Category} | |||||
RequestIntent random any {Category} hero | |||||
RequestIntent random another {Category} | |||||
RequestIntent random another {Category} hero | |||||
RequestTwoIntent random {Category1} {Category2} | |||||
RequestIntent random {Category1} {Category2} hero | |||||
RequestIntent random any {Category1} {Category2} | |||||
RequestIntent random any {Category1} {Category2} hero | |||||
RequestIntent random another {Category1} {Category2} | |||||
RequestIntent random another {Category1} {Category2} hero | |||||
RequestIntent random {Role} | |||||
RequestIntent random {Role} hero | |||||
RequestIntent random any {Role} | |||||
RequestIntent random any {Role} hero | |||||
RequestIntent random another {Role} | |||||
RequestIntent random another {Role} hero | |||||
RequestTwoIntent random {RoleOne} {RoleTwo} | |||||
RequestTwoIntent random {RoleOne} {RoleTwo} hero | |||||
RequestTwoIntent random any {RoleOne} {RoleTwo} | |||||
RequestTwoIntent random any {RoleOne} {RoleTwo} hero | |||||
RequestTwoIntent random another {RoleOne} {RoleTwo} | |||||
RequestTwoIntent random another {RoleOne} {RoleTwo} hero | |||||
RequestThreeIntent random {RoleOne} {RoleTwo} {RoleThree} | |||||
RequestThreeIntent random {RoleOne} {RoleTwo} {RoleThree} hero | |||||
RequestThreeIntent random any {RoleOne} {RoleTwo} {RoleThree} | |||||
RequestThreeIntent random any {RoleOne} {RoleTwo} {RoleThree} hero | |||||
RequestThreeIntent random another {RoleOne} {RoleTwo} {RoleThree} | |||||
RequestThreeIntent random another {RoleOne} {RoleTwo} {RoleThree} hero | |||||
AnyRequest random any hero | AnyRequest random any hero | ||||
AnyRequest random any other hero | AnyRequest random any other hero | ||||
AnyRequest random another | |||||
AnyRequest random another hero | |||||
Stop stop | Stop stop |
@@ -13,7 +13,7 @@ var handlers = { | |||||
'RequestIntent': function () { | 'RequestIntent': function () { | ||||
var given = [] | var given = [] | ||||
var category = this.event.request.intent.slots.Category | |||||
var category = this.event.request.intent.slots.Role.value.toString() | |||||
given.push(category) | given.push(category) | ||||
randomHero(given, (name) => { | randomHero(given, (name) => { | ||||
@@ -23,8 +23,8 @@ var handlers = { | |||||
'RequestTwoIntent': function () { | 'RequestTwoIntent': function () { | ||||
var given = [] | var given = [] | ||||
var category1 = this.event.request.intent.slots.Category1 | |||||
var category2 = this.event.request.intent.slots.Category2 | |||||
var category1 = this.event.request.intent.slots.RoleOne.value.toString() | |||||
var category2 = this.event.request.intent.slots.RoleTwo.value.toString() | |||||
given.push(category1) | given.push(category1) | ||||
given.push(category2) | given.push(category2) | ||||
@@ -33,6 +33,20 @@ var handlers = { | |||||
}) | }) | ||||
}, | }, | ||||
'RequestThreeIntent': function () { | |||||
var given = [] | |||||
var category1 = this.event.request.intent.slots.RoleOne.value.toString() | |||||
var category2 = this.event.request.intent.slots.RoleTwo.value.toString() | |||||
var category3 = this.event.request.intent.slots.RoleThree.value.toString() | |||||
given.push(category1) | |||||
given.push(category2) | |||||
given.push(category3) | |||||
randomHero(given, (name) => { | |||||
this.emit(':tell', name) | |||||
}) | |||||
}, | |||||
'AnyRequest': function () { | 'AnyRequest': function () { | ||||
var given = [] | var given = [] | ||||
randomHero(given, (name) => { | randomHero(given, (name) => { | ||||
@@ -42,7 +56,7 @@ var handlers = { | |||||
}, | }, | ||||
'AMAZON.HelpIntent': function () { | 'AMAZON.HelpIntent': function () { | ||||
this.emit(':ask', 'You can try saying random any hero, random melee carry or random ranged support for more specific randoming.') | |||||
this.emit(':ask', 'You can try saying random any hero, random melee carry or random ranged support.') | |||||
}, | }, | ||||
'Stop': function () { | 'Stop': function () { | ||||
@@ -56,6 +70,21 @@ function randomHero (categories, callback) { | |||||
var location | var location | ||||
httpsGet((heroes) => { | httpsGet((heroes) => { | ||||
var possible = false | |||||
var i = 0 | |||||
while (possible === false && i < heroes.length) { | |||||
if (checkCategory(categories, heroes[i])) { | |||||
possible = true | |||||
} | |||||
i++ | |||||
} | |||||
if (!possible) { | |||||
callback('Random failed') | |||||
return | |||||
} | |||||
do { | do { | ||||
location = random(heroes.length) | location = random(heroes.length) | ||||
} while (!checkCategory(categories, heroes[location])) | } while (!checkCategory(categories, heroes[location])) | ||||
@@ -92,16 +121,14 @@ function random (size) { | |||||
} | } | ||||
function checkCategory (categories, hero) { | function checkCategory (categories, hero) { | ||||
var i = 0 | |||||
var hits = false | var hits = false | ||||
while (i < categories.length) { | |||||
if (categories[i] === hero.primary_attr || categories[i] === hero.attack_type) { | |||||
for (var i = 0; i < categories.length; i++) { | |||||
if (categories[i].toLowerCase().localeCompare(hero.attack_type.toLowerCase()) === 0 || categories[i].toLowerCase().substring(0, 3).localeCompare(hero.primary_attr) === 0) { | |||||
hits = true | hits = true | ||||
} else { | } else { | ||||
for (var j = 0; j < hero.roles.length; j++) { | for (var j = 0; j < hero.roles.length; j++) { | ||||
if (categories[i] === hero.roles[j]) { | |||||
if (categories[i].toLowerCase().localeCompare(hero.roles[j].toLowerCase()) === 0) { | |||||
hits = true | hits = true | ||||
break | break | ||||
} | } | ||||
@@ -109,7 +136,6 @@ function checkCategory (categories, hero) { | |||||
} | } | ||||
if (hits) { | if (hits) { | ||||
i++ | |||||
hits = false | hits = false | ||||
} else { | } else { | ||||
return false | return false | ||||