add hashtag option (#1)

This commit is contained in:
Mylloon 2024-01-26 15:44:28 +01:00
parent ec233810d2
commit c091d0cdd0
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 15 additions and 7 deletions

View file

@ -20,6 +20,7 @@ services:
- TWITTER_PASSWORD=yourpassword # take care, you need to double $ signs in your password - TWITTER_PASSWORD=yourpassword # take care, you need to double $ signs in your password
- TWITTER_TOTP=yourseed # optional if you don't have 2fa - TWITTER_TOTP=yourseed # optional if you don't have 2fa
- PUSK_DEBUG=FALSE # optional - PUSK_DEBUG=FALSE # optional
- PUSK_HASHTAG=TRUE # optional, will add an hashtag to tweets
restart: unless-stopped restart: unless-stopped
``` ```

View file

@ -45,10 +45,12 @@ let rec check ctx =
if 0 = timeout if 0 = timeout
then ( then (
if ctx.debug then print_endline "Tweeting..."; 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 *)
tweet tweet ctx message;
ctx
"This tweet is for the Twitter's CTO: don't suspend my account for inactivity.";
(* Returns to profile page *) (* Returns to profile page *)
go_to_profile ctx; go_to_profile ctx;
(* Wait the maximum time since we just tweeted *) (* Wait the maximum time since we just tweeted *)
@ -87,10 +89,8 @@ let () =
load_dotenv; load_dotenv;
let ctx = let ctx =
{ session_id = snd data { session_id = snd data
; debug = ; debug = boolean_env "PUSK_DEBUG"
(match Sys.getenv_opt "PUSK_DEBUG" with ; hashtag = boolean_env "PUSK_HASHTAG"
| Some boolean -> if String.lowercase_ascii boolean = "true" then true else false
| None -> false)
} }
in in
if ctx.debug then print_endline "Logging is enabled"; if ctx.debug then print_endline "Logging is enabled";

View file

@ -5,6 +5,7 @@ let fmt = Printf.sprintf
type context = type context =
{ session_id : string { session_id : string
; debug : bool ; debug : bool
; hashtag : bool
} }
let load_dotenv = let load_dotenv =
@ -13,6 +14,12 @@ let load_dotenv =
if Sys.file_exists path then Dotenv.export ~path () 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 keys_to_typing str =
let rec aux acc = function let rec aux acc = function
| 0 -> acc | 0 -> acc