123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- class Conversation {
- constructor() {
- this.simple = [
- {
- "trigger": ["hello", "hey", "hi"],
- "response": ["say Hello {source.name}", "say hi {source.name}", "say hello", "say hey", "say hi", "emote waves.", "emote smiles."]
- },
- {
- "trigger": ["help", "oh no", "oops"],
- "response": ["say Are you ok, {source.name}?", "say What's wrong?", "say How can I help?"]
- },
- {
- "trigger": ["whats your name", "who are you"],
- "response": ["say I'm {listener.name}", "say {listener.name}", "say Oh! It's {listener.name}!", "say Me?"]
- },
- {
- "trigger": ["how are you", "you ok"],
- "response": ["say I'm fine", "say Pretty good", "say peachy", "say ehh", "say I'm good. How are you, {source.name}?"]
- },
- {
- "trigger": ["whats up", "whats wrong"],
- "response": ["say Not much", "say nothing", "say Everything is great", "say ehh"]
- },
- {
- "trigger": ["bye", "goodbye", "good bye", "see you"],
- "response": ["say Bye!", "say Goodbye {source.name}", "say It was a pleasure talking to you.", "emote waves."]
- },
- {
- "trigger": ["good luck"],
- "response": ["say Thanks."]
- },
- {
- "trigger": ["thanks", "thank you"],
- "response": ["say You're welcome!", "say No problem.", "say The pleasure was mine."]
- },
- {
- "trigger": ["how do you know"],
- "response": ["say Lucky guess, I guess", "emote shrugs."]
- },
- {
- "trigger": ["do you know", "who i am"],
- "response": ["say You're kinda famous, {source.name}. I imagine everyone knows you.", "say I mean, you are {source.name}, right?", "say You're {source.name}."]
- },
- {
- "trigger": ["i like you", "youre great", "your great"],
- "response": ["say Aww.", "say I like you too!", "say That's nice of you to say."]
- },
- ];
- this.orders = [
- {
- "trigger": ["go east"],
- "response": ["east"]
- },
- {
- "trigger": ["go west"],
- "response": ["west"]
- },
- {
- "trigger": ["go north"],
- "response": ["north"]
- },
- {
- "trigger": ["go south"],
- "response": ["south"]
- },
- {
- "trigger": ["go northwest"],
- "response": ["nw"]
- },
- {
- "trigger": ["go northeast"],
- "response": ["ne"]
- },
- {
- "trigger": ["go southwest"],
- "response": ["sw"]
- },
- {
- "trigger": ["go southeast"],
- "response": ["se"]
- },
- {
- "trigger": ["go up"],
- "response": ["up"]
- },
- {
- "trigger": ["go down"],
- "response": ["down"]
- },
- {
- "trigger": ["enter"],
- "response": ["enter"]
- },
- {
- "trigger": ["leave"],
- "response": ["leave"]
- },
- {
- "trigger": ["inventory"],
- "response": ["inventory"]
- },
- ];
- }
- basicDecency(source, message, listener) {
- return this.mobileInstructionRules(source, message, listener, this.simple);
- }
- followsOrders(source, message, listener) {
- return this.mobileInstructionRules(source, message, listener, this.orders);
- }
- mobileInstructionRules(source, message, listener, instructionset) {
- if(source == null) {
- return false;
- }
- if(message.indexOf("shout") != -1) {
- return false;
- }
- for(var i = 0; i < instructionset.length; i++) {
- var response = this.triggerResponse(
- instructionset[i].trigger,
- instructionset[i].response,
- message
- );
- if(response != null) {
- var cleanResponse = this.parsedResponse(response, source, listener, message);
- if(typeof listener['mud_addCommand'] == 'function') {
- listener.mud_addCommand(listener, cleanResponse);
- return true;
- }
- return true;
- }
- }
- return false;
- }
- parsedResponse(response, source, listener) {
- response = response.replace("{source.name}", source.name);
- response = response.replace("{listener.name}", listener.name);
- return response;
- }
- triggerResponse(triggers, responses, message) {
- if(this.contains(triggers, message)) {
- return this.random(responses);
- }
- }
- random(responses) {
- var index = parseInt(Math.random() * responses.length);
- return responses[index];
- }
- contains(keys, message) {
- var cleanMessage = message.replace(/'/g, "");
- for(var i = 0; i < keys.length; i++) {
- var regex = new RegExp("\\b" + keys[i] + "\\b", "i");
- if(cleanMessage.search(regex) != -1) {
- return true;
- }
- }
- return false;
- }
- }
- module.exports = new Conversation();
|