better join/leave, griefprevention support

This commit is contained in:
BuildTools 2020-07-18 20:31:51 -04:00
parent aeb14d12d9
commit f08b284397
2 changed files with 36 additions and 21 deletions

View File

@ -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')

View File

@ -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')