Browse Source

Merge pull request #1 from binhonglee/production

Certification approved
master
BinHong Lee 7 years ago
committed by GitHub
parent
commit
9d0492d1a7
6 changed files with 124 additions and 34 deletions
  1. +33
    -0
      README.md
  2. +0
    -4
      speechAssets/CustomSlot.txt
  3. +25
    -8
      speechAssets/IntentSchema.json
  4. +10
    -0
      speechAssets/ROLE_TYPES.txt
  5. +20
    -12
      speechAssets/Utterances.txt
  6. +36
    -10
      src/index.js

+ 33
- 0
README.md View File

@@ -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

+ 0
- 4
speechAssets/CustomSlot.txt View File

@@ -1,4 +0,0 @@
melee
ranged
carry
support

+ 25
- 8
speechAssets/IntentSchema.json View File

@@ -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"
}
]
},


+ 10
- 0
speechAssets/ROLE_TYPES.txt View File

@@ -0,0 +1,10 @@
melee
ranged
carry
support
strength
intelligence
agility
nuker
initiator
escape

+ 20
- 12
speechAssets/Utterances.txt View File

@@ -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

+ 36
- 10
src/index.js View File

@@ -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


Loading…
Cancel
Save