~fultonbrowne/rc-scripts

ref: 1548cc3d3364e742e401026593c24123c7b17457 rc-scripts/grid/chat -rwxr-xr-x 2.0 KiB
1548cc3d — glenda added yet another handy script 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/rc
# minimal chat client for hubfs: chat [-n NICK] [-j CHANNEL] [chatsrv]

fn helpmessage{
	echo -------------------------
	echo '/q to quit  |  /c to list channels  |  /h for help message'
	echo '/n NICK to change nick  |  /j CHANNEL to change channels'
	echo -------------------------
}

rfork enf
channel=chat
chatsrv=chat
while (~ $1 -*){
	switch($1){
	case -n
		name = $2
		shift
		shift
	case -j
		channel = $2
		shift
		shift
	case *
		echo bad flag $1 '-n NICK -j CHANNEL'
		shift
	}
}
if(! ~ $1 '')
	chatsrv=$1
if(! test -e /n/$chatsrv/chat)
	mount /srv/$chatsrv /n/$chatsrv
if(! test -e /n/$chatsrv/chat){
	echo 'no chat service named $chatsrv found' >[1=2]
	exit no.chat
}

echo '		-- hubchat 0.2 --'
helpmessage
sleep 2
while(~ $#name 0){
	echo 'please enter a chat name:'
	name=`{read}
}
echo JOIN $name to $channel >>/n/$chatsrv/$channel
cat /n/$chatsrv/$channel &
catkill=$apid

while(talk=`{read}){
	if(~ $talk /*){
		switch($talk){
		case /q*
			echo PART $name from $channel >>/n/$chatsrv/$channel
			@{echo kill>/proc/$catkill/ctl}
			exit
		case /n*
			if(! ~ $talk(2) ''){
				echo nick $name ' -> ' $talk(2) >>/n/$chatsrv/$channel
				name=$talk(2)
			}
			if not
				echo 'you need to provide a nick for /n NICK'
			command=yes
		case /j*
			if (~ $talk(2) '')
				echo must specify a channel to join
			if not if(test -e /n/chat/$talk(2)){
				echo PART $name from $channel >>/n/$chatsrv/$channel
				@{echo kill>/proc/$catkill/ctl}
				channel=$talk(2)
				cat /n/chat/$channel &
				catkill=$apid
				echo JOIN $name to $channel >>/n/$chatsrv/$channel
			}
			if not
				echo channel does not exist
			command=yes
		case /h*
			helpmessage
			echo currently in $channel
			echo
			command=yes
		case /c
			echo Available channels:
			lc /n/$chatsrv
			echo -------------------
			echo currently in $channel
			echo
			command=yes
		case *
			echo unknown command
			command=yes
		}
	}
	if(~ $talk '')
		command=yes
	if(! ~ $command yes){
#		ts=`{date -u}
#		ts=`{echo '('^$ts(4)^')'}
		line=`{echo $name ': ' $talk}
		echo $line >>/n/chat/$channel
	}
	command=no
}