emacs-erc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RFC: BAN and UNBAN commands


From: Corwin Brust
Subject: RFC: BAN and UNBAN commands
Date: Mon, 9 Oct 2023 11:04:33 -0500

I created a function and ERC commands for BAN and UNBAN.   They rely on the built-in OP and DEOP commands (which in turn rely on CHANNELSERV) when you use them without already having OP status (+o) in the given channel.

I hope they might be useful to others -of course; eventually- but especially, I gratefully anticipate any feedback you think may improve my knowledge of ERC, elisp, or give me a better sense of the stylistic preferences of other users.

TIA for your comments and suggestions.
Corwin

https://git.sr.ht/~mplscorwin/dotfiles/tree/master/item/elisp/init-erc-30.el#L161

(defun erc-channel-ban-user (who &optional unban)
  "Attempt to set mode +b for WHO in the current channel.

WHO is a string containing the nick of the user to ban.  When
UNBAN is non-nil, attemp to remove channel ban, instead.  Use
CHANNELSERV to attempt to gain OP in the current channel, if
necessary, in which case drop OP again afterword.

Return a string indicicating the outcome."
  (if-let ((channel (erc-default-target))
	   (mynick (erc-current-nick)))
      (let ((isop (if-let ((user (erc-get-channel-user mynick)))
		      (erc-channel-user-op (cdr user)))))
	(unless isop (erc-cmd-OPME))
	(if (prog1 (erc-server-send (format "MODE %s %sb %s :"
					    channel
					    (if unban "-" "+")
					    who))
	      (unless isop (erc-cmd-DEOPME)))
	    (format "Banned %s from %s" who channel)
	  (format "Failed to band %s from %s" who channel)))
    "Not an IRC channel or missing WHO, a nickname to ban"))

(defun erc-cmd-BAN (who)
  "Attempt to set mode +b for WHO in the current channel."
  (erc-display-line (erc-channel-ban-user who)))

(defun erc-cmd-UNBAN (who)
  "Attempt to set mode -b for WHO in the current channel."
  (erc-display-line (erc-channel-ban-user who t)))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]