An open API service indexing awesome lists of open source software.

https://github.com/ebeem/erc-history


https://github.com/ebeem/erc-history

Last synced: 4 months ago
JSON representation

Awesome Lists containing this project

README

          

#+STARTUP: inlineimages
#+OPTIONS: toc:3 ^:nil

** ERC History

This package enhances Emacs's IRC client =ERC= by enabling it to retrieve chat history from channels. Note that chat logs must be archived and accessible online (currently, this package only supports HTTP access).

** Configuration

The primary configuration required is setting the variable =erc-history-sources=, which is a list of sources (HTTP links) and the channels they offer logs for.

The link can include wildcards that will be replaced when pulling chat logs:
- =#CHANNEL#=: The name of the currently viewed channel.
- =TIME=: Replaces all available time formats using Emacs Lisp's =format-time-string= function.

#+begin_src elisp
(require 'erc-history)
(setq erc-history-sources
'(("http://localhost/grc-history/#CHANNEL#/%Y/%m/%d.txt"
("#erc-history" "#erc-history-1"))))
#+end_src

Most of the time, the available logs will need to be parsed. In such cases, you can provide a parser function for each source. If no parser function is provided, a default one will be used, though it may not work properly.

The 3rd element in the source list is the function that parses log messages. The =parser= will receive a line from the chat logs and is expected to return a list of three variables: (=MSG_TIME= =SENDER_NICK= =MSG_CONTENT=). Ensure that the time format is in Emacs Lisp's time format. Use =encode-time= when needed, and convert the =timezone= as necessary. The default parser is =erc-history-common-message-parser=.

#+begin_src elisp
(defun erc-history-myhost-message-parser (msg)
"Display MSG in its erc buffer named CHANNEL.
MSG must match the format described for erc messages.
example: 2024-06-10 08:00:01 - ByteMaster: Good morning, team!"
(let ((regex "\\([0-9-]+ [0-9:]+\\) - \\([^:]+\\): \\(.*\\)"))
(when (string-match regex msg)
(let* ((time (match-string 1 msg))
(nick (match-string 2 msg))
(content (match-string 3 msg))
(full-date (format-time-string
(concat (string-replace " " "T" time) "+0000")
erc-history-last-pulled-date)))
(list (encode-time (parse-time-string full-date))
nick
content)))))

(setq erc-history-sources
'(("http://myhost/grc-history/#CHANNEL#/%Y/%m/%d.txt"
("#erc-history" "#erc-history-1")
erc-history-myhost-message-parser)))
#+end_src

*** Example: Configuring Ubuntu Archives

Since all of Ubuntu's IRC chats are archived, they can be easily accessed using erc-history.

#+begin_src elisp
(defun erc-history-ubuntu-message-parser (msg)
"Parse a chat log MSG and return a list of (time nickname message).
example: [23:22] UWN: Opening 842 for Saturday."
(let ((regex "\\[\\([0-9:]+\\)\\] <\\([^>]+\\)> \\(.*\\)"))
(when (string-match regex msg)
(let* ((time (match-string 1 msg))
(nick (match-string 2 msg))
(content (match-string 3 msg))
(full-date (format-time-string
(concat "%Y-%m-%dT" time ":00+0000")
erc-history-last-pulled-date)))
(list (encode-time (parse-time-string full-date))
nick
content)))))

(setq erc-history-sources
;; my personal logs
'(("http://myhost/grc-history/#CHANNEL#/%Y/%m/%d.txt"
("#erc-history-1" "#erc-history"))

;; ubuntu logs
("https://irclogs.ubuntu.com/%Y/%m/%d/#CHANNEL#.txt"
("#cloud-init" "#kubuntu-devel" "#kubuntu"
"#launchpad-dev" "#launchpad" "#lubuntu-devel"
"#lubuntu" "#maas" "#mir-server" "#netplan"
"#snappy" "#ubports" "#ubuntu-au" "#ubuntu-bd"
"#ubuntu-bugs" "#ubuntu-community-team" "#ubuntu-de"
"#ubuntu-desktop" "#ubuntu-devel" "#ubuntu-discuss"
"#ubuntu-doc" "#ubuntu-es" "#ubuntu-hr" "#ubuntu-ir"
"#ubuntu-irc" "#ubuntu-it" "#ubuntu-kernel" "#ubuntu-kr"
"#ubuntu-lt" "#ubuntu-mate" "#ubuntu-meeting" "#ubuntu-mirrors"
"#ubuntu-news" "#ubuntu-next" "#ubuntu-nl" "#ubuntu-on-air"
"#ubuntu-ops" "#ubuntu-pl" "#ubuntu-qt" "#ubuntu-quality"
"#ubuntu-release" "#ubuntu-ru" "#ubuntu-sa" "#ubuntu-security"
"#ubuntu-server" "#ubuntu-tw" "#ubuntu-uk" "#ubuntu-us-mi"
"#ubuntu-us-oh" "#ubuntu-us-pa" "#ubuntu" "#ubuntustudio-devel"
"#ubuntustudio" "#xubuntu-devel" "#xubuntu")
erc-history-ubuntu-message-parser)))
#+end_src

The configured channels' logs will automatically be retrieved when you navigate to the beginning of their buffers.

Note: Make sure you enable =erc-history-mode=.

*** Elpaca Configuration
In case you use a flexible package manager, you can just link this repo.

#+begin_src elisp
(use-package erc-history
:after erc
:ensure (:host github :repo "ebeem/erc-history")
:hook (erc-mode . erc-history-mode)
:init
(setq erc-history-sources
'(("http://localhost/grc-history/#CHANNEL#/%Y/%m/%d.txt"
("#erc-history" "#erc-history-1")))))
#+end_src

** Preview

#+ATTR_ORG: :width 800
[[./preview.gif]]