Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Version 1.1

- Added some basic macro functionality, you can now use $TIME$, $DAY$, $WEEKDAY$, $MONTH$, and $YEAR$ to refer to the current time/date while speaking. Check the README for details.
- Fixed a potential crash-prone spot in one of the functions.
  • Loading branch information...
commit 433c98e0c4eed13a4e80b55eef38dff3e1b16268 1 parent 3062695
Michael Kamensky authored committed
Showing with 46 additions and 7 deletions.
  1. +13 −0 README.orig
  2. +33 −7 plugin/VimChatBot.vim
View
13 README.orig
@@ -45,6 +45,19 @@ change the mapping to another combination of keys).
Alternatively, you can start Vim ChatBot by typing the following command:
:call MainChatLoop()
+Macros
+======
+
+You can use the following macros when typing answers, the bot will also utilize them
+when learning to use the phrase from you:
+
+$TIME$ - refers to the current time.
+$TIME12$ - (experimental) refers to the current time in 12-hour format.
+$DAY$ - refers to the current day.
+$WEEKDAY$ - refers to the current day of the week.
+$MONTH$ - refers to the current month.
+$YEAR$ - refers to the current year.
+
Finishing the conversation
==========================
View
40 plugin/VimChatBot.vim
@@ -4,7 +4,7 @@
let s:ChatIteration = 1
let s:MagicalContexts = 2
-let s:BotVersion = "1.0"
+let s:BotVersion = "1.1"
function! Random(min, max)
if has("python")
@@ -19,6 +19,16 @@ function! Random(min, max)
endif
endfunction
+function! Macroexpand(phrase)
+ let s:expanded_phrase = substitute(a:phrase, "\\$TIME\\$", strftime("%H:%M"), "g")
+ let s:expanded_phrase = substitute(s:expanded_phrase, "\\$TIME12\\$", strftime("%I:%M %p"), "g")
+ let s:expanded_phrase = substitute(s:expanded_phrase, "\\$WEEKDAY\\$", strftime("%A"), "g")
+ let s:expanded_phrase = substitute(s:expanded_phrase, "\\$DAY\\$", strftime("%d"), "g")
+ let s:expanded_phrase = substitute(s:expanded_phrase, "\\$MONTH\\$", strftime("%B"), "g")
+ let s:expanded_phrase = substitute(s:expanded_phrase, "\\$YEAR\\$", strftime("%Y"), "g")
+ return s:expanded_phrase
+endfunction
+
function! GetLineMatchingPattern(pattern)
let s:num_line = 1
let s:max_line = line("$")
@@ -107,6 +117,7 @@ function! AI_Store_New_Response(pattern, response, iteration)
execute ("normal o" . a:pattern . ":::")
endif
execute ("normal o" . a:response)
+ execute ("normal o")
endfunction
function! AI_Respond(pattern, iteration)
@@ -131,7 +142,7 @@ function! AI_Respond(pattern, iteration)
let s:request_signature = ":::"
endif
if s:chosen_response != -1
- echo "ChatBot: " . getline(s:chosen_response) . "\n"
+ echo "ChatBot: " . Macroexpand(getline(s:chosen_response)) . "\n"
else
echohl Comment
echo "ChatBot: I don't understand that. Can you please teach me what to say?\n"
@@ -143,7 +154,7 @@ function! AI_Respond(pattern, iteration)
echohl N
return
endif
- echo "Human: " . s:suggested_response . "\n"
+ echo "Human: " . Macroexpand(s:suggested_response) . "\n"
call AI_Store_New_Response(a:pattern, s:suggested_response, a:iteration)
echohl Comment
echo "ChatBot: Thanks, I'll remember that!\n"
@@ -155,7 +166,7 @@ function! AI_Respond(pattern, iteration)
let s:requests = filter(s:lines, s:next_request)
if len(s:requests) != 0
let s:decision = Random(0, len(s:requests) - 1)
- echo "ChatBot: " . s:requests[s:decision][:-s:resp_offset] . "\n"
+ echo "ChatBot: " . Macroexpand(s:requests[s:decision][:-s:resp_offset]) . "\n"
let s:taught_response = input("You say: ")
if s:taught_response == "/Q" || s:taught_response =~ "^\\s*$"
echohl Comment
@@ -163,7 +174,7 @@ function! AI_Respond(pattern, iteration)
echohl None
return
endif
- echo "Human: " . s:taught_response . "\n"
+ echo "Human: " . Macroexpand(s:taught_response) . "\n"
let s:response_group_loc = GetLineMatchingPattern(s:requests[s:decision][:-s:resp_offset] . s:request_signature)
let s:already_has_resp = HasResponse(s:response_group_loc, s:taught_response)
if s:already_has_resp != 1
@@ -193,7 +204,7 @@ function! MainChatLoop()
echo "ChatBot: Bye-bye!\n"
break
endif
- echo "Human: " . s:HumanResponse . "\n"
+ echo "Human: " . Macroexpand(s:HumanResponse) . "\n"
call AI_Respond(s:HumanResponse, s:ChatIteration)
let s:ChatIteration += 1
endwhile
@@ -217,6 +228,7 @@ Not a whole lot!
Not much!
How's it going?:::1
+Doing good, thanks!
Good, thanks!
Are you a robot?:::2
@@ -233,13 +245,14 @@ No...
No
What about you?:::
-Same! :)
+Same!
Doing good, thanks!
Are you a robot?:::
No, of course not!
Should I work today?:::
+No, you shouldn't.
Probably :P
Yes, of course!
I don't know, to be honest.
@@ -248,14 +261,27 @@ What's new?:::2
Not a whole lot!
What's new?:::1
+Not much, what about you?
Not much!
What are you doing?:::2
Talking to you!
Are you an alien?:::
+No.
+Yes, sure!
Yes, yes I am.
You could say so.
What about you?:::2
+Doing good!
I'm great, thanks!
+
+
+What time is it?:::
+It's $TIME$.
+
+
+What day of the week is it?:::
+It's $WEEKDAY$!
+
Please sign in to comment.
Something went wrong with that request. Please try again.