From 387fd50f7d727ecf9c2df21ef6ed9d134b21324a Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Sun, 27 Jan 2019 12:57:37 +0100 Subject: No longer respond to its own messages, chat log. --- jh-discord.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/jh-discord.py b/jh-discord.py index d9e4503..c377175 100644 --- a/jh-discord.py +++ b/jh-discord.py @@ -27,6 +27,14 @@ parser.add_argument( help = 'Discord token.', ) +parser.add_argument( + '-c', + '--print-chat', + dest='print_chat', + help = 'Prints all messages', + action="store_true", +) + args = parser.parse_args() server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) @@ -47,8 +55,6 @@ def get_jh_reply (): c = server.recv(1) jh_reply += c - print(jh_reply) - if ((jh_reply == b"!P \n") or (jh_reply == b"!N \n")): is_done = True else: @@ -70,9 +76,25 @@ async def on_ready(): @client.event async def on_message(message): + if (message.author.id == client.user.id): + return + server.sendall(b"?RLR " + bytes(message.content, "utf8") + b"\n") result = get_jh_reply() - print("Result: " + result) + + if (args.print_chat): + print( + str(message.server) + + "#" + + str(message.channel.name) + + " <" + + str(message.author.name) + + "> " + + str(message.content) + ) + + if (len(result) > 0): + print("#" + str(message.channel.name) + " <- " + result) if (len(result) > 0): await client.send_message(message.channel, result) -- cgit v1.2.3-70-g09d2