-
Notifications
You must be signed in to change notification settings - Fork 7
Project w/ Tiffany #2
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
Open
ChaseFaggard
wants to merge
1
commit into
TalentPath:main
Choose a base branch
from
ChaseFaggard:work
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // Tiffany May-Phillips & Chase Faggard - Talent Path - Build-a-bot - 11/5/2021 | ||
|
|
||
| const { DbService } = require("m3o/db"); | ||
| const prompt = require("prompt-sync")(); | ||
|
|
||
| M3O_API_TOKEN = "ZTAyOWY3NDgtNGRjZS00MmRhLTg1ZWEtNDAxZDIzODU3OTg4"; | ||
|
|
||
| GARBAGE_WORDS = ['of', 'the', 'in', 'on', 'at', 'to', 'a', 'is', 'what\'s', 'whats', 'what', 'is', 'your', 'it', 'for', 'i', 'do', 'you']; | ||
|
|
||
| SUPERLATIVE_WORDS = ["Astounding", "Bedazzling", "Brilliant", "Breathtaking", "Classy", "Compelling", "Dazzling", "Elite", "Enriching", "Epic", "First-rate", "Gripping", "Groundbreaking", "Iconic", "Impeccable", "Insightful", "Inspired", "Laudable", "Legendary", "Luminous", "Masterful", "Notable", "Pioneering", "Rich", "Riveting", "Sensational", "Stellar", "Thought-Provoking", "Touching", "Transcendent", "Unforgettable", "Vibrant", "World class"]; | ||
|
|
||
| REMARK_WORDS = ["I don’t have the foggiest idea", "I haven’t a clue", "Who knows", "Don’t ask me", "Your guess is as good as mine", "Great question", "I’m not sure I’m the best person to answer that", "I don't know", "I'm not sure.."]; | ||
|
|
||
| BYE_WORDS = ["Bye bye", "See you later", "See you soon", "Talk to you later", "Take it easy", "Farewell. Someone is really going to miss you. Not me... someone.", "Goodbye, don't cry! We won't", "Sayonara", "Catch you later", "Toodle-oo", "Catch you later, alligator", "See you down the road, toad", "It won't be the same without you here, work may actually get done", "Hasta la vista", "Tata", "Bon voyage"]; | ||
|
|
||
| USER_PREFIX = "[You]:"; | ||
|
|
||
| BOT_PREFIX = "[Terra 2.0]:"; | ||
|
|
||
| const main = async () => { | ||
|
|
||
| console.log(BOT_PREFIX + " Hi there. I'm Terra 2.0. Ask me anything!"); | ||
|
Contributor
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. Loved the Terra 2.0 bot! lol |
||
| console.log(BOT_PREFIX + " If you start to get tired of me at anytime, please type exit."); | ||
|
|
||
| let keepGoing = true; | ||
|
|
||
| while(keepGoing) { | ||
| let question = prompt(USER_PREFIX + " "); | ||
| if(question.toLowerCase() === "exit") keepGoing = false; | ||
| else { | ||
| const record = await readRecords(sanitize(question)); | ||
|
|
||
| if(record.records[0] != undefined) console.log(BOT_PREFIX + " " + record.records[0].answer); | ||
| else { | ||
| let rand = getRandomInt(REMARK_WORDS.length); | ||
| console.log(`${BOT_PREFIX} ${REMARK_WORDS[rand]}. Will you please tell me?`); | ||
| let answer = prompt(USER_PREFIX + " "); | ||
| if(answer.toLowerCase() === "exit") keepGoing = false; | ||
| else { | ||
| const newRecord = await createRecord(sanitize(question), answer); | ||
| rand = getRandomInt(SUPERLATIVE_WORDS.length); | ||
| console.log(`${BOT_PREFIX} ${SUPERLATIVE_WORDS[rand]}! Any more questions?`); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| let rand = getRandomInt(BYE_WORDS.length); | ||
| console.log(BYE_WORDS[rand] + "!"); | ||
| } | ||
|
|
||
| const sanitize = (str) => { | ||
| let result = new RegExp('\\b(' + GARBAGE_WORDS.join('|') + ')\\b', 'g'); | ||
| return (str.toLowerCase() || '').replace(result, '').replace(/[ ]{2,}/, ' ').replace(/[^A-Za-z0-9\s]/g,"").replace(/\s{2,}/g, " ").replace(/\s/g, ''); | ||
| } | ||
|
|
||
| const createRecord = async (question, answer) => { | ||
|
Contributor
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. Nice use of DB to store info! |
||
| let dbService = new DbService(M3O_API_TOKEN); | ||
| let rsp = await dbService.create({ | ||
| record: { | ||
| "question": question, | ||
| "answer": answer | ||
| }, | ||
| table: "questionBank", | ||
| }); | ||
| return rsp.id; | ||
| } | ||
|
|
||
| const readRecords = async (question) => { | ||
| let dbService = new DbService(M3O_API_TOKEN); | ||
| let rsp = await dbService.read({ | ||
| query: `question == "${question}"`, | ||
| table: "questionBank" | ||
| }); | ||
| return rsp; | ||
| } | ||
|
|
||
| const getRandomInt = max => { | ||
| return Math.floor(Math.random() * max); | ||
| } | ||
|
|
||
| main(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "dependencies": { | ||
| "m3o": "^1.0.649", | ||
| "prompt-sync": "^4.2.0" | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Make sure you declare constants with the
constkeyword