From 3cf508e575ac518bb1222387c0381cf10290e131 Mon Sep 17 00:00:00 2001 From: Elmon11 Date: Sat, 31 Oct 2020 03:06:25 +0100 Subject: [PATCH] Update telnet.py --- telnet.py | 53 ++++++++++++++++++++--------------------------------- 1 file changed, 20 insertions(+), 33 deletions(-) diff --git a/telnet.py b/telnet.py index d6955cc..73519f8 100644 --- a/telnet.py +++ b/telnet.py @@ -1,38 +1,25 @@ -import discord import time +import checks from telnetlib import Telnet -from discord.ext import commands -class telnet(commands.Cog): - def __init__(self, bot): - self.bot = bot - self.ip = [ip] - self.telnet_port = [port] - self.telnet_password = [password] - - self.bot.telnet_session = Telnet(self.ip, self.telnet_port) - self.read_timeout = 3 - if b'Username:' in self.bot.telnet_session.read_until(b'Username:', timeout=self.read_timeout): - self.bot.telnet_session.write(bytes('TotalFreedom', 'ascii') + b"\r\n") - - if b'Password:' in self.bot.telnet_session.read_until(b'Password:', timeout=self.read_timeout): - time.sleep(2) - self.bot.telnet_session.write(bytes(self.telnet_password, 'ascii') + b"\r\n") - else: - raise PyboardError('Failed to establish a telnet connection with the board') - - def connect(): - self.bot.telnet_session = Telnet(self.ip, self.telnet_port) - self.read_timeout = 3 - if b'Username:' in self.bot.telnet_session.read_until(b'Username:', timeout=self.read_timeout): - self.bot.telnet_session.write(bytes('TotalFreedom', 'ascii') + b"\r\n") - - if b'Password:' in self.bot.telnet_session.read_until(b'Password:', timeout=self.read_timeout): - time.sleep(2) - self.bot.telnet_session.write(bytes(self.telnet_password, 'ascii') + b"\r\n") - else: - raise PyboardError('Failed to establish a telnet connection with the board') +class telnet(): + def __init__(self, ip, port, username, password): + self.ip = ip + self.port = port + self.password = password + self.username = username -def setup(bot): - bot.add_cog(telnet(bot)) + def connect(self, *username): + self.session = Telnet(self.ip, self.port) + for x in username: + self.username = username[0] + + if b'Username:' in self.session.read_until(b'Username:', timeout = 3): + time.sleep(0.5) + self.session.write(bytes(self.username, 'ascii') + b"\r\n") + if b'Password:' in self.session.read_until(b'Password:', timeout = 3): + time.sleep(0.5) + self.session.write(bytes(self.password, 'ascii') + b"\r\n") + else: + raise ConnectionError('Failed to establish telnet connection.')