diff options
author | Joseph Graham <joseph@fibreglass.tunachunks> | 2013-08-29 22:19:31 +0100 |
---|---|---|
committer | Joseph Graham <joseph@fibreglass.tunachunks> | 2013-08-29 22:19:31 +0100 |
commit | e9090dded3c478126731855c860bcd51f4a2910b (patch) | |
tree | b5489d5dbcf8bd34a3371d561f9e044efe8b0ac5 | |
parent | 984a9c3bf8260440a9fd7c04e5a21cbd73c22f88 (diff) |
made the code that unsets facts more robust
-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#,}" |