From 20879400dd0c6652269e6b135064e12c55cf79d9 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Wed, 28 Apr 2021 21:12:31 -0400 Subject: Add copy mode to typer --- bin/man1/typer.1 | 8 ++++++-- bin/typer.c | 10 ++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/bin/man1/typer.1 b/bin/man1/typer.1 index a3b0eb90..dd1108d1 100644 --- a/bin/man1/typer.1 +++ b/bin/man1/typer.1 @@ -1,4 +1,4 @@ -.Dd April 18, 2021 +.Dd April 28, 2021 .Dt TYPER 1 .Os . @@ -8,7 +8,7 @@ . .Sh SYNOPSIS .Nm -.Op Fl PRv +.Op Fl CPRv .Op Fl c Ar cert .Op Fl n Ar nick .Op Fl p Ar port @@ -22,6 +22,10 @@ is an IRC bot that types all day long. The arguments are as follows: .Bl -tag -width Ds +.It Fl C +Copy +.Nm . +Type whenever anyone else is typing. .It Fl P Request the .Sy causal.agency/passive diff --git a/bin/typer.c b/bin/typer.c index 0218ee24..186f8214 100644 --- a/bin/typer.c +++ b/bin/typer.c @@ -64,6 +64,7 @@ static void format(const char *format, ...) { static bool joined; static bool reverse; +static bool copy; static void handle(char *line) { char *tags = NULL; @@ -84,6 +85,10 @@ static void handle(char *line) { joined = true; } else if (!strcmp(cmd, "PING")) { format("PONG %s\r\n", line); + } else if (copy && !strcmp(cmd, "TAGMSG") && tags) { + if (strstr(tags, "typing=")) { + format("@%s TAGMSG %s\r\n", tags, chan); + } } else if (reverse && !strcmp(cmd, "TAGMSG") && tags && origin) { char *nick = strsep(&origin, "!"); if (strstr(tags, "typing=active")) { @@ -114,8 +119,9 @@ int main(int argc, char *argv[]) { const char *user = "typer"; bool passive = false; - for (int opt; 0 < (opt = getopt(argc, argv, "PRc:n:p:u:v"));) { + for (int opt; 0 < (opt = getopt(argc, argv, "CPRc:n:p:u:v"));) { switch (opt) { + break; case 'C': copy = true; break; case 'P': passive = true; break; case 'R': reverse = true; break; case 'c': cert = optarg; @@ -156,7 +162,7 @@ int main(int argc, char *argv[]) { nick, user ); - if (!reverse) { + if (!copy && !reverse) { signal(SIGALRM, timer); struct itimerval itimer = { .it_interval.tv_sec = 5, -- cgit 1.4.1