Ver a proveniência

Refactored

pull/1/head
BinHong Lee há 7 anos
ascendente
cometimento
7b98452350
4 ficheiros alterados com 73 adições e 216 eliminações
  1. +4
    -0
      speechAssets/CustomSlot.txt
  2. +20
    -22
      speechAssets/IntentSchema.json
  3. +12
    -24
      speechAssets/Utterances.txt
  4. +37
    -170
      src/index.js

+ 4
- 0
speechAssets/CustomSlot.txt Ver ficheiro

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

+ 20
- 22
speechAssets/IntentSchema.json Ver ficheiro

@@ -1,28 +1,26 @@
{
"intents": [
{
"intent": "RequestMeleeCarry"
},
{
"intent": "RequestMeleeSupport"
},
{
"intent": "RequestRangedCarry"
},
{
"intent": "RequestRangedSupport"
},
{
"intent": "RequestCarry"
},
{
"intent": "RequestSupport"
},
{
"intent": "RequestMelee"
},
{
"intent": "RequestRanged"
"intent": "RequestIntent",
"slot": [
{
"name": "Category",
"type": "CustomSlot"
}
]
},
{
"intent": "RequestTwoIntent",
"slot": [
{
"name": "Category1",
"type": "CustomSlot"
},
{
"name": "Category2",
"type": "CustomSlot"
}
]
},
{
"intent": "AnyRequest"


+ 12
- 24
speechAssets/Utterances.txt Ver ficheiro

@@ -1,27 +1,15 @@
RequestMeleeCarry random melee carry
RequestMeleeCarry random another melee carry
RequestMeleeCarry random melee carry again
RequestRangedCarry random ranged carry
RequestRangedCarry random another ranged carry
RequestRangedCarry random ranged carry again
RequestMeleeSupport random melee support
RequestMeleeSupport random another melee support
RequestMeleeSupport random melee support again
RequestRangedSupport random ranged support
RequestRangedSupport random another ranged support
RequestRangedSupport random ranged support again
RequestCarry random carry
RequestCarry random another carry
RequestCarry random carry again
RequestSupport random support
RequestSupport random another support
RequestSupport random support again
RequestMelee random melee
RequestMelee random another melee
RequestMelee random melee again
RequestRanged random ranged
RequestRanged random another ranged
RequestRanged random ranged again
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
AnyRequest random any hero
AnyRequest random any other hero
Stop stop

+ 37
- 170
src/index.js Ver ficheiro

@@ -1,5 +1,4 @@
var Alexa = require('alexa-sdk')
var askingConditions = [3, 3, false, false, false, false, false, false, false, false, false]

exports.handler = function (event, context, callback) {
var alexa = Alexa.handler(event, context)
@@ -12,95 +11,40 @@ var handlers = {
this.emit(':ask', 'Welcome to Dota 2 Random. Say help for help.')
},

'RequestMeleeCarry': function () {
reset()
askingConditions[1] = 0
askingConditions[2] = true
getHero(askingConditions, (name) => {
this.emit(':tell', name)
// this.emit(':ask', 'RequestMeleeCarry')
})
},
'RequestIntent': function () {
var given = []
var category = this.event.request.intent.slots.Category
given.push(category)

'RequestMeleeSupport': function () {
reset()
askingConditions[1] = 0
askingConditions[3] = true
getHero(askingConditions, (name) => {
randomHero(given, (name) => {
this.emit(':tell', name)
// this.emit(':ask', 'RequestMeleeSupport')
})
},

'RequestRangedCarry': function () {
reset()
askingConditions[1] = 1
askingConditions[2] = true
getHero(askingConditions, (name) => {
this.emit(':tell', name)
// this.emit(':ask', 'RequestRangedCarry')
})
},
'RequestTwoIntent': function () {
var given = []
var category1 = this.event.request.intent.slots.Category1
var category2 = this.event.request.intent.slots.Category2
given.push(category1)
given.push(category2)

'RequestRangedSupport': function () {
reset()
askingConditions[1] = 1
askingConditions[3] = true
getHero(askingConditions, (name) => {
randomHero(given, (name) => {
this.emit(':tell', name)
// this.emit(':ask', 'RequestRangedSupport')
})
},

'RequestCarry': function () {
reset()
askingConditions[2] = true
getHero(askingConditions, (name) => {
this.emit(':tell', name)
// this.emit(':ask', 'RequestCarry')
})
},

'RequestSupport': function () {
reset()
askingConditions[3] = true
getHero(askingConditions, (name) => {
this.emit(':tell', name)
// this.emit(':ask', 'RequestSupport')
})
},

'RequestMelee': function () {
reset()
askingConditions[1] = 0
getHero(askingConditions, (name) => {
this.emit(':tell', name)
// this.emit(':ask', 'RequestMelee')
})
},

'RequestRanged': function () {
reset()
askingConditions[1] = 1
getHero(askingConditions, (name) => {
'AnyRequest': function () {
var given = []
randomHero(given, (name) => {
this.emit(':tell', name)
// this.emit(':ask', 'RequestRanged')
// this.emit(':ask', 'AnyRequest triggered')
})
},

'AMAZON.HelpIntent': function () {
reset()
this.emit(':ask', 'You can try saying random any hero, random melee carry or random ranged support for more specific randoming.')
},

'AnyRequest': function () {
reset()
getHero(askingConditions, (name) => {
this.emit(':tell', name)
// this.emit(':ask', 'AnyRequest triggered')
})
},

'Stop': function () {
this.emit(':tell', 'Enjoy the game!')
}
@@ -108,18 +52,16 @@ var handlers = {

var https = require('https')

function getHero (conditions, callback) {
function randomHero (categories, callback) {
var location

httpsGet((heroes) => {
do {
location = random(heroes.length)
} while (!checkConditions(conditions, heroes[location]))
} while (!checkCategory(categories, heroes[location]))

callback(heroes[location].localized_name)
// callback(heroes[location].attack_type + ': ' + heroes[location].localized_name)
}
)
})
}

function httpsGet (callback) {
@@ -149,105 +91,30 @@ function random (size) {
return Math.floor(Math.random() * (size))
}

function checkConditions (conditions, hero) {
if (!checkType(conditions[0], hero.primary_attr)) {
return false
}
function checkCategory (categories, hero) {
var i = 0

if (!checkAttackType(conditions[1], hero.attack_type)) {
return false
}

var allConditions = []

// carry
if (conditions[2]) {
allConditions.push('Carry')
}
// support
if (conditions[3]) {
allConditions.push('Support')
}
// jungler
if (conditions[4]) {
allConditions.push('Jungler')
}
// escape
if (conditions[5]) {
allConditions.push('Escape')
}
// nuker
if (conditions[6]) {
allConditions.push('Nuker')
}
// durable
if (conditions[7]) {
allConditions.push('Durable')
}
// disabler
if (conditions[8]) {
allConditions.push('Disabler')
}
// initiator
if (conditions[9]) {
allConditions.push('Initiator')
}
// pusher
if (conditions[10]) {
allConditions.push('Pusher')
}

if (allConditions.length > 0 && !checkRoles(allConditions, hero.roles)) {
return false
}
var hits = false

return true
}

function checkType (type, toCheck) {
switch (type) {
case 0:
return (toCheck === 'str')
case 1:
return (toCheck === 'agi')
case 2:
return (toCheck === 'int')
default:
return true
}
}

function checkAttackType (atype, toCheck) {
switch (atype) {
case 0:
return (toCheck.localeCompare('Melee') === 0)
case 1:
return (toCheck.localeCompare('Ranged') === 0)
default:
return true
}
}

function checkRoles (roles, toCheck) {
var match = true

for (var i = 0; i < roles.length; i++) {
var thisCondition = false

for (var j = 0; j < toCheck.length; j++) {
if (roles[i].localeCompare(toCheck[j]) === 0) {
thisCondition = true
while (i < categories.length) {
if (categories[i] === hero.primary_attr || categories[i] === hero.attack_type) {
hits = true
} else {
for (var j = 0; j < hero.roles.length; j++) {
if (categories[i] === hero.roles[j]) {
hits = true
break
}
}
}

if (!thisCondition) {
match = false
if (hits) {
i++
hits = false
} else {
return false
}
}

return match
}

function reset () {
askingConditions = [3, 3, false, false, false, false, false, false, false, false, false]
return true
}

Carregando…
Cancelar
Guardar