-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.sh
More file actions
56 lines (47 loc) · 975 Bytes
/
bot.sh
File metadata and controls
56 lines (47 loc) · 975 Bytes
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
#!/bin/bash
NICK="quotes_bot"
USER="irccat 8 x : irccat"
SLEEP_TIME=3.4
send_message()
{
printf "%s\r\n" "$@"
}
get_random_quote()
{
local response=$(curl -s 'https://api.quotable.io/random')
local formatted=$(echo "$response" | tr '"' '\n')
local content=$(echo "$formatted" | grep -A2 content | sed '3q;d')
local author=$(echo "$formatted" | grep -A2 author | sed '3q;d')
echo "$content - $author"
}
bot()
{
local password="$1"
local channel="$2"
if ! (echo "$channel" | grep -q '#'); then
channel="#$channel"
fi
send_message "PASS $password"
send_message "NICK $NICK"
send_message "USER $USER"
send_message "JOIN $channel"
while true; do
sleep "$SLEEP_TIME"
quote=$(get_random_quote)
send_message "PRIVMSG $channel :$quote"
done
}
run()
{
if [ "$#" -ne 4 ]; then
echo "Usage: $0 <host> <port> <password> <channel>"
exit 1
fi
local host="$1"
local port="$2"
shift 2
while true;do
bot $@ | nc -q 0 "$host" "$port"
done
}
run $@