Last active
April 23, 2019 17:13
-
-
Save delivrance/b450953c5fb0a56edb4c8389f91e5a9b to your computer and use it in GitHub Desktop.
This is the Welcome Bot in @PyrogramChat (Telegram) written in Hy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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