Skip to content

Instantly share code, notes, and snippets.

@alexwilson
Last active September 27, 2020 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexwilson/95cbb8ad0f7969a6387571e51bc8bbfb to your computer and use it in GitHub Desktop.
Save alexwilson/95cbb8ad0f7969a6387571e51bc8bbfb to your computer and use it in GitHub Desktop.
Gender Identity and Preferred Gender Pronoun module for InspIRCd
#include "inspircd.h"
/**
* m_gender_pronouns.cpp
* Introduces two new commands, SETGENDER and SETPRONOUN,
* allowing a user to specify their gender identity and
* preferred gender pronouns.
*
* Copyright (c) 2017 Alex Wilson <a@ax.gy>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* Handle /SETGENDER
*/
class CommandSetgender : public Command
{
public:
StringExtItem gender;
CommandSetgender(Module* Creator) :
Command(Creator,"SETGENDER", 1, 1),
gender("gender", Creator)
{
allow_empty_last_param = true;
syntax = "<gender>";
}
CmdResult Handle(const std::vector<std::string> &parameters, User* user)
{
if (parameters[0].size() > ServerInstance->Config->Limits.MaxGecos)
{
user->WriteServ("*** SETGENDER: Gender too long");
return CMD_FAILURE;
}
if (parameters[0].empty()) {
gender.unset(user);
} else {
gender.set(user, parameters[0]);
}
ServerInstance->SNO->WriteGlobalSno('a', "%s used SETGENDER to change their gender to '%s'", user->nick.c_str(), parameters[0].c_str());
ServerInstance->PI->SendMetaData(user, "gender", parameters[0]);
return CMD_SUCCESS;
}
};
/**
* Handle /SETPRONOUN
*/
class CommandSetpronoun : public Command
{
public:
StringExtItem pronoun;
CommandSetpronoun(Module* Creator) :
Command(Creator,"SETPRONOUN", 1, 1),
pronoun("pronoun", Creator)
{
allow_empty_last_param = true;
syntax = "<pronouns>";
}
CmdResult Handle(const std::vector<std::string> &parameters, User* user)
{
if (parameters[0].size() > ServerInstance->Config->Limits.MaxGecos)
{
user->WriteServ("*** SETPRONOUN: Pronoun(s) too long");
return CMD_FAILURE;
}
if (parameters[0].empty()) {
pronoun.unset(user);
} else {
pronoun.set(user, parameters[0]);
}
ServerInstance->SNO->WriteGlobalSno('a', "%s used SETPRONOUN to change their pronouns to '%s'", user->nick.c_str(), parameters[0].c_str());
ServerInstance->PI->SendMetaData(user, "pronoun", parameters[0]);
return CMD_SUCCESS;
}
};
class ModuleGenderPronouns : public Module
{
CommandSetgender setgender;
CommandSetpronoun setpronoun;
public:
ModuleGenderPronouns() : setgender(this), setpronoun(this)
{
}
void init()
{
ServerInstance->Modules->AddService(setgender);
ServerInstance->Modules->AddService(setgender.gender);
ServerInstance->Modules->AddService(setpronoun);
ServerInstance->Modules->AddService(setpronoun.pronoun);
Implementation eventlist[] = { I_OnWhoisLine };
ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
}
ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text)
{
if (numeric == 312) {
std::string* gender = setgender.gender.get(dest);
std::string* pronoun = setpronoun.pronoun.get(dest);
if ((gender) || (pronoun)) {
std::string response = "";
if (gender) {
response += std::string("identifies their gender as '")+gender->c_str()+"'";
}
if (pronoun) {
if (!response.empty()) {
response += std::string(" and ");
}
response += std::string("prefers the gender pronouns '")+pronoun->c_str()+"'";
}
ServerInstance->SendWhoisLine(user, dest, 320, "%s %s :%s", user->nick.c_str(), dest->nick.c_str(), response.c_str());
}
}
return MOD_RES_PASSTHRU;
}
Version GetVersion()
{
return Version("Provides the SETGENDER and SETPRONOUNS commands which allow users to display gender identity and pronouns in WHOIS.", VF_VENDOR);
}
};
MODULE_INIT(ModuleGenderPronouns)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment