about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2022-03-02 23:26:16 -0500
committerJune McEnroe <june@causal.agency>2022-03-02 23:26:16 -0500
commitab426ddcc6c3488db8ef4b17d91f135b04a9209a (patch)
tree94ea6c734f3cfe33129f8d4d8c1af44af77fb21e
parentImplement self-signed certificate trusting (diff)
downloadcatgirl-ab426ddcc6c3488db8ef4b17d91f135b04a9209a.tar.gz
catgirl-ab426ddcc6c3488db8ef4b17d91f135b04a9209a.zip
Prompt for account, nick, pronouns
Diffstat (limited to '')
-rw-r--r--enroll.c63
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);