-
Notifications
You must be signed in to change notification settings - Fork 17
updates key_script to store 5 key_holder(colorwise) #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
060cc55
f72ee0e
9aed8d7
253da75
2e01bef
bc58f2e
3fb6519
04cd5fa
34549ef
f519331
ca3d71d
72781de
68f9b72
880d7aa
0aa2d0f
6e98819
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,95 +10,309 @@ | |
# bot xyz has keys : sets xyz as the holder of keys | ||
# | ||
# Examples: | ||
# :bot who has keys | ||
# :bot i have keys | ||
# :bot i dont have keys | ||
# :bot who has keys | ||
# :bot ravi has keys | ||
# :bot who has <color> keys | ||
# :bot i have <color> keys | ||
# :bot i dont have <color> keys | ||
# :bot who has <color> keys | ||
# :bot ravi has <color> keys | ||
# | ||
# Author: | ||
# Punit Dhoot (@pdhoot) | ||
# Developer at SDSLabs (@sdslabs) | ||
# Developer at SDSLabs (@sdslabs | ||
# Edit: | ||
# prakhar gupta | ||
|
||
|
||
module.exports = (robot)-> | ||
|
||
key = ()-> | ||
Key = robot.brain.get("key") or "" | ||
robot.brain.set("key" ,Key) | ||
Key | ||
keyRed = ()-> | ||
Key1 = robot.brain.get("keyRed") or "" | ||
robot.brain.set("keyRed",Key1) | ||
Key1 | ||
keyBlue = ()-> | ||
Key1 = robot.brain.get("keyBlue") or "" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be Key2? @Arnesh07 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Corrected |
||
robot.brain.set("keyBlue",Key2) | ||
Key2 | ||
aseem09 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
keyYellow = ()-> | ||
Key1 = robot.brain.get("keyYellow") or "" | ||
robot.brain.set("keyYellow",Key3) | ||
Key3 | ||
keyGreen = ()-> | ||
Key1 = robot.brain.get("keyGreen") or "" | ||
robot.brain.set("keyGreen",Key4) | ||
Key4 | ||
keyOrange = ()-> | ||
Key1 = robot.brain.get("keyOrange") or "" | ||
robot.brain.set("keyOrange",Key5) | ||
Key5 | ||
|
||
|
||
robot.respond /i have (a key|the key|key|keys)/i, (msg)-> | ||
#1this section belongs to "i have keys" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aseem09 done |
||
robot.respond /i (have the|have) (.+) (key|keys)/i, (msg)-> | ||
keyname = msg.match[2] | ||
name = msg.message.user.name | ||
user = robot.brain.userForName name | ||
k = key() | ||
if typeof user is 'object' | ||
msg.send "Okay #{name} has keys" | ||
k = user.name | ||
robot.brain.set("key",k) | ||
|
||
unless keyname not in ["red", "blue", "yellow", "green", "orange"] | ||
if keyname is 'red' | ||
key_holder = keyRed() | ||
key_holder = user.name | ||
robot.brain.set("keyRed",key_holder) | ||
else if keyname is 'blue' | ||
key_holder = keyBlue() | ||
key_holder = user.name | ||
robot.brain.set("keyBlue",key_holder) | ||
else if keyname is 'Yellow' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
key_holder = keyYellow() | ||
key_holder = user.name | ||
robot.brain.set("keyYellow",key_holder) | ||
else if keyname is 'Green' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. corrected |
||
key_holder = keyGreen() | ||
key_holder = user.name | ||
robot.brain.set("keyGreen",key_holder) | ||
else if keyname is 'orange' | ||
key_holder = keyOrange() | ||
key_holder = user.name | ||
robot.brain.set("keyOrange",key_holder) | ||
if typeof user is 'object' | ||
msg.send "Okay #{name} has #{keyname} keys" | ||
|
||
robot.respond /i (don\'t|dont|do not) (has|have) (the key|key|keys|a key)/i , (msg)-> | ||
#2this section belongs to "i dont have key" | ||
Arnesh07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
robot.respond /i (do not|don\'t|dont) (has the|have the|has|have) (key|keys)/i , (msg)-> | ||
name = msg.message.user.name | ||
user = robot.brain.userForName name | ||
k = key() | ||
if k is name | ||
k = "" | ||
if typeof user is 'object' | ||
if k is "" | ||
msg.send "Okay #{name} doesn't have keys. Who got the keys then?" | ||
else | ||
msg.send "Yes , i know buddy, its because #{k} has got the keys" | ||
robot.brain.set("key",k) | ||
|
||
key_holder1 = keyRed() | ||
key_holder2 = keyBlue() | ||
key_holder3 = keyYellow() | ||
key_holder4 = keyGreen() | ||
key_holder5 = keyOrange() | ||
if name is key_holder1 | ||
key_holder1 = "" | ||
robot.brain.set("keyRed",key_holder1) | ||
msg.send "Okay #{name} doesn't have Red keys. Who got the Red keys then?" | ||
else if name is key_holder2 | ||
key_holder2 = "" | ||
robot.brain.set("keyBlue",key_holder2) | ||
msg.send "Okay #{name} doesn't have Blue keys. Who got the Blue keys then?" | ||
else if name is key_holder3 | ||
key_holder3 = "" | ||
robot.brain.set("keyYellow",key_holder3) | ||
msg.send "Okay #{name} doesn't have Yellow keys. Who got the Yellow keys then?" | ||
else if name is key_holder4 | ||
key_holder4 = "" | ||
robot.brain.set("keyGreen",key_holder4) | ||
msg.send "Okay #{name} doesn't have Green keys. Who got the green keys then?" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a few letter case issues in the code. I am not going to pin point all of them. Go through the code once. |
||
else if name is key_holder5 | ||
key_holder5 = "" | ||
robot.brain.set("keyOrange",key_holder5) | ||
msg.send "Okay #{name} doesn't have orange keys. Who got the orange keys then?" | ||
else if typeof user is 'object' | ||
if key_holder1 is not "" | ||
msg.send "Yes , I know buddy, its because #{key_holder1} has got the Red keys\n" | ||
if key_holder2 is not "" | ||
msg.send "Yes , I know buddy, its because #{key_holder2} has got the Blue keys\n" | ||
if key_holder3 is not "" | ||
msg.send "Yes , I know buddy, its because #{key_holder3} has got the yellow keys\n" | ||
if key_holder4 is not "" | ||
msg.send "Yes , I know buddy, its because #{key_holder4} has got the green keys\n" | ||
if key_holder5 is not "" | ||
msg.send "Yes , I know buddy, its because #{key_holder5} has got the orange keys\n" | ||
|
||
robot.respond /(.+) (has|have) (the key|key|keys|a key)/i , (msg)-> | ||
#3this section belongs to "$name has keys" | ||
robot.respond /(.+) (has the|have the|has|have) (.+) (key|keys)/i , (msg)-> | ||
othername = msg.match[1] | ||
keyname = msg.match[3] | ||
name = msg.message.user.name | ||
k = key() | ||
unless othername in ["who", "who all","Who", "Who all" , "i" , "I" , "i don't" , "i dont" , "i do not" , "I don't" , "I dont" , "I do not"] | ||
if othername is 'you' | ||
msg.send "How am I supposed to take those keys? #{name} is a liar!" | ||
else if othername is robot.name | ||
msg.send "How am I supposed to take those keys? #{name} is a liar!" | ||
else | ||
users = robot.brain.usersForFuzzyName othername | ||
if users.length is 1 | ||
robot.brain.set "key", users[0].name | ||
msg.send "Okay, so now the keys are with #{users[0].name}" | ||
else if users.length > 1 | ||
msg.send getAmbiguousUserText users | ||
unless keyname not in ["red", "blue", "yellow", "green", "orange"] | ||
users = robot.brain.userForName othername | ||
if users is null | ||
key_holder = null | ||
else | ||
msg.send "#{othername}? Never heard of 'em" | ||
|
||
robot.respond /(i|I) (have given|gave|had given) (the key|key|keys|a key|the keys) to (.+)/i , (msg)-> | ||
key_holder = users.name | ||
if key_holder is null | ||
if othername is 'you' | ||
msg.send "How am I supposed to take those #{keyname} keys? #{name} is a liar!" | ||
else if othername is robot.name | ||
msg.send "That's utter lies! How can you blame a bot to have the keys?" | ||
else | ||
msg.send "I don't know anyone by the name #{othername}" | ||
else | ||
if keyname is 'red' | ||
robot.brain.set("keyRed",key_holder) | ||
else if keyname is 'blue' | ||
robot.brain.set("keyBlue",key_holder) | ||
else if keyname is 'yellow' | ||
robot.brain.set("keyYellow",key_holder) | ||
else if keyname is 'green' | ||
robot.brain.set("keyGreen",key_holder) | ||
else if keyname is 'orange' | ||
robot.brain.set("keyOrange",key_holder) | ||
msg.send "Okay, so now the #{keyname} keys are with #{othername}" | ||
#4this section belongs to "i gave the keys to $name" | ||
Arnesh07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
robot.respond /(i|I) (have given the|had given the|have given|gave the|had given|gave) (key|keys) to (.+)/i , (msg)-> | ||
othername = msg.match[4] | ||
name = msg.message.user.name | ||
k = key() | ||
if othername is 'you' | ||
msg.send "That's utter lies! How can you blame a bot to have the keys?" | ||
else if othername is robot.name | ||
msg.send "That's utter lies! How can you blame a bot to have the keys?" | ||
else | ||
users = robot.brain.userForName othername | ||
key_holder1 = keyRed() | ||
key_holder2 = keyBlue() | ||
key_holder3 = keyYellow() | ||
key_holder4 = keyGreen() | ||
key_holder5 = keyOrange() | ||
keyname="" | ||
users = robot.brain.userForName othername | ||
if name is key_holder1 | ||
if users is null | ||
msg.send "I don't know anyone by the name #{othername}" | ||
key_holder1 = null | ||
robot.brain.set("keyRed",key_holder1) | ||
keyname="Red" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make it a habit of adding a space on both the sides of an operator. eg the |
||
else | ||
k = users.name | ||
msg.send "Okay, so now the keys are with #{users.name}" | ||
|
||
robot.brain.set("key",k) | ||
|
||
robot.respond /(who|who all) (has|have) (the key|key|keys|a key)/i , (msg)-> | ||
k = key() | ||
msgText = k | ||
key_holder1 = users.name | ||
robot.brain.set("keyRed",key_holder1) | ||
keyname="Red" | ||
else if name is key_holder2 | ||
if users is null | ||
key_holder2 = null | ||
robot.brain.set("keyBlue",key_holder2) | ||
keyname="Blue" | ||
else | ||
key_holder2 = users.name | ||
robot.brain.set("keyBlue",key_holder2) | ||
keyname="Blue" | ||
else if name is key_holder3 | ||
if users is null | ||
key_holder3 = null | ||
robot.brain.set("keyYellow",key_holder3) | ||
keyname="yellow" | ||
else | ||
key_holder3 = users.name | ||
robot.brain.set("keyYellow",key_holder3) | ||
keyname="yellow" | ||
else if name is key_holder4 | ||
if users is null | ||
key_holder4 = null | ||
robot.brain.set("keyGreen",key_holder4) | ||
keyname="green" | ||
else | ||
key_holder4 = users.name | ||
robot.brain.set("keyGreen",key_holder4) | ||
keyname="green" | ||
else if name is key_holder5 | ||
if users is null | ||
key_holder5 = null | ||
robot.brain.set("keyOrange",key_holder5) | ||
keyname="orange" | ||
else | ||
key_holder5 = users.name | ||
robot.brain.set("keyOrange",key_holder5) | ||
keyname="orange" | ||
if key_holder1 is null or key_holder2 is null or key_holder3 is null or key_holder4 is null or key_holder5 is null | ||
if othername is 'you' | ||
msg.send "That's utter lies! How can you blame a bot to have the keys? #{name} is a liar!" | ||
else if othername is robot.name | ||
msg.send "That's utter lies! How can you blame a bot to have the keys?" | ||
else | ||
msg.send "I don't know anyone by the name #{othername}" | ||
robot.brain.set("keyOrange",key_holder5) | ||
else | ||
msg.send "Okay, so now the #{keyname} keys are with #{users.name}" | ||
#5this section is for commands -> {i} dont have the keys | ||
robot.respond /(.+) (do not|don\'t|dont) (has the|have the|has|have) (key|keys)/i , (msg)-> | ||
othername = msg.match[1] | ||
key_holder1 = keyRed() | ||
key_holder2 = keyBlue() | ||
key_holder3 = keyYellow() | ||
key_holder4 = keyGreen() | ||
key_holder5 = keyOrange() | ||
if othername is key_holder1 | ||
robot.brain.set("keyRed" ,key_holder1) | ||
msg.send "Okay, so now the Red keys are with #{othername}" | ||
else if othername is key_holder2 | ||
robot.brain.set("keyBlue" ,key_holder1) | ||
msg.send "Okay, so now the Blue keys are with #{othername}" | ||
else if othername is key_holder3 | ||
robot.brain.set("keyYellow" ,key_holder1) | ||
msg.send "Okay, so now the yellow keys are with #{othername}" | ||
else if othername is key_holder4 | ||
robot.brain.set("keyGreen" ,key_holder1) | ||
msg.send "Okay, so now the green keys are with #{othername}" | ||
else if othername is key_holder5 | ||
robot.brain.set("keyOrange" ,key_holder1) | ||
msg.send "Okay, so now the orange keys are with #{othername}" | ||
#6this section is to print the details about the key holder. | ||
robot.respond /who (has the|have the|has|have) (.+) (key|keys)/i , (msg)-> | ||
keyname = msg.match[2] | ||
if keyname is 'red' | ||
key_holder = keyRed() | ||
msgText = key_holder | ||
if msgText is "" | ||
msg.send "Ah! Nobody informed me about the keys. Don't hold me responsible for this :expressionless:" | ||
else | ||
msgText+=" has red keys" | ||
msg.send msgText | ||
robot.brain.set("keyRed" ,key_holder) | ||
else if keyname is 'blue' | ||
key_holder = keyBlue() | ||
msgText = key_holder | ||
if msgText is "" | ||
msg.send "Ah! Nobody informed me about the keys. Don't hold me responsible for this :expressionless:" | ||
else | ||
msgText+=" has blue keys" | ||
msg.send msgText | ||
robot.brain.set("keyBlue" ,key_holder) | ||
else if keyname is 'yellow' | ||
key_holder = keyYellow() | ||
msgText = key_holder | ||
if msgText is "" | ||
msg.send "Ah! Nobody informed me about the keys. Don't hold me responsible for this :expressionless:" | ||
else | ||
msgText+=" has yellow keys" | ||
msg.send msgText | ||
robot.brain.set("keyYellow" ,key_holder) | ||
else if keyname is 'green' | ||
key_holder = keyGreen() | ||
msgText = key_holder | ||
if msgText is "" | ||
msg.send "Ah! Nobody informed me about the keys. Don't hold me responsible for this :expressionless:" | ||
else | ||
msgText+=" has green keys" | ||
msg.send msgText | ||
robot.brain.set("keyGreen" ,key_holder) | ||
else if keyname is 'orange' | ||
key_holder = keyOrange() | ||
msgText = key_holder | ||
if msgText is "" | ||
msg.send "Ah! Nobody informed me about the keys. Don't hold me responsible for this :expressionless:" | ||
else | ||
msgText+=" has orange keys" | ||
msg.send msgText | ||
robot.brain.set("keyOrange" ,key_holder) | ||
robot.respond /who (has the|have the|has|have) (key|keys)/i , (msg)-> | ||
key_holder1 = keyRed() | ||
key_holder2 = keyBlue() | ||
key_holder3 = keyYellow() | ||
key_holder4 = keyGreen() | ||
key_holder5 = keyOrange() | ||
msgText="" | ||
if key_holder1 != "" | ||
msgText+=key_holder1 | ||
msgText+=" has red keys.\n" | ||
if key_holder2 != "" | ||
msgText+=key_holder2 | ||
msgText+=" has blue keys.\n" | ||
if key_holder3 != "" | ||
msgText+=key_holder3 | ||
msgText+=" has yellow keys.\n" | ||
if key_holder4 != "" | ||
msgText+=key_holder3 | ||
msgText+=" has green keys.\n" | ||
if key_holder5 != "" | ||
msgText+=key_holder3 | ||
msgText+=" has orange keys.\n" | ||
if msgText is "" | ||
msg.send "Ah! Nobody informed me about the keys. Don't hold me responsible for this :expressionless:" | ||
msg.send "Ah! Nobody informed me about any keys. Don't hold me responsible for this :expressionless:" | ||
else | ||
msgText+=" has keys" | ||
msg.send msgText | ||
robot.brain.set("key" ,k) | ||
|
||
getAmbiguousUserText = (users) -> | ||
"Be more specific, I know #{users.length} people named like that: #{(user.name for user in users).join(", ")}" | ||
|
||
msg.send msgText | ||
robot.brain.set("keyRed" ,key_holder1) | ||
robot.brain.set("keyBlue" ,key_holder2) | ||
robot.brain.set("keyYellow" ,key_holder3) | ||
robot.brain.set("keyGreen" ,key_holder2) | ||
robot.brain.set("keyOrange" ,key_holder2) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a good practice to write the name in capitals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok