From 75f49a6344a69718c9675da1bf5823df88fdae15 Mon Sep 17 00:00:00 2001 From: Valerie Pond <79415174+ValwareIRC@users.noreply.github.com> Date: Thu, 24 Aug 2023 17:13:56 +0100 Subject: [PATCH 1/2] My implementation of https://github.com/ircv3/ircv3-ideas/issues/108 ## `+draft/rated` This lets users who post media mark their posts as "Not safe for work" to some degree, allowing other users to choose whether or not they want to see this post. --- files/rated.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 files/rated.c diff --git a/files/rated.c b/files/rated.c new file mode 100644 index 0000000..bcbc63b --- /dev/null +++ b/files/rated.c @@ -0,0 +1,85 @@ +/* + Licence: GPLv3 or later + Copyright Ⓒ 2023 Valerie Pond + draft/rated + +*/ +/*** <<>> +module +{ + documentation "https://github.com/ValwareIRC/valware-unrealircd-mods/blob/main/rated/README.md"; + troubleshooting "In case of problems, documentation or e-mail me at v.a.pond@outlook.com"; + min-unrealircd-version "6.*"; + max-unrealircd-version "6.*"; + post-install-text { + "The module is installed. Now all you need to do is add a loadmodule line:"; + "loadmodule \"third/rated\";"; + "The module does not need any other configuration."; + } +} +*** <<>> +*/ + + +#include "unrealircd.h" +#define MTAG_RATED "+draft/rated" // can be changed at a later date + +ModuleHeader MOD_HEADER = { + "third/rated", + "1.0", + "+draft/rated", + "Valware", + "unrealircd-6", +}; + +int rated_mtag_is_ok(Client *client, const char *name, const char *value); +void mtag_add_rated(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature); + +MOD_INIT() +{ + MessageTagHandlerInfo mtag; + + MARK_AS_GLOBAL_MODULE(modinfo); + + memset(&mtag, 0, sizeof(mtag)); + mtag.is_ok = rated_mtag_is_ok; + mtag.flags = MTAG_HANDLER_FLAGS_NO_CAP_NEEDED; + mtag.name = MTAG_RATED; + MessageTagHandlerAdd(modinfo->handle, &mtag); + + HookAddVoid(modinfo->handle, HOOKTYPE_NEW_MESSAGE, 0, mtag_add_rated); + + return MOD_SUCCESS; +} + +MOD_LOAD() +{ + return MOD_SUCCESS; +} + +MOD_UNLOAD() +{ + return MOD_SUCCESS; +} + +int rated_mtag_is_ok(Client *client, const char *name, const char *value) +{ + if (strlen(value) && strlen(value) >= 100) // allow null values but cap long values to 100 chars. + return 0; + return 1; +} + +void mtag_add_rated(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature) +{ + MessageTag *m; + + if (IsUser(client)) + { + m = find_mtag(recv_mtags, MTAG_RATED); + if (m) + { + m = duplicate_mtag(m); + AddListItem(m, *mtag_list); + } + } +} From 6ce72758befb2975d1220f7a2552fa7610482679 Mon Sep 17 00:00:00 2001 From: Valerie Liu <79415174+ValwareIRC@users.noreply.github.com> Date: Tue, 24 Oct 2023 00:46:46 +0100 Subject: [PATCH 2/2] Fix indentation, give better description, rename rated-tag --- files/{rated.c => rated-tag.c} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename files/{rated.c => rated-tag.c} (94%) diff --git a/files/rated.c b/files/rated-tag.c similarity index 94% rename from files/rated.c rename to files/rated-tag.c index bcbc63b..54950b3 100644 --- a/files/rated.c +++ b/files/rated-tag.c @@ -25,9 +25,9 @@ module #define MTAG_RATED "+draft/rated" // can be changed at a later date ModuleHeader MOD_HEADER = { - "third/rated", + "third/rated-tag", "1.0", - "+draft/rated", + "+draft/rated tag, allowing clients to implement ratings on their message", "Valware", "unrealircd-6", }; @@ -65,7 +65,7 @@ MOD_UNLOAD() int rated_mtag_is_ok(Client *client, const char *name, const char *value) { if (strlen(value) && strlen(value) >= 100) // allow null values but cap long values to 100 chars. - return 0; + return 0; return 1; }