shithub: irc.myr

Download patch

ref: d31f3121f86f5ba32ee9bc00709d9b4a0de22b2a
parent: 995307348c9d76513e09b520d55d0d4d0997813a
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Nov 19 16:48:18 EST 2017

A few tweaks

	- Throttle reconnects
	- Don't let part/join as stale channels
	- Highlight the nick

--- a/irc.myr
+++ b/irc.myr
@@ -38,7 +38,7 @@
 	nbuf	: std.size
 	chan	: chan#[:]
 	focus	: std.size
-	live	: bool
+	death	: std.time
 ;;
 
 type chan = struct
@@ -65,6 +65,7 @@
 	var c
 	var fd
 
+	std.startalloctrace("irc.trace")
 	irc = mkirc()
 	while true
 		redraw(irc)
@@ -82,7 +83,7 @@
 
 const redial = {irc
 	for s : irc.srv
-		if s.live
+		if s.death == 0 || std.now() - s.death < 60*std.Sec
 			continue
 		;;
 		match std.dial(s.ds)
@@ -92,7 +93,7 @@
 				std.close(s.fd)
 				continue
 			;;
-			s.live = true
+			s.death = 0
 			for c : s.chan
 				send(irc, s, "JOIN {}\r\n", c.name)
 			;;
@@ -218,11 +219,14 @@
 const deluser = {irc, srv, user
 	for c : srv.chan
 		user = displayname(user)
+		puthist(irc, c, (std.now(), `Part std.sldup(user)))
 		match std.lsearch(c.users, user, std.strcmp)
-		| `std.Some i:  std.sldel(&c.users, i)
-		| `std.None:    continue
+		| `std.None:    
+			continue
+		| `std.Some i:  
+			std.slfree(c.users[i])
+			std.sldel(&c.users, i)
 		;;
-		puthist(irc, c, (std.now(), `Part std.sldup(user)))
 	;;
 }
 
@@ -283,8 +287,8 @@
 }
 
 const closed = {irc, srv, msg
-	if srv.live
-		srv.live = false
+	if srv.death == 0
+		srv.death = std.now()
 		status(irc, irc.self, "{} closed: {}", srv.ds, msg)
 	;;
 }
@@ -487,7 +491,7 @@
 			std.slpush(&irc.srv, srv)
 			if irc.focus == -1
 				irc.focus = irc.srv.len - 1
-				srv.live = true
+				srv.death = 0
 			;;
 			status(irc, irc.self, "connected to {}", ds)
 		else
@@ -934,7 +938,7 @@
 		| `Msg (m, ln):
 			termdraw.setattr(t, termdraw.Bold)
 
-			x = std.clamp(x0 + c.gutter - termdraw.strwidth(t, m)  - 3, 0, dx)
+			x = std.clamp(x0 + c.gutter - termdraw.strwidth(t, m), 0, dx)
 			(x, y) = draw(t, m, x, y, x1, y1)
 			(x, y) = draw(t, " | ", x, y, x1, y1)
 			termdraw.setattr(t, lineattr(irc, ln[off:]))
@@ -1171,10 +1175,14 @@
 	if chan.log != -1
 		date = date.mkinstant(tm, "local")
 		match contents
-		| `Msg (u, ln):	std.fput(chan.log, "{} {} >{}\n", date, u, ln)
 		| `Join user:	std.fput(chan.log, "{} #join {}\n", date, user)
 		| `Part user:	std.fput(chan.log, "{} #part {}\n", date, user)
 		| `Status msg:	std.fput(chan.log, "{} #status {}\n", date, msg)
+		| `Msg (u, ln):
+			std.fput(chan.log, "{} {} >{}\n", date, u, ln)
+			if chan != curchan(irc)
+				chan.stale = true
+			;;
 		;;
 	else
 		std.put("wat\n")
@@ -1181,9 +1189,6 @@
 	;;
 	if chan.scroll != 0
 		chan.scroll++
-	;;
-	if chan != curchan(irc)
-		chan.stale = true
 	;;
 }
 
--