Skip to content

Commit 6f806c0

Browse files
authored
Merge pull request #5 from Tiger-Tom/version-2.1
QOL Update 2.1
2 parents ed150c0 + f29a7f4 commit 6f806c0

2 files changed

Lines changed: 57 additions & 15 deletions

File tree

Changelog.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
From release 2.0 to QOL 2.1:
2+
3+
Additions:
4+
- Help file will now no longer be updated if the newer version is for a newer version of the program
5+
- Antimalware scan command, using Windows Defender on Windows, and ClamAV on Linux
6+
7+
Changes:
8+
- "AutoClean" subcommand of the upgrade command now also runs "sudo apt-get autoremove"
9+
10+
Removals:
11+
- Removed "PIP" subcommand of the upgrade command, because it wasn't useful or needed
12+
13+
--------------------------------------------------
14+
115
From bugfix 1.1 to release 2.0:
216

317
Additions:

RunServer.py

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def runWFullOutput(cmd, callbackFunc, callbackFuncXtraArgs=[]): #Runs a system c
9494
while True:
9595
out = proc.stdout.readline().decode('UTF-8', 'replace')
9696
if not len(out): break #If there is no output
97-
callbackFunc(out, *callbackFuncXtraArgs)
97+
callbackFunc(out.lstrip().rstrip(), *callbackFuncXtraArgs)
9898
def runWCallback(callbackFunc, cmd): #Runs a system command and waits for it to finish, and then runs "callbackFunc" with the output as an argument
9999
callbackFunc(runWOutput(cmd))
100100
def asyncRunWCallback(callbackFunc, cmd): #Runs a system command with a callback, but asynchronously
@@ -212,17 +212,20 @@ def getOutput(process): #Prints all of the process' buffered STDOUT (decoded it
212212
if not os.path.exists(cacheDir): os.mkdir(cacheDir)
213213

214214
# Auto-update
215-
def autoUpdate():
216-
print ('Checking for a new release...')
217-
latestRelease = json.loads(getFileFromServer('https://api.github.com/repos/Tiger-Tom/RunServerDotPy/releases/latest'))
218-
latestID = float(latestRelease['tag_name'].replace('v', ''))
219-
if not os.path.exists(cacheDir+'/version.txt'): currentID = -1.0
215+
def getVersion():
216+
if not os.path.exists(cacheDir+'version.txt'): currentID = -1.0
220217
else:
221-
with open(cacheDir+'/version.txt') as f:
218+
with open(cacheDir+'version.txt') as f:
222219
try:
223220
currentID = float(f.read().rstrip())
224221
except:
225222
currentID = -1.0
223+
return currentID
224+
def autoUpdate():
225+
print ('Checking for a new release...')
226+
latestRelease = json.loads(getFileFromServer('https://api.github.com/repos/Tiger-Tom/RunServerDotPy/releases/latest'))
227+
latestID = float(latestRelease['tag_name'].replace('v', ''))
228+
currentID = getVersion()
226229
print ('Current release: '+str(currentID))
227230
print ('Newest availiable release: '+str(latestID))
228231
if currentID >= latestID:
@@ -241,7 +244,7 @@ def autoUpdate():
241244
f.write(i.decode('UTF-8')+'\n')
242245
print ('Update written')
243246
print ('Writing version tag...')
244-
with open(cacheDir+'/version.txt', 'w') as f:
247+
with open(cacheDir+'version.txt', 'w') as f:
245248
f.write(str(latestID))
246249
print ('Closing self to open new version...')
247250
try:
@@ -518,13 +521,21 @@ def parseChat(line): #Get the chat / /me / /say message and username out of a co
518521

519522
# Help variables (help text keys in-game will be organized by the order by they are defined)
520523
rewriteHelp = False
521-
if not os.path.exists(cacheDir+'/help/'): os.mkdir(cacheDir+'/help/') #Create help cache directory if it doesn't exist
524+
if not os.path.exists(cacheDir+'help/'): os.mkdir(cacheDir+'help/') #Create help cache directory if it doesn't exist
522525
if not os.path.exists(cacheDir+'help/version.txt'): #Create help version file if it doesn't exist
523526
with open(cacheDir+'help/version.txt', 'w') as f:
524527
rewriteHelp = True
525528
if not rewriteHelp: #Compare current help version with newest help version
526529
with open(cacheDir+'help/version.txt') as f:
527-
if int(f.read()) < int(getFileFromServer('https://raw.githubusercontent.com/Tiger-Tom/RunServerDotPy-extras/main/Help/Version')): rewriteHelp = True
530+
newVer = getFileFromServer('https://raw.githubusercontent.com/Tiger-Tom/RunServerDotPy-extras/main/Help/Version').rstrip().split('/')
531+
curVer = f.read().rstrip().split('/')[1]
532+
print ('Current help version: '+str(getVersion())+'/'+str(curVer)+'\nNewest help version: '+('/'.join(newVer)))
533+
if getVersion() < float(newVer[0]):
534+
rewriteHelp = False
535+
print ('Did not update help file, as current program version is outdated anyways')
536+
elif float(curVer) < float(newVer[1]):
537+
rewriteHelp = True
538+
print ('Help file needs updating, current version is out of date')
528539
if rewriteHelp: #Update cached help JSON to latest version
529540
with open(cacheDir+'help/ChatCommandsHelp.json', 'w') as f:
530541
f.write(getFileFromServer('https://raw.githubusercontent.com/Tiger-Tom/RunServerDotPy-extras/main/Help/ChatCommandsHelp.json'))
@@ -716,6 +727,26 @@ def runChatCommand(cmd, args, user):
716727
def runAdminChatCommand(cmd, args, user):
717728
tellRaw('Running SuperUser ChatCommand '+cmd, '$'+user, user)
718729
if cmd == 'help': cc_help(chatCommandsHelpAdmin, args, chatComPrefix+'sudo', user) #Display a list of admin commands, or information on a specific one if specified in arguments
730+
elif cmd in {'antimalware', 'antivirus', 'scan'}:
731+
tellRaw('Operating system: '+os.name, 'AntiMal')
732+
if os.name == 'nt':
733+
tellRaw('Scanner: Windows Defender', 'AntiMal')
734+
comm = '"%ProgramFiles%/Windows Defender/MpCmdRun.exe" -Scan'
735+
else:
736+
tellRaw('Scanner: ClamAV', 'AntiMal')
737+
if shutil.which('clamscan') == None: #ClamAV is not installed, so install it
738+
comm = 'sudo apt-get install clamav libfreshclam'
739+
tellRaw(comm)
740+
runWFullOutput(comm, tellRaw)
741+
os.system('sudo systemctl stop clamav-freshclam.service')
742+
os.system('sudo systemctl disable clamav-freshclam.service')
743+
comm = 'sudo freshclam'
744+
tellRaw(comm)
745+
runWFullOutput(comm, tellRaw)
746+
comm = 'sudo clamscan --quiet -r /'
747+
tellRaw(comm)
748+
asyncRunWCallback(tellRaw, comm)
749+
tellRaw('This will last a while. The results will be displayed once the scan is complete', 'AntiMal')
719750
elif cmd == 'ban': #Bans a user for (optional) reason. Uses the in-game /ban command
720751
if len(args) > 1: tellRaw('Banning '+args[0]+' for '+(' '.join(args[1:])), 'Ban', user)
721752
else: tellRaw('Banning '+args[0], 'Ban', user)
@@ -803,13 +834,10 @@ def runAdminChatCommand(cmd, args, user):
803834
cmd = 'yes | sudo apt-get autoclean'
804835
tellRaw(cmd)
805836
runWFullOutput(cmd, tellRaw)
806-
tellRaw('Done', 'AutoClean')
807-
if 'pip' in args:
808-
tellRaw('Updating PIP packages...', 'PIP')
809-
cmd = sys.executable+' -m pip list --outdated --format=freeze | grep -v \'^\\-e\' | cut -d = -f 1e'
837+
cmd = 'yes | sudo apt-get autoremove'
810838
tellRaw(cmd)
811839
runWFullOutput(cmd, tellRaw)
812-
tellRaw('Done', 'PIP')
840+
tellRaw('Done', 'AutoClean')
813841
del cmd
814842
else: tellRaw('Unknown command "'+cmd+'", sorry', 'OPCCmd', user)
815843

0 commit comments

Comments
 (0)