diff options
| author | 2022-09-20 11:38:18 +0200 | |
|---|---|---|
| committer | 2022-09-20 11:38:18 +0200 | |
| commit | 065773c70377567f7c6669b752ca51b27bef8ad3 (patch) | |
| tree | 76b1ef7c3b63744d4854bbd7b7059386449aa5f3 /data.c | |
| parent | Add following code. (diff) | |
| download | snac2-065773c70377567f7c6669b752ca51b27bef8ad3.tar.gz snac2-065773c70377567f7c6669b752ca51b27bef8ad3.tar.xz snac2-065773c70377567f7c6669b752ca51b27bef8ad3.zip | |
Added muted functions.
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 42 |
1 files changed, 42 insertions, 0 deletions
| @@ -477,3 +477,45 @@ int following_check(snac *snac, char *actor) | |||
| 477 | 477 | ||
| 478 | return !!(mtime(fn) != 0.0); | 478 | return !!(mtime(fn) != 0.0); |
| 479 | } | 479 | } |
| 480 | |||
| 481 | |||
| 482 | d_char *_muted_fn(snac *snac, char *actor) | ||
| 483 | { | ||
| 484 | xs *md5 = xs_md5_hex(actor, strlen(actor)); | ||
| 485 | return xs_fmt("%s/muted/%s.json", snac->basedir, md5); | ||
| 486 | } | ||
| 487 | |||
| 488 | |||
| 489 | void mute(snac *snac, char *actor) | ||
| 490 | /* mutes a moron */ | ||
| 491 | { | ||
| 492 | xs *fn = _muted_fn(snac, actor); | ||
| 493 | FILE *f; | ||
| 494 | |||
| 495 | if ((f = fopen(fn, "w")) != NULL) { | ||
| 496 | fprintf(f, "%s\n", actor); | ||
| 497 | fclose(f); | ||
| 498 | |||
| 499 | snac_debug(snac, 2, xs_fmt("muted %s %s", actor, fn)); | ||
| 500 | } | ||
| 501 | } | ||
| 502 | |||
| 503 | |||
| 504 | void unmute(snac *snac, char *actor) | ||
| 505 | /* actor is no longer a moron */ | ||
| 506 | { | ||
| 507 | xs *fn = _muted_fn(snac, actor); | ||
| 508 | |||
| 509 | unlink(fn); | ||
| 510 | |||
| 511 | snac_debug(snac, 2, xs_fmt("unmuted %s %s", actor, fn)); | ||
| 512 | } | ||
| 513 | |||
| 514 | |||
| 515 | int is_muted(snac *snac, char *actor) | ||
| 516 | /* check if someone is muted */ | ||
| 517 | { | ||
| 518 | xs *fn = _muted_fn(snac, actor); | ||
| 519 | |||
| 520 | return !!(mtime(fn) != 0.0); | ||
| 521 | } | ||