From f08b2843979491753e1b8698c25228ac11c8f3da Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 18 Jul 2020 20:31:51 -0400 Subject: [PATCH] better join/leave, griefprevention support --- tcirc.py | 28 ++++++++++++++++++---------- tcirctilde.py | 29 ++++++++++++++++++----------- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/tcirc.py b/tcirc.py index 63338fe..9511e1b 100755 --- a/tcirc.py +++ b/tcirc.py @@ -89,7 +89,7 @@ def mc_to_irc(): time.sleep(1) latest_lines = file.readlines() for line in latest_lines: - if re.search('\[Async Chat Thread -.*?/INFO', line) is not None : + if re.search('\[Async Chat Thread -.*?/INFO', line) is not None and ': [GriefPrevention] ' not in line: print('received ' + ''.join(line)) line = re.sub(r'', r'^[', line) line = re.sub(r'\^.*?m', '', line) @@ -126,10 +126,11 @@ def mc_to_irc(): print('sent ' + line) irc.send(bytes('PRIVMSG ' + channel + ' :' + line, 'utf8')) - elif 'left the game' in line and 'IRC ' not in line: + elif 'left the game' in line and '[Server thread/INFO]: [Rcon] ' not in line: print('received ' + ''.join(line)) line = re.sub(r'', r'^[', line) line = re.sub(r'\[.*?: ', '', line, 1) + line = re.sub(r'left the game', 'logged off', line, 1) line = re.sub(r'\[/.*?\]', '', line, 1) line = re.sub(r'> ', '', line, 1) line = re.sub(r'lost connection: Disconnected', 'disconnected', line, 1) @@ -153,7 +154,7 @@ def mc_to_irc(): print('sent ' + line) if '@tildeverse:' not in line: irc.send(bytes('PRIVMSG ' + channel + ' :' + line, 'utf8')) - elif any(death in line for death in death_messages): + elif any(' ' + death + ' ' in line for death in death_messages) and 'Villager EntityVillager[\'' not in line: line = re.sub(r'^\[.*\]: ', '', line, 1) print('sent ' + line) irc.send(bytes('PRIVMSG ' + channel + ' :' + line, 'utf8')) @@ -166,7 +167,7 @@ def irc_to_mc(): rcon_password_file = open('rcon_password', 'r') rcon_password = rcon_password_file.readline().strip() rcon_password_file.close() - rcon.connect('209.182.234.192', 6668, rcon_password) + rcon.connect('0.0.0.0', 6668, rcon_password) print('initiated rcon connection') while 1: @@ -234,12 +235,19 @@ def irc_to_mc(): elif 'JOIN' in text or 'PART' in text: - text = re.sub(r':.*?\!', r'', text, 1) - text = re.sub(r'@localhost', r'', text, 1) - text = re.sub(r':WeeChat.*', r'', text, 1) - text = re.sub(r'JOIN', r'joined', text, 1) - text = re.sub(r'PART', r'left', text, 1) - rcon.command('say ' + text[:-2]) + print("-- JOIN EVENT --") + print(text) + if 'PART' in text: + text = re.search(r':.*!', text).group(0) + text = text[:-1] + text = text[1:] + text = text + ' left irc' + if 'JOIN' in text: + text = re.search(r':.*!', text).group(0) + text = text[:-1] + text = text[1:] + text = text + ' joined irc' + rcon.command('say ' + text) elif 'PING' in text: print('pinged by server, returning pong') diff --git a/tcirctilde.py b/tcirctilde.py index 74b8191..c661da3 100755 --- a/tcirctilde.py +++ b/tcirctilde.py @@ -89,7 +89,7 @@ def mc_to_irc(): time.sleep(1) latest_lines = file.readlines() for line in latest_lines: - if re.search('\[Async Chat Thread -.*?/INFO', line) is not None : + if re.search('\[Async Chat Thread -.*?/INFO', line) is not None and ': [GriefPrevention] ' not in line: print('received ' + ''.join(line)) line = re.sub(r'', r'^[', line) line = re.sub(r'\^.*?m', '', line) @@ -126,10 +126,11 @@ def mc_to_irc(): print('sent ' + line) irc.send(bytes('PRIVMSG ' + channel + ' :' + line, 'utf8')) - elif 'left the game' in line and 'IRC ' not in line: + elif 'left the game' in line and '[Server thread/INFO]: [Rcon] ' not in line: print('received ' + ''.join(line)) line = re.sub(r'', r'^[', line) line = re.sub(r'\[.*?: ', '', line, 1) + line = re.sub(r'left the game', 'logged off', line, 1) line = re.sub(r'\[/.*?\]', '', line, 1) line = re.sub(r'> ', '', line, 1) line = re.sub(r'lost connection: Disconnected', 'disconnected', line, 1) @@ -153,7 +154,7 @@ def mc_to_irc(): print('sent ' + line) if '@tilde.town:' not in line: irc.send(bytes('PRIVMSG ' + channel + ' :' + line, 'utf8')) - elif any(death in line for death in death_messages): + elif any(' ' + death + ' ' in line for death in death_messages) and 'Villager EntityVillager[\'' not in line: line = re.sub(r'^\[.*\]: ', '', line, 1) print('sent ' + line) irc.send(bytes('PRIVMSG ' + channel + ' :' + line, 'utf8')) @@ -166,7 +167,7 @@ def irc_to_mc(): rcon_password_file = open('rcon_password', 'r') rcon_password = rcon_password_file.readline().strip() rcon_password_file.close() - rcon.connect('209.182.234.192', 6668, rcon_password) + rcon.connect('0.0.0.0', 6668, rcon_password) print('initiated rcon connection') while 1: @@ -234,13 +235,19 @@ def irc_to_mc(): elif 'JOIN' in text or 'PART' in text: - text = re.sub(r':.*?\!', r'', text, 1) - text = re.sub(r'@localhost', r'', text, 1) - text = re.sub(r':WeeChat.*', r'', text, 1) - text = re.sub(r'JOIN', r'joined', text, 1) - text = re.sub(r'PART', r'left', text, 1) - rcon.command('say ' + text[:-2]) - + print("-- JOIN EVENT --") + print(text) + if 'PART' in text: + text = re.search(r':.*!', text).group(0) + text = text[:-1] + text = text[1:] + text = text + ' left irc' + elif 'JOIN' in text: + text = re.search(r':.*!', text).group(0) + text = text[:-1] + text = text[1:] + text = text + ' joined irc' + rcon.command('say ' + text) elif 'PING' in text: print('pinged by server, returning pong') irc.send(b'PONG ' + text.split()[1].encode() + b'\r\n')