From e9090dded3c478126731855c860bcd51f4a2910b Mon Sep 17 00:00:00 2001 From: Joseph Graham Date: Thu, 29 Aug 2013 22:19:31 +0100 Subject: made the code that unsets facts more robust --- hack_of_all_hacks | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/hack_of_all_hacks b/hack_of_all_hacks index 5ee621b..2f940dc 100644 --- a/hack_of_all_hacks +++ b/hack_of_all_hacks @@ -277,26 +277,40 @@ EOF thing="${thing%% isn\'t *}" isnt="${sentence#* isn\'t }" - if grep "${isnt}" "info/${thing}" >/dev/null - then - grep -v "${isnt}" "info/${thing}" | sponge "info/${thing}" - send_msg "${channel_it_came_from}" "${personoslash}: OK, entry removed." - else - send_msg "${channel_it_came_from}" "${personoslash}: I know." - fi + number_of_matching_lines=$(grep -c "^${isnt}" "info/${thing}") + + case "${number_of_matching_lines}" in + 0 ) + send_msg "${channel_it_came_from}" "${personoslash}: I know." + ;; + 1 ) + grep -v "${isnt}" "info/${thing}" | sponge "info/${thing}" + send_msg "${channel_it_came_from}" "${personoslash}: OK, entry removed." + ;; + * ) + send_msg "${channel_it_came_from}" "${personoslash}: Ambiguos." + ;; + esac ;; "${my_own_name}: "+([![:space:]])" isn't: "+([![:space:]])* ) declare -l thing="${sentence#${my_own_name}: }" thing="${thing%% isn\'t: *}" isnt="${sentence#* isn\'t: }" - if grep "${isnt}" "info/${thing}" >/dev/null - then - grep -v "${isnt}" "info/${thing}" | sponge "info/${thing}" - send_msg "${channel_it_came_from}" "${personoslash}: OK, entry removed." - else - send_msg "${channel_it_came_from}" "${personoslash}: I know." - fi + number_of_matching_lines=$(grep -c "^${isnt}" "info/${thing}") + + case "${number_of_matching_lines}" in + 0 ) + send_msg "${channel_it_came_from}" "${personoslash}: I know." + ;; + 1 ) + grep -v "${isnt}" "info/${thing}" | sponge "info/${thing}" + send_msg "${channel_it_came_from}" "${personoslash}: OK, entry removed." + ;; + * ) + send_msg "${channel_it_came_from}" "${personoslash}: Ambiguos." + ;; + esac ;; ','+([![:space:]]) ) thing="${sentence#,}" -- cgit v1.2.3