Recently Written · git

ii-lchat-metapackage

Get suckless irc working for YOU

git clone https://github.com/equwal/ii-lchat-metapackage

Log | Files | Refs


irc-connect (1755 bytes)

1 #!/bin/sh
2 
3 # IRC client connector script
4 # Usage: irc-connect <server> <nick> <pass> <dir> [channel1] [channel2] ...
5 
6 SERVER="$1"
7 NICK="$2"
8 PASS="$3"
9 DIR="$4"
10 shift 4
11 
12 # Start ii client
13 ii -s "$SERVER" -n "$NICK" -i "$DIR" -e &
14 II_PID=$!
15 
16 # Wait for server directory to be created and connection established
17 wait_for_connection() {
18     local server_dir="$DIR/$SERVER"
19     local timeout=30
20     local count=0
21     
22     while [ $count -lt $timeout ]; do
23         if [ -p "$server_dir/in" ]; then
24             echo "Connection established to $SERVER"
25             return 0
26         fi
27         sleep 1
28         count=$((count + 1))
29     done
30     echo "Timeout waiting for connection to $SERVER" >&2
31     return 1
32 }
33 
34 # Wait for nickserv directory (indicates we're connected)
35 wait_for_nickserv() {
36     local nickserv_dir="$DIR/$SERVER/nickserv"
37     local timeout=15
38     local count=0
39     
40     while [ $count -lt $timeout ]; do
41         if [ -d "$nickserv_dir" ]; then
42             echo "NickServ available"
43             return 0
44         fi
45         sleep 1
46         count=$((count + 1))
47     done
48     echo "NickServ not found, proceeding anyway" >&2
49     return 1
50 }
51 
52 # Wait for connection
53 if ! wait_for_connection; then
54     kill $II_PID 2>/dev/null
55     exit 1
56 fi
57 
58 # Authenticate with NickServ if password provided
59 if [ -n "$PASS" ]; then
60     # Wait for nickserv to be available
61     wait_for_nickserv
62     
63     # Try different authentication methods
64     if [ -p "$DIR/$SERVER/nickserv/in" ]; then
65         echo "IDENTIFY $PASS" >"$DIR/$SERVER/nickserv/in"
66         sleep 2
67     fi
68     echo "/msg NickServ IDENTIFY $PASS" >"$DIR/$SERVER/in"
69     sleep 3
70 fi
71 
72 # Join all provided channels
73 for channel in "$@"; do
74     echo "/j $channel" >"$DIR/$SERVER/in"
75     sleep 2
76 done
77 
78 wait $II_PID