Add connection prompts

This commit is contained in:
Ultracoolguy 2020-11-24 14:29:56 -04:00
parent 700e3f3aa9
commit f327a1000a
2 changed files with 22 additions and 3 deletions

View File

@ -2,3 +2,5 @@
server = chat.freenode.invalid
nickname = matchmaking-bot
channels = #matchmaking-test
#Skipping ':' means using default port 1234
connections = tilde tildeverse.org foo foo.bar:6969

23
bot.py
View File

@ -7,6 +7,7 @@ from ircrobots import ConnectionParams
servers = []
match_players = {}
connections = {}
def update_file(name):
file = open(f"playerlist-{name}.txt", "w")
@ -36,7 +37,15 @@ class Server(BaseServer):
ping += f"{channel.users[pfold].nickname} "
await self.send(build("PRIVMSG", [chan, f"Pinging users: {ping}"]))
if connections[self.name]:
for connection,address in connections[self.name].items():
if connection in line.params[1]:
if ':' in address:
realaddress = address.split(':')[0]
port = address.split(':')[1]
self.send(build("PRIVMSG", [chan, f"Connect using nc {realaddress} {port}"]))
else:
self.send(build("PRIVMSG", [chan, f"Connect using nc {address} 1234"]))
elif line.params[1].startswith(".matchadd"):
user = line.source.split('!')[0]
@ -82,8 +91,16 @@ async def main():
exit(1)
server = config[section]['server']
nickname = config[section]['nickname']
channels = set(config[section]['channels'].split(' '))
# servers.update([(section, {'server':server, 'nickname':nickname, 'channels':channels})])
channels = set(config[section]['channels'].split())
if config[section]['connections']:
if len(config[section]['connections'].split()) % 2 != 0: # If connections isn't even
print(f"ERROR: The section {section} has an invalid 'connections' defined.")
exit(1)
config_connections = config[section]['connections'].split()
connections.update({section:{}})
for i in range(0, len(config_connections), 2):
connections[section].update({config_connections[i]:config_connections[i+1]})
servers.append({'name':section, 'opts':{'server':server, 'nickname':nickname, 'channels':channels}})
for channel in channels:
match_players.update([(section + '-' + channel, set())])