diff options
Diffstat (limited to 'enroll.c')
-rw-r--r-- | enroll.c | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/enroll.c b/enroll.c index 8cb96c1..ac97414 100644 --- a/enroll.c +++ b/enroll.c @@ -130,6 +130,9 @@ static struct { struct addrinfo *addr; struct tls_config *tls; char *trust; + char *account; + char *nick; + char *pronouns; } info; static void unset(char **resp) { @@ -423,6 +426,45 @@ fail: return -1; } +static int getAccount(void) { + int pop = prompt( + &info.account, "", + "If you already have an account on %s, what is its name?\n" + "If you have a NickServ account already, enter the name of the\n" + "account. If you aren't sure, leave this blank.\n", + info.network + ); + if (pop) return pop; + if (!info.account[0]) return 0; + + info.nick = strdup(info.account); + if (!info.nick) err(EX_OSERR, "strdup"); + + // TODO: Prompt for account password. + return 0; +} + +static int getNick(void) { + return prompt( + &info.nick, getenv("USER"), + "What name would you like to use on %s?\n" + "This is the name others will see on IRC, called a nick. It must be\n" + "unique, and can usually contain letters, digits, underscores and\n" + "hyphens, but cannot start with a digit.\n", + info.network + ); +} + +static int getPronouns(void) { + return prompt( + &info.pronouns, NULL, + "What are your pronouns?\n" + "This will be added to your \"real name\" so that other IRC users can\n" + "find out how to refer to you with /whois.\n" + "Examples: they/them, she/her, he/him\n" + ); +} + int main(int argc, char *argv[]) { for (int opt; 0 < (opt = getopt(argc, argv, "v"));) { switch (opt) { @@ -485,6 +527,21 @@ int main(int argc, char *argv[]) { unset(&info.host); unset(&info.port); } + } else if (!info.account) { + pop = getAccount(); + if (pop) { + unset(&info.trust); + freeaddrinfo(info.addr); + info.addr = NULL; + unset(&info.host); + unset(&info.port); + } + } else if (!info.nick) { + pop = getNick(); + if (pop) unset(&info.account); + } else if (!info.pronouns) { + pop = getPronouns(); + if (pop) unset(&info.nick); } else { break; } @@ -500,7 +557,11 @@ int main(int argc, char *argv[]) { fprintf(file, "port = %s\n", info.port); } if (info.trust) { - fprintf(file, "trust = %s.pem", info.host); + fprintf(file, "trust = %s.pem\n", info.host); + } + fprintf(file, "nick = %s\n", info.nick); + if (strlen(info.pronouns) > 1) { + fprintf(file, "real = %s [%s]\n", info.nick, info.pronouns); } error = fclose(file); |