From 065773c70377567f7c6669b752ca51b27bef8ad3 Mon Sep 17 00:00:00 2001 From: default Date: Tue, 20 Sep 2022 11:38:18 +0200 Subject: [PATCH] Added muted functions. --- data.c | 42 ++++++++++++++++++++++++++++++++++++++++++ snac.h | 3 +++ 2 files changed, 45 insertions(+) diff --git a/data.c b/data.c index 7f60df5..667d1e6 100644 --- a/data.c +++ b/data.c @@ -477,3 +477,45 @@ int following_check(snac *snac, char *actor) return !!(mtime(fn) != 0.0); } + + +d_char *_muted_fn(snac *snac, char *actor) +{ + xs *md5 = xs_md5_hex(actor, strlen(actor)); + return xs_fmt("%s/muted/%s.json", snac->basedir, md5); +} + + +void mute(snac *snac, char *actor) +/* mutes a moron */ +{ + xs *fn = _muted_fn(snac, actor); + FILE *f; + + if ((f = fopen(fn, "w")) != NULL) { + fprintf(f, "%s\n", actor); + fclose(f); + + snac_debug(snac, 2, xs_fmt("muted %s %s", actor, fn)); + } +} + + +void unmute(snac *snac, char *actor) +/* actor is no longer a moron */ +{ + xs *fn = _muted_fn(snac, actor); + + unlink(fn); + + snac_debug(snac, 2, xs_fmt("unmuted %s %s", actor, fn)); +} + + +int is_muted(snac *snac, char *actor) +/* check if someone is muted */ +{ + xs *fn = _muted_fn(snac, actor); + + return !!(mtime(fn) != 0.0); +} diff --git a/snac.h b/snac.h index f2eae37..1e4a1a6 100644 --- a/snac.h +++ b/snac.h @@ -54,3 +54,6 @@ int following_add(snac *snac, char *actor, char *msg); int following_del(snac *snac, char *actor); int following_check(snac *snac, char *actor); +void mute(snac *snac, char *actor); +void unmute(snac *snac, char *actor); +int is_muted(snac *snac, char *actor);