Skip to content

Instantly share code, notes, and snippets.

@izabera
Last active June 21, 2023 14:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save izabera/345327710e70c10c4e45 to your computer and use it in GitHub Desktop.
Save izabera/345327710e70c10c4e45 to your computer and use it in GitHub Desktop.
a simple irc bot written in sed
#!/bin/bash
owner=izabera nick=sedirc network=irc.freenode.net
echo "
# send bot data
1 {
s/.*/nick $nick/p
s/.*/user $nick $nick $nick :$nick/p
s/.*/cat factoids 2>\/dev\/null/e; H
b
}
# reply to pings
/^PING/ { s/I/O/p; b }
# !learn a b
/^:\([^!]*\)![^ ]* PRIVMSG \(#[^ ]*\) :!learn \([^ ][^ ]*\) *\(..*\)/ {
H
s//PRIVMSG \2 :Ok, \1/p
b
}
# reply to !a with b
/^:[^!]*![^ ]* PRIVMSG \(#[^ ]*\) :!\([^ ].*\)/ {
s//\1 \2/
G
s/^\([^ ]*\) \([^\n]*\).*\n:[^!]*![^ ]* PRIVMSG \1 :!learn \2 \([^\n]*\).*/PRIVMSG \1 :\3/p
b
}
# owner can control the bot with these
/^\(:$owner![^ ]* PRIVMSG $nick :!\)\(.*\)/ s//\2/p
/^:$owner![^ ]* PRIVMSG $nick :save$/ {
# this is supposed to be used before killing the bot for whatever reason
g; w factoids.bak
s/.*/mv factoids.bak factoids/e
}
" > bot.sed
sed -unf bot.sed <> "/dev/tcp/$network/6667" >&0
@nataliemeow
Copy link

why

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment