From 3657fbd8d20138287f596b07ecb7c1b9f8e31ccd Mon Sep 17 00:00:00 2001 From: xfnw Date: Tue, 13 Oct 2020 11:22:00 -0400 Subject: [PATCH] allow some connections to be disconnected without effecting other connections --- bot.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index 1b7864b..832a6d2 100755 --- a/bot.py +++ b/bot.py @@ -6,6 +6,9 @@ from irctokens import build, Line from ircrobots import Bot as BaseBot from ircrobots import Server as BaseServer from ircrobots import ConnectionParams +# aaaaaaaaaaaaaAAAAAAAAAAAAAAA +# im too lazy to import more stuffs :tm: +from ircrobots.server import * SERVERS = [ ("freenode", "chat.freenode.net", 6697, True), @@ -17,6 +20,31 @@ SERVERS = [ ] class Server(BaseServer): + + # overwrite connect so i can put try except blocks there + async def connect(self, + transport: ITCPTransport, + params: ConnectionParams): + try: + await sts_transmute(params) + await resume_transmute(params) + + reader, writer = await transport.connect( + params.host, + params.port, + tls =params.tls, + tls_verify=params.tls_verify, + bindhost =params.bindhost) + + self._reader = reader + self._writer = writer + + self.params = params + await self.handshake() + except: + print('connection with {} failed, disconnecting'.format(self.name)) + self.disconnected = True + async def line_read(self, line: Line): print(f"{self.name} < {line.format()}") if line.command == "001": @@ -36,7 +64,7 @@ class Server(BaseServer): async def line_send(self, line: Line): print(f"{self.name} > {line.format()}") async def bc(self,name,nick,msg): - if name == self.name or "chan" not in list(dir(self)): + if not self.disconnected and name == self.name or "chan" not in list(dir(self)): return await self.send(build("PRIVMSG",[self.chan,"<"+nick+"@"+name+"> "+msg]))