Moderating maiko

by marco on the 08 of June, 2015 at 22:00

The maiko forum now holds posts in a moderation queue. This wasn't due to any urgent necessity, but as a consequence of developing a notification system for new posts and topics (plus, in the process, fixing a couple of glitches in the mmod.py script — maiko.py itself remains unchanged at version 1).

The notification mechanism takes form as a zsh script external to maiko. After changing the appropriate settings (e.g. log_dir) it should be run manually the first time to create a baseline snapshot of the current state of the forum. From then on it should be placed in, say, cron.hourly.

The script is as follows:

#!/bin/zsh -f

email='moderator@example'
subject='Maiko forum activity detected'
topics_dir='/www/path_to/topics'
log_dir='/path_to/var'

setopt null_glob
setopt extended_glob

new_ls=`ls -p -C1 -d ${topics_dir}/**/[0-9]*`
new_md5sum=`echo ${new_ls} | md5sum | awk '{print $1}'`
new_md5file=${log_dir}/${new_md5sum}.maiko
old_md5file=(${log_dir}/[a-z0-9](#c32).maiko)
if [[ ! -e ${old_md5file} ]]
    then
    echo ${new_ls} > ${new_md5file}
    exit 0
fi
old_md5sum=${${old_md5file}:t:r}
if [[ ${new_md5sum} == ${old_md5sum} ]]
    then
    exit 0
fi
echo ${new_ls} > ${new_md5file}
upd=`diff --old-line-format='old: %L' --new-line-format='new: %L' --unchanged-line-format='' ${old_md5file} ${new_md5file}`
(echo ${upd}) | mail -s "${subject}" ${email}
rm ${old_md5file}

If any changes are detected an email will be sent within the hour indicating any new posts or topics. Please note that, as it stands, the above script does not contain any error-catching code.


Comments

(click here to contribute, will open a new tab)

This page has no comments.


up     previous     next