mirror of
https://github.com/Xevion/tcp-chat.git
synced 2025-12-10 02:08:47 -06:00
command name argument lower, ensure client is properly removed from main.py all_clients
This commit is contained in:
@@ -32,7 +32,7 @@ class CommandHandler:
|
|||||||
aliases = []
|
aliases = []
|
||||||
|
|
||||||
name = name or func.__name__.capitalize()
|
name = name or func.__name__.capitalize()
|
||||||
command_name = command_name or func.__name__.lower()
|
command_name = (command_name or func.__name__).lower()
|
||||||
|
|
||||||
for alias in aliases:
|
for alias in aliases:
|
||||||
self.aliases[alias] = command_name
|
self.aliases[alias] = command_name
|
||||||
|
|||||||
@@ -104,7 +104,9 @@ class Client:
|
|||||||
|
|
||||||
command = data['content'].strip()
|
command = data['content'].strip()
|
||||||
if command.startswith('/'):
|
if command.startswith('/'):
|
||||||
msg = self.command.process(data['content'][1:].strip().split())
|
args = data['content'][1:].strip().split()
|
||||||
|
args[0] = args[0].lower() # Command name will always be perceived as lowercase
|
||||||
|
msg = self.command.process(args)
|
||||||
if msg is not None:
|
if msg is not None:
|
||||||
self.broadcast_message(msg)
|
self.broadcast_message(msg)
|
||||||
|
|
||||||
@@ -112,5 +114,6 @@ class Client:
|
|||||||
logger.critical(e, exc_info=True)
|
logger.critical(e, exc_info=True)
|
||||||
logger.info(f'Client {self.id} closed. ({self.nickname})')
|
logger.info(f'Client {self.id} closed. ({self.nickname})')
|
||||||
self.conn.close()
|
self.conn.close()
|
||||||
|
self.all_clients.remove(self)
|
||||||
self.broadcast_message(f'{self.nickname} left!')
|
self.broadcast_message(f'{self.nickname} left!')
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -33,5 +33,6 @@ def receive():
|
|||||||
thread = threading.Thread(target=client.handle, name=client.id[:8])
|
thread = threading.Thread(target=client.handle, name=client.id[:8])
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
receive()
|
receive()
|
||||||
|
|||||||
Reference in New Issue
Block a user