diff options
-rw-r--r-- | hack_of_all_hacks | 42 |
1 files 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#,}" |