diff options
author | bill-auger <mr.j.spam.me@gmail.com> | 2018-09-08 10:27:56 +0000 |
---|---|---|
committer | bill-auger <mr.j.spam.me@gmail.com> | 2018-10-02 19:02:24 -0400 |
commit | 478bc51a173e13d49c296e4b5178abc8ad847594 (patch) | |
tree | 6a7fb69fc264bdbbd265fad549e94b7998406448 | |
parent | 63a28cc90bca774a51cd26ab531f43b14ede5739 (diff) |
implement factoids list command
-rw-r--r-- | process_event | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/process_event b/process_event index 0f62ed7..1526e1d 100644 --- a/process_event +++ b/process_event @@ -16,7 +16,7 @@ function format_cgit_title fi } -function tell_fact # thing channel +function tell_fact # (thing , channel) { thing="${1}" declare -l lower_case_thing="${thing}" @@ -24,17 +24,12 @@ function tell_fact # thing channel if [[ -s "info/${lower_case_thing}" ]] then - # For the first entry we will say like: `thing is: ' - first="${thing} is: " - - uniq "info/${lower_case_thing}" | while read line do - send_msg "${channel}" "${first}${line}" - first='' - done + send_msg "${channel}" "${thing} is: ${line}" + done < <(cat "info/${lower_case_thing}") - return + return 0 else return 1 fi @@ -367,6 +362,34 @@ function process_event # factoids # ############ + # list factoids + ',' | ',list' | ',factoids' | "${my_own_name}: list factoids" ) + local factoids=( $(ls info/) ) + local n_factoids=${#factoids[*]} + local begin_msg="ask me about:" + local end_msg="e.g. ${server_nick_current}: what is ${factoids[0]} (or ,${factoids[0]})" + + send_msg "${personoslash}" "${begin_msg}" + for (( factoid_n = 0 ; factoid_n < n_factoids ; factoid_n = factoid_n + 10 )) + do send_msg "${personoslash}" " ${factoids[*]:${factoid_n}:10}" + sleep 1 + done + send_msg "${personoslash}" "${end_msg}" + ;; + + # display factoid + ','+([!/]) ) + thing="${sentence#,}" + + tell_fact "${thing}" "${channel_it_came_from}" + ;; + "${my_own_name}: what is "+([![:space:]]) ) + thing="${sentence#${my_own_name}: what is }" + + tell_fact "${thing}" "${channel_it_came_from}" + ;; + + # set factoid "${my_own_name}: "+([!/])" is "+([![:space:]])* ) declare -l thing="${sentence#${my_own_name}: }" thing="${thing%% is *}" @@ -381,6 +404,8 @@ function process_event remember_fact ;; + + # delete factoid "${my_own_name}: "+([![:space:]])" isn't "+([![:space:]])* ) declare -l thing="${sentence#${my_own_name}: }" thing="${thing%% isn\'t *}" @@ -395,11 +420,6 @@ function process_event forget_fact ;; - ','+([!/]) ) - thing="${sentence#,}" - - tell_fact "${thing}" "${channel_it_came_from}" - ;; ############# |