Merge pull request #17 from matan1905/add_telegram_user_filter1725652208138

Add telegram user filter
This commit is contained in:
Matan
2024-09-06 23:01:23 +03:00
committed by GitHub
2 changed files with 12 additions and 2 deletions
+1
View File
@@ -2,6 +2,7 @@
Welcome to the ComfyUI Serving Toolkit, a powerful tool for serving image generation workflows in Discord and other platforms (soon).
This toolkit is designed to simplify the process of serving your ComfyUI workflow, making image generation bots easier than ever before.
You can serve on discord, or on websockets.
* allowed_user - (Optional) The Telegram username of the user allowed to use the bot. If not set, all users can use the bot.
If you need any help, Checkout the [Discord!](https://discord.gg/AyHFchFZuV)
+11 -2
View File
@@ -20,6 +20,8 @@ class TelegramServing:
def telegram_handler(self):
@self.bot.message_handler(commands=[self.command_name])
def handle_command(message):
if self.allowed_user and message.from_user.username != self.allowed_user:
return # Silently ignore messages from unauthorized users
print(f"Received command from {message.chat.id}: {message.text}")
parsed_data = parse_command_string(message.text, self.command_name)
@@ -72,8 +74,14 @@ class TelegramServing:
"multiline": False,
"default": "generate"
})
"optional": {
"allowed_user": ("STRING", {
"multiline": False,
"default": ""
})
}
}
}
RETURN_TYPES = ("SERVING_CONFIG",)
RETURN_NAMES = ("Serving config",)
@@ -83,13 +91,14 @@ class TelegramServing:
def IS_CHANGED(cls, **kwargs):
return float("NaN")
def serve(self, telegram_token, command_name):
def serve(self, telegram_token, command_name, allowed_user=""):
if not self.telegram_running:
self.bot = telebot.TeleBot(telegram_token)
self.command_name = command_name
self.allowed_user = allowed_user
threading.Thread(target=self.telegram_handler, daemon=True).start()
print(f"Telegram bot running, listening for /{command_name} commands")
self.telegram_running = True
data = self.get_data()
return (data,)
return (data,)