diff --git a/README.md b/README.md new file mode 100644 index 0000000..ded8f9f --- /dev/null +++ b/README.md @@ -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 diff --git a/speechAssets/CustomSlot.txt b/speechAssets/CustomSlot.txt deleted file mode 100644 index d3cb291..0000000 --- a/speechAssets/CustomSlot.txt +++ /dev/null @@ -1,4 +0,0 @@ -melee -ranged -carry -support diff --git a/speechAssets/IntentSchema.json b/speechAssets/IntentSchema.json index 89f4b3e..01df2c2 100644 --- a/speechAssets/IntentSchema.json +++ b/speechAssets/IntentSchema.json @@ -2,23 +2,40 @@ "intents": [ { "intent": "RequestIntent", - "slot": [ + "slots": [ { - "name": "Category", - "type": "CustomSlot" + "name": "Role", + "type": "ROLE_TYPES" } ] }, { "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" } ] }, diff --git a/speechAssets/ROLE_TYPES.txt b/speechAssets/ROLE_TYPES.txt new file mode 100644 index 0000000..d209ce4 --- /dev/null +++ b/speechAssets/ROLE_TYPES.txt @@ -0,0 +1,10 @@ +melee +ranged +carry +support +strength +intelligence +agility +nuker +initiator +escape diff --git a/speechAssets/Utterances.txt b/speechAssets/Utterances.txt index 54b6861..771ff4a 100644 --- a/speechAssets/Utterances.txt +++ b/speechAssets/Utterances.txt @@ -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 other hero +AnyRequest random another +AnyRequest random another hero Stop stop diff --git a/src/index.js b/src/index.js index 1c33ce0..ee979bb 100644 --- a/src/index.js +++ b/src/index.js @@ -13,7 +13,7 @@ var handlers = { 'RequestIntent': function () { var given = [] - var category = this.event.request.intent.slots.Category + var category = this.event.request.intent.slots.Role.value.toString() given.push(category) randomHero(given, (name) => { @@ -23,8 +23,8 @@ var handlers = { 'RequestTwoIntent': function () { 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(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 () { var given = [] randomHero(given, (name) => { @@ -42,7 +56,7 @@ var handlers = { }, '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 () { @@ -56,6 +70,21 @@ function randomHero (categories, callback) { var location 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 { location = random(heroes.length) } while (!checkCategory(categories, heroes[location])) @@ -92,16 +121,14 @@ function random (size) { } function checkCategory (categories, hero) { - var i = 0 - 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 } else { 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 break } @@ -109,7 +136,6 @@ function checkCategory (categories, hero) { } if (hits) { - i++ hits = false } else { return false