mirror of
https://github.com/TotalFreedomMC/TotalFreedomBot.git
synced 2024-12-22 23:54:58 +00:00
Update telnet.py
This commit is contained in:
parent
db2dea30a3
commit
3cf508e575
1 changed files with 20 additions and 33 deletions
49
telnet.py
49
telnet.py
|
@ -1,38 +1,25 @@
|
||||||
import discord
|
|
||||||
import time
|
import time
|
||||||
|
import checks
|
||||||
|
|
||||||
from telnetlib import Telnet
|
from telnetlib import Telnet
|
||||||
from discord.ext import commands
|
|
||||||
|
|
||||||
class telnet(commands.Cog):
|
class telnet():
|
||||||
def __init__(self, bot):
|
def __init__(self, ip, port, username, password):
|
||||||
self.bot = bot
|
self.ip = ip
|
||||||
self.ip = [ip]
|
self.port = port
|
||||||
self.telnet_port = [port]
|
self.password = password
|
||||||
self.telnet_password = [password]
|
self.username = username
|
||||||
|
|
||||||
self.bot.telnet_session = Telnet(self.ip, self.telnet_port)
|
def connect(self, *username):
|
||||||
self.read_timeout = 3
|
self.session = Telnet(self.ip, self.port)
|
||||||
if b'Username:' in self.bot.telnet_session.read_until(b'Username:', timeout=self.read_timeout):
|
for x in username:
|
||||||
self.bot.telnet_session.write(bytes('TotalFreedom', 'ascii') + b"\r\n")
|
self.username = username[0]
|
||||||
|
|
||||||
if b'Password:' in self.bot.telnet_session.read_until(b'Password:', timeout=self.read_timeout):
|
if b'Username:' in self.session.read_until(b'Username:', timeout = 3):
|
||||||
time.sleep(2)
|
time.sleep(0.5)
|
||||||
self.bot.telnet_session.write(bytes(self.telnet_password, 'ascii') + b"\r\n")
|
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:
|
else:
|
||||||
raise PyboardError('Failed to establish a telnet connection with the board')
|
raise ConnectionError('Failed to establish telnet connection.')
|
||||||
|
|
||||||
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')
|
|
||||||
|
|
||||||
def setup(bot):
|
|
||||||
bot.add_cog(telnet(bot))
|
|
||||||
|
|
Loading…
Reference in a new issue