executable_twitch.scm 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/run/current-system/profile/bin/guile \
  2. --no-auto-compile -e (twitch) -s
  3. !#
  4. (define-module (twitch)
  5. #:use-module (guix records)
  6. #:use-module (guix discovery)
  7. #:use-module (ice-9 format)
  8. #:use-module (srfi srfi-41)
  9. #:export (main))
  10. (define-record-type* <twitch>
  11. twitch make-twitch
  12. twitch?
  13. (user twitch-user))
  14. (define %twitch-url
  15. "https://www.twitch.tv")
  16. (define %distro-root-directory
  17. ;; Absolute file name of the module hierarchy.
  18. (let ((file (dirname (current-filename))))
  19. (and (file-exists? file) (canonicalize-path file))))
  20. (define %default-package-module-path
  21. ;; Default search path for package modules.
  22. `(,%distro-root-directory))
  23. (define %twitch-module-path
  24. (let* ((not-colon (char-set-complement (char-set #\:)))
  25. (environment (string-tokenize (or (getenv "GUILE_LOAD_PATH") "")
  26. not-colon)))
  27. (set! %load-path
  28. (append environment (list %distro-root-directory) %load-path))
  29. (set! %load-compiled-path
  30. (append environment (list %distro-root-directory) %load-compiled-path))
  31. (make-parameter (append environment %default-package-module-path))))
  32. (define* (fold-twitch proc init
  33. #:optional
  34. (modules (all-modules (%twitch-module-path))))
  35. (fold-module-public-variables (lambda (object result)
  36. (if (twitch? object)
  37. (proc object result)
  38. result))
  39. init
  40. modules))
  41. (define (twitch->commands)
  42. (fold-twitch (lambda (twitch lst)
  43. (format #t "mpv ~s ~%"
  44. (string-append %twitch-url "/" (twitch-user twitch)))
  45. (format #t "firefox ~s ~%"
  46. (string-append "https://www.twitch.tv/popout/"
  47. (twitch-user twitch) "/chat?popout="))
  48. (newline))
  49. '()))
  50. (define-public twitch-shyt33
  51. (twitch
  52. (user "shyt33")))
  53. (define-public twitch-inv1ve
  54. (twitch
  55. (user "inv1ve")))
  56. (define-public twitch-arhont-tv
  57. (twitch
  58. (user "arhont_tv")))
  59. (define-public twitch-jeziq
  60. (twitch
  61. (user "jeziq")))
  62. (define (main args)
  63. (twitch->commands))