diff --git a/README.md b/README.md index 22705e9..dafef79 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ services: - TWITTER_PASSWORD=yourpassword # take care, you need to double $ signs in your password - TWITTER_TOTP=yourseed # optional if you don't have 2fa - PUSK_DEBUG=FALSE # optional + - PUSK_HASHTAG=TRUE # optional, will add an hashtag to tweets restart: unless-stopped ``` diff --git a/bin/main.ml b/bin/main.ml index 6e9456c..7ffd225 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -45,10 +45,12 @@ let rec check ctx = if 0 = timeout then ( if ctx.debug then print_endline "Tweeting..."; + let message = + "This tweet is for the Twitter's CTO: don't suspend my account for inactivity." + ^ if ctx.hashtag then "#puskbot" else "" + in (* Tweet *) - tweet - ctx - "This tweet is for the Twitter's CTO: don't suspend my account for inactivity."; + tweet ctx message; (* Returns to profile page *) go_to_profile ctx; (* Wait the maximum time since we just tweeted *) @@ -87,10 +89,8 @@ let () = load_dotenv; let ctx = { session_id = snd data - ; debug = - (match Sys.getenv_opt "PUSK_DEBUG" with - | Some boolean -> if String.lowercase_ascii boolean = "true" then true else false - | None -> false) + ; debug = boolean_env "PUSK_DEBUG" + ; hashtag = boolean_env "PUSK_HASHTAG" } in if ctx.debug then print_endline "Logging is enabled"; diff --git a/lib/utils.ml b/lib/utils.ml index cf5cbe0..ecbe5ba 100644 --- a/lib/utils.ml +++ b/lib/utils.ml @@ -5,6 +5,7 @@ let fmt = Printf.sprintf type context = { session_id : string ; debug : bool + ; hashtag : bool } let load_dotenv = @@ -13,6 +14,12 @@ let load_dotenv = if Sys.file_exists path then Dotenv.export ~path () ;; +let boolean_env variable = + match Sys.getenv_opt variable with + | Some boolean -> String.lowercase_ascii boolean = "true" + | None -> false +;; + let keys_to_typing str = let rec aux acc = function | 0 -> acc