Skip to content

Commit 97b09c6

Browse files
authored
Setup bot added
Not tested, meant to replace steps 8-9 of installation.
1 parent ba255ca commit 97b09c6

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

setup.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# SysBot.py setup tool
2+
3+
import asyncio
4+
import os
5+
6+
# Install requirements.txt
7+
print("Installing required modules.")
8+
try:
9+
os.system('python -m pip -r requirements.txt')
10+
except Exception as e:
11+
print(f"Unable to install requirements: {e}")
12+
13+
import discord
14+
from discord.ext import commands
15+
from yaml import load
16+
import socket
17+
18+
# Load information from config.yaml
19+
with open("config.yaml") as file:
20+
data = load(file)
21+
token = data["token"]
22+
switchip = data["ip"]
23+
switchport = data["port"]
24+
25+
client = commands.Bot(description="SysBot.py Setup", intents=discord.Intents.all())
26+
27+
# Log into discord and connect to switch tests
28+
@client.event
29+
async def on_ready():
30+
print(f"Successfully connected to: {client.user.tag}")
31+
serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
32+
try:
33+
serv.connect((switchip, switchport))
34+
print(f"Successfully connected to {switchip}:{switchport}.")
35+
except socket.error:
36+
print(f"Unable to connect to {switchip}:{switchport}.\nClick here to follow the connection troubleshooting guide by the official sysbot team.\nhttps://github.com/kwsch/SysBot.NET/wiki/Troubleshooting-Connection-Errors\nEnsure you have sys-botbase installed on your switch.")
37+
await asyncio.sleep(5)
38+
print("Setup successful. Now closing setup.py...")
39+
await asyncio.sleep(5)
40+
client.logout()
41+
42+
try:
43+
client.run('{}'.format(token))
44+
except Exception as e:
45+
print(f"Error when logging in: {e}\n\n\nMake sure you have PRESENCE INTENT and SERVER MEMBERS INTENT turned on in the bot's settings page on the developer portal.")

0 commit comments

Comments
 (0)