Skip to content

Instantly share code, notes, and snippets.

@delivrance
Last active April 23, 2019 17:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save delivrance/b450953c5fb0a56edb4c8389f91e5a9b to your computer and use it in GitHub Desktop.
Save delivrance/b450953c5fb0a56edb4c8389f91e5a9b to your computer and use it in GitHub Desktop.
This is the Welcome Bot in @PyrogramChat (Telegram) written in Hy
;; This is the Welcome Bot in @PyrogramChat (Telegram) written in Hy
;;
;; Example ported from
;; https://github.com/pyrogram/pyrogram/blob/c2da2a61ece6711bd7ed51d68249995843ff5dec/examples/welcome_bot.py
;;
(import [pyrogram [Client Emoji Filters]])
(setv MENTION "[{}](tg://user?id={})")
(setv MESSAGE "{} Welcome to [Pyrogram](https://docs.pyrogram.ml/)'s group chat {}!")
(setv app (Client "my_account"))
(with-decorator (.on_message app (& (.chat Filters "PyrogramChat") (. Filters new_chat_members)))
(defn welcome [client message]
;; Build the new members list (with mentions) by using their first_name
(setv new_members (lfor i (. message new_chat_members) (.format MENTION (. i first_name) (. i id))))
;; Build the welcome message by using an emoji and the list we built above
(setv text (.format MESSAGE (. Emoji SPARKLES) (.join ", " new_members)))
;; Send the welcome message
(.reply message text :disable_web_page_preview True)))
(.run app) ; Automatically start() and idle()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment