From 0a18669f4068c7c19e84bbeefa649961af47d14b Mon Sep 17 00:00:00 2001 From: retoor Date: Wed, 19 Mar 2025 21:02:39 +0000 Subject: [PATCH] feat: add auth_init function and remove version-specific startup messages Implement auth_init() in auth.h to detect API keys from environment variables (R_KEY or OPENAI_API_KEY) and set auth_type accordingly. In main.c, call auth_init() during init() and replace the conditional commercial/free version startup messages with a simple carriage return clear. --- auth.h | 17 +++++++++++++++++ main.c | 9 +++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/auth.h b/auth.h index 141f0ea..ace0580 100644 --- a/auth.h +++ b/auth.h @@ -19,10 +19,27 @@ enum AUTH_TYPE { int auth_type = AUTH_TYPE_FREE; +void auth_init() { + char *api_key = NULL; + api_key = getenv("R_KEY"); + if (api_key) { + auth_type = AUTH_TYPE_API_KEY; + return; + } + api_key = getenv("OPENAI_API_KEY"); + if (api_key) { + auth_type = AUTH_TYPE_API_KEY; + return; + } + auth_type = AUTH_TYPE_FREE; + return; +} + const char *resolve_api_key() { static char *api_key = NULL; api_key = getenv("R_KEY"); if (api_key) { + auth_type = AUTH_TYPE_API_KEY; return api_key; } api_key = getenv("OPENAI_API_KEY"); diff --git a/main.c b/main.c index 918805d..a5803c0 100644 --- a/main.c +++ b/main.c @@ -289,6 +289,7 @@ bool openai_include(char *path) { void init() { setbuf(stdout, NULL); line_init(); + auth_init(); const char *locale = setlocale(LC_ALL, NULL); char payload[4096] = {0}; sprintf(payload, "Your locale is %s. User lang is %s.", locale, locale); @@ -296,12 +297,8 @@ void init() { openai_system(payload); if(!openai_include(".rcontext.txt")){ openai_include("~/.rcontext.txt"); - } - #ifndef FREE_VERSION - fprintf(stderr, "%s", "\r✅ Commercial version. Type help for features.\n"); - #else - fprintf(stderr, "%s","\r✅ Free version (GPT-3.5 Turbo), for you by retoor.\n"); - #endif + } + fprintf(stderr, "\r \r"); } int main(int argc, char *argv[]) {