Skip to content

Commit

Permalink
Bug fix - fix message duplicated from discord webhook bug
Browse files Browse the repository at this point in the history
  • Loading branch information
HappyGroupHub committed Jan 12, 2023
1 parent 0d3ad4e commit 6fc9801
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion discord_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def on_ready():
async def on_message(message):
if message.author == client.user:
return
if message.author == utils.get_discord_webhook_id():
if message.author.id == utils.get_discord_webhook_id():
return
elif message.channel.id == int(config.get('discord_channel_id')):
author = message.author.display_name
Expand Down
11 changes: 6 additions & 5 deletions line_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,16 @@ def handle_message(event):
"""Handle message event."""
author = line_bot_api.get_profile(event.source.user_id).display_name
message = event.message.text
body = request.get_data(as_text=True)
json_data = json.loads(body)
print(json_data)
# Debug:
# body = request.get_data(as_text=True)
# json_data = json.loads(body)
# print(json_data)
if config.get('line_chat_type') == 'group':
if event.source.group_id == config.get('line_group_id'):
discord_webhook.send(f"{author}: {message}", username="LD's Automation Bot")
discord_webhook.send(f"{author}: {message}", username="Line 訊息")
if config.get('line_chat_type') == 'user':
if event.source.user_id == config.get('line_user_id'):
discord_webhook.send(f"{author}: {message}", username="LD's Automation Bot")
discord_webhook.send(f"{author}: {message}", username="Line 訊息")


# TODO(LD): zmq
Expand Down
2 changes: 1 addition & 1 deletion utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ def get_discord_webhook_id():
:rtype: int
"""
webhook_url = read_config().get('discord_channel_webhook')
return webhook_url.split('/')[-2]
return int(webhook_url.split('/')[-2])

0 comments on commit 6fc9801

Please sign in to comment.