Skip to content

Commit

Permalink
Merge pull request #51 from Pilot1782/dev-builds
Browse files Browse the repository at this point in the history
Dev builds
  • Loading branch information
Pilot1782 committed Jun 29, 2022
2 parents 7d55d9a + b548783 commit ec59933
Show file tree
Hide file tree
Showing 9 changed files with 356 additions and 1,365 deletions.
5 changes: 2 additions & 3 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
TOKEN=YOUR_TOKEN_HERE
PATH=C:\\Users\\Pilot1782\\Downloads\\bad_copenheimer\\
GUILDID=12345
PATH=D:\\Carson\\Programming\\Python_Stuff\\bad_copeheimer-main\\bad_copeheimer-main\\bad_copenheimer\\settings.json
GUILDID=12345
51 changes: 27 additions & 24 deletions dis-bot.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import os as osys
import subprocess
import json
import multiprocessing
from funcs import *
from funcs import funcs



Expand All @@ -17,9 +17,8 @@ settings_path = osys.getenv("PATH")
# Below this is preconfigured #
###############################

fncs = funcs(settings_path)


settings_path = osys.getenv("PATH")
# Varaible getting defeined
bot = interactions.Client(token=osys.getenv("TOKEN"))

Expand Down Expand Up @@ -65,7 +64,7 @@ try:
except Exception as e:
if e == PermissionError:
print(f"Please run as root, not as {subprocess.check_output('whoami',shell=True).decode('utf-8')}")
log(e)
fncs.log(e)
exit()


Expand All @@ -74,20 +73,21 @@ except Exception as e:
# Discord commands #
####################

fncs.dprint("Checking scan")
# Scan the large list
@bot.command(
name="server_scan",
description="scan some ips",
options = [
interactions.Option(
name="Ip Lower Bound",
description="The lower bound of the ip range",
name="lower_ip_bound",
description="Lower Ip Bound",
type=interactions.OptionType.STRING,
required=True,
),
interactions.Option(
name="Ip Upper Bound",
description="The upper bound of the ip range",
name="upper_ip_bound",
description="Upper Ip Bound",
type=interactions.OptionType.STRING,
required=True,
),
Expand All @@ -104,7 +104,7 @@ async def server_scan(ctx: interactions.CommandContext, ip_lower_bound: str, ip_

iplower = ip_lower_bound
ipupper = ip_upper_bound
log("Command: mc run" + iplower + "|" + ipupper)
fncs.log("Command: mc " + iplower + "|" + ipupper)

if ipupper != None:
lower_ip_bound = iplower
Expand All @@ -119,11 +119,12 @@ async def server_scan(ctx: interactions.CommandContext, ip_lower_bound: str, ip_
await ctx.send("Invalid IP")
exit()

for line in scan(lower_ip_bound, upper_ip_bound):
for line in fncs.scan(lower_ip_bound, upper_ip_bound):
await ctx.send(line)



fncs.dprint("Checking status")
# Scan the large list
@bot.command(
name="status",
description="Check the status of the given ip or check all in the json file",
Expand All @@ -145,7 +146,7 @@ async def status(ctx: interactions.CommandContext, ip: str):

if len(ip) > 0:
print(f"Scan of {ip} requested.")
log(f"Scan of {ip} requested.")
fncs.log(f"Scan of {ip} requested.")
for i in ip.split(" "):
try: #Try getting the status
from mcstatus import MinecraftServer
Expand All @@ -157,7 +158,7 @@ async def status(ctx: interactions.CommandContext, ip: str):
except Exception as err:
await ctx.send(f"Failed to scan {i}.\n")
print("Failed to scan {0}.\n{1}".format(i,err))
log(err)
fncs.log(err)

try: #Try quering server
from mcstatus import MinecraftServer
Expand All @@ -168,7 +169,7 @@ async def status(ctx: interactions.CommandContext, ip: str):
except Exception as err:
print(f"Failed to query {i}")
await ctx.send(f"Failed to query {i}.")
log(err)
fncs.log(err)
else:
with open(output_path) as json_file:
data = json.load(json_file)
Expand All @@ -195,18 +196,20 @@ async def status(ctx: interactions.CommandContext, ip: str):
er.append(str(e))
print("Failed to scan {0} due to {1} \n {2}:{3}".format(p, e, c, u))
c += 1
log(e)
fncs.log(e)
except Exception as err: #Catches all other errors
if not str(err) in er:
er.append(str(err))
print("Failed to scan {0} due to {1} \n {2}:{3}".format(p, err, c, u))
c += 1
log(err)
fncs.log(err)
er = list(set(er)) #Remove duplicates
er = "\n".join(er)
await ctx.send("Scanning finished.\n{1} out of {0} are up.\nThe following Errors occured:\n{2}".format(len(data), u, er))
print("Scanning finished.\n{1} out of {0} are up.\nThe following Errors occured:\n{2}".format(len(data), u, er))


fncs.dprint("Checking list")
#Help command
@bot.command(
name="help",
Expand All @@ -233,11 +236,11 @@ def startup():
# Print whether debugging and testing are active
if __name__ == "__main__":
print("Testing:{0}, Debugging:{1}\n".format(testing,debug))
log("Startup has been called, "+str(testing)+": testing and "+str(debug)+": debugging")
fncs.log("Startup has been called, "+str(testing)+": testing and "+str(debug)+": debugging")
try:
if testing:
flag = True
dprint("Starting bot...")
fncs.dprint("Starting bot...")
proc2 = multiprocessing.Process(target=startup,args=())
proc2.start()

Expand All @@ -246,8 +249,8 @@ if __name__ == "__main__":
else:
pypath = "python3"

dprint("Starting emergency bot...")
for line in run_command(r"{} stopper.pyw".format(pypath)):
fncs.dprint("Starting emergency bot...")
for line in fncs.run_command(r"{} stopper.pyw".format(pypath)):
print(line.decode("utf-8"))
if line.decode("utf-8") == "BAIL|A*(&HDO#QDH" and proc2.is_alive():
proc2.terminate()
Expand All @@ -257,7 +260,7 @@ if __name__ == "__main__":
proc2.join()
else:
flag = True
dprint("Starting bot...")
fncs.dprint("Starting bot...")
proc2 = multiprocessing.Process(target=startup,args=())
proc2.start()

Expand All @@ -266,8 +269,8 @@ if __name__ == "__main__":
else:
pypath = "python3"

dprint("Starting emergency bot...")
for line in run_command(r"{} stopper.pyw".format(pypath)):
fncs.dprint("Starting emergency bot...")
for line in fncs.run_command(r"{} stopper.pyw".format(pypath)):
print(line.decode("utf-8"))
if line.decode("utf-8") == "BAIL|A*(&HDO#QDH" and proc2.is_alive():
proc2.terminate()
Expand All @@ -277,4 +280,4 @@ if __name__ == "__main__":
proc2.join()
except Exception as err:
print("\n\nSorry, Execution of this file has failed, see the log for more details.\n")
log(err)
fncs.log(err)
Loading

0 comments on commit ec59933

Please sign in to comment.