From f4a3ce3c396ac3b99d671a77791f187c8e1cadb5 Mon Sep 17 00:00:00 2001 From: LD Date: Fri, 13 Jan 2023 14:11:19 +0800 Subject: [PATCH] Update - now messages to discord will use author's avatar image --- line_bot.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/line_bot.py b/line_bot.py index a0dfb53..9c49df3 100644 --- a/line_bot.py +++ b/line_bot.py @@ -1,6 +1,7 @@ """This python file will handle line webhooks.""" import json + # from threading import Thread # # import zmq @@ -52,18 +53,20 @@ def callback(): @handler.add(MessageEvent, message=TextMessage) def handle_message(event): """Handle message event.""" - print(debug_json()) if config.get('line_chat_type') == 'user': if event.source.user_id == config.get('line_user_id'): author = line_bot_api.get_profile(event.source.user_id).display_name + author_image = line_bot_api.get_profile(event.source.user_id).picture_url message = event.message.text - discord_webhook.send(f"{author}: {message}", username="Line 訊息") + discord_webhook.send(message, username=f"{author} - (Line訊息)", avatar_url=author_image) if config.get('line_chat_type') == 'group': if event.source.group_id == config.get('line_group_id'): author = line_bot_api.get_group_member_profile(event.source.group_id, event.source.user_id).display_name + author_image = line_bot_api.get_group_member_profile(event.source.group_id, + event.source.user_id).picture_url message = event.message.text - discord_webhook.send(f"{author}: {message}", username="Line 訊息") + discord_webhook.send(message, username=f"{author} - (Line訊息)", avatar_url=author_image) # TODO(LD): zmq