irctk

libircclient binding for scripts
git clone https://a3nm.net/git/irctk/
Log | Files | Refs | README

1events.sh (3174B)


      1 #!/bin/bash
      2 
      3 trap 'kill $(jobs -p)' EXIT
      4 
      5 mkdir -p events
      6 cd events
      7 
      8 cat >tosay <<EOF
      9 /join #events_test2
     10 [#events_test1] /nick eventsop2
     11 /mode +n
     12 /mode -n
     13 /part
     14 [#events_test1,#events_test2] /topic mytopic
     15 [#events_test2] /invite eventsc
     16 [#events_test2] /kick eventsc kickarg
     17 /say hello
     18 /me blah
     19 / /hello2
     20 /quit
     21 EOF
     22 cat > ref_message <<EOF
     23 [#events_test1] -!- eventsm has joined #events_test1
     24 [#events_test2] -!- eventsm has joined #events_test2
     25 [#events_test1] -!- eventsc has joined #events_test1
     26 [#events_test2] -!- eventsc has joined #events_test2
     27 [#events_test1] -!- eventsn has joined #events_test1
     28 [#events_test2] -!- eventsn has joined #events_test2
     29 [#events_test1] -!- eventsu has joined #events_test1
     30 [#events_test2] -!- eventsu has joined #events_test2
     31 [#events_test1] <eventsu> /join #events_wrong
     32 [] -!- eventsop is now known as eventsop2
     33 [#events_test1] -!- eventsop2 mode +n on #events_test1
     34 [#events_test1] -!- eventsop2 mode -n on #events_test1
     35 [#events_test1] -!- eventsop2 has left #events_test1
     36 [#events_test2] -!- eventsop2 changed the topic of #events_test2 to mytopic
     37 [#events_test2] -!- eventsc was kicked from #events_test2 by eventsop2 (kickarg)
     38 [#events_test2] <eventsop2> hello
     39 [#events_test2] *** eventsop2 blah
     40 [#events_test2] <eventsop2> /hello2
     41 [] -!- eventsop2 has quit
     42 EOF
     43 cat > ref_command <<EOF
     44 [#events_test1] <eventsc> /join #events_test1
     45 [#events_test2] <eventsc> /join #events_test2
     46 [#events_test1] <eventsn> /join #events_test1
     47 [#events_test2] <eventsn> /join #events_test2
     48 [#events_test1] <eventsu> /join #events_test1
     49 [#events_test2] <eventsu> /join #events_test2
     50 [#events_test1] <eventsu> / /join #events_wrong
     51 [] <eventsop> /nick eventsop2
     52 [#events_test1] <eventsop2> /mode +n #events_test1
     53 [#events_test1] <eventsop2> /mode -n #events_test1
     54 [#events_test1] <eventsop2> /part #events_test1
     55 [#events_test2] <eventsop2> /topic mytopic
     56 [#events_test2] <eventsop2> /kick eventsc kickarg
     57 EOF
     58 cat > ref_nothing <<EOF
     59 [#events_test1] <eventsu> /join #events_wrong
     60 [#events_test2] <eventsop2> hello
     61 [#events_test2] <eventsop2> /hello2
     62 EOF
     63 
     64 (sleep 6; cat tosay) |
     65   ../../irctk -p eventsop@localhost \#events_test1 \#events_test2 2>/dev/null > /dev/null&
     66 PID=$!
     67 sleep 1
     68 tail -f /dev/null | ../../irctk -m eventsm@localhost \#events_test1 \#events_test2 > heard_message &
     69 PID1=$!
     70 sleep 1
     71 tail -f /dev/null | ../../irctk -c eventsc@localhost \#events_test1 \#events_test2 > heard_command &
     72 PID2=$!
     73 sleep 1
     74 tail -f /dev/null | ../../irctk -n eventsn@localhost \#events_test1 \#events_test2 > heard_nothing &
     75 PID3=$!
     76 sleep 2
     77 (echo '/join #events_wrong'; tail -f /dev/null) |
     78   ../../irctk -E0 eventsu@localhost \#events_test1 \#events_test2 > /dev/null &
     79 PID4=$!
     80 wait $PID
     81 sleep 3
     82 kill $PID1 $PID2 $PID3
     83 sleep 0.3
     84 kill $PID4
     85 
     86 # must work around "Quit: " prefix and quotes problem
     87 # must remove spurious /mode +i events
     88 # give up on testing on "quitarg" because some servers do not relay it
     89 diff ref_message <(
     90   sed '
     91     s/has quit.*/has quit/g;
     92     s/\(has left[^(]*\) (.*/\1/g' heard_message | grep -v '+i') \
     93       && diff ref_command <(
     94   sed '
     95     s_/quit.*_/quit_' heard_command | grep -v '+i') \
     96   && diff ref_nothing heard_nothing
     97