shithub: ircs

Download patch

ref: e978996babb834efb9d2de465c812e11178cc33a
parent: 5479f0fb4283ca4a5a58c9b7b50c5b86bde13aa1
author: kemal <kemalinanc8@gmail.com>
date: Mon Nov 15 06:48:06 EST 2021

ircs, ircx: add support for /me

--- a/dat.h
+++ b/dat.h
@@ -47,4 +47,4 @@
 	int	depth;
 };
 
-extern char *logdir;
+extern char *logdir, *mynick;
--- a/fns.h
+++ b/fns.h
@@ -8,6 +8,7 @@
 void	ircfmtquit(Ircmsg *, char *, int);
 void	ircfmtpart(Ircmsg *, char *, int);
 void	ircfmtpriv(Ircmsg *, char *, int);
+void	ircfmtaction(Ircmsg *, char *, int);
 void	ircfmtnumeric(Ircmsg *, char *, int);
 void	listfree(List **);
 int	listadd(List **, void *);
--- a/ircfmt.c
+++ b/ircfmt.c
@@ -123,6 +123,27 @@
 }
 
 void
+ircfmtaction(Ircmsg *irc, char *buf, int bufsize)
+{
+	int n;
+
+	n = strlen(irc->trail);
+	if(irc->trail[n-1] == 1)
+		irc->trail[n-1] = 0;
+	if(irc->nick == nil)
+		irc->nick = mynick;
+
+	if(logdir != nil && ircischan(irc->par[0]))
+		snprint(buf, bufsize,
+			"* %s %s",
+			irc->nick, irc->trail+8);
+	else
+		snprint(buf, bufsize,
+			"(%s) * %s %s",
+			irc->par[0], irc->nick, irc->trail+8);
+}
+
+void
 ircfmtnumeric(Ircmsg *irc, char *buf, int bufsize)
 {
 	int i, n;
--- a/ircs.man
+++ b/ircs.man
@@ -51,8 +51,8 @@
 
 The -p option causes a password to be sent to the server.  The
 password is read via the authentication agent factotum(4) which
-must be mounted in the same namespace.  The -p option can only be
-used with the -e (use TLS) option.
+must be mounted in the same namespace. Ircs will use TLS if -p is
+used.
 
 By default the logs are formatted so that they can easily be
 processed with Plan 9 tools, like cat(1) or grep(1).  The log
--- a/ircx
+++ b/ircx
@@ -27,7 +27,8 @@
 /w mask         send who query
 /W mask         send whois query
 /x              create new ircx window
-[/ ]message     send message to target'
+[/ ]message     send message to target
+/me message	send an action emote'
 
 fn usage{
 	aux/usage
@@ -299,6 +300,11 @@
 				ifs=$oifs				
 				msg='PRIVMSG '^$target^' :'^$line
 			}
+		case /me
+			if(~ $#target 0)
+				echo no target
+			if not
+				msg='PRIVMSG '^$target^' :ACTION '^$"*^''	
 		case /*
 			echo unknown command
 		case *
--- a/main.c
+++ b/main.c
@@ -45,13 +45,12 @@
 };
 
 int mainstacksize = Stacksize;
-char *logdir;
+char *logdir, *mynick;
 
 static char *service = "ircs";
 
 static char *post;
 static char *file;
-static char *mynick;
 static char *user;
 static char *addr;
 
@@ -498,7 +497,10 @@
 	target = nil;
 
 	if(strcmp(irc.cmd, "PRIVMSG") == 0){
-		fmt = ircfmtpriv;
+		if(strncmp(irc.trail, "\1ACTION ", 8) == 0)
+			fmt = ircfmtaction; /* /me */
+		else
+			fmt = ircfmtpriv;
 		target = irc.par[0];
 	} else if(strcmp(irc.cmd, "JOIN") == 0){
 		joinmsg(&irc, msg, time);
@@ -572,7 +574,10 @@
 	target = nil;
 
 	if(strcmp(irc.cmd, "PRIVMSG") == 0){
-		fmt = ircfmtpriv;
+		if(strncmp(irc.trail, "\1ACTION ", 8) == 0)
+			fmt = ircfmtaction; /* /me */
+		else
+			fmt = ircfmtpriv;
 		target = irc.par[0];
 	} else if(strcmp(irc.cmd, "QUIT") == 0){
 		state = Quit;