Skip to content

Commit

Permalink
Hotfix for Controller/Target AMP Setups.
Browse files Browse the repository at this point in the history
Fixed requirements.txt having Pycord (oops)
Removed Indexing on AMP Instances.
Fixed startup times for Bot Permissions validation.
Fixed issue with url Validation. Removed auto correction.
*This may break some peoples AMP urls.
  • Loading branch information
k8thekat committed Nov 19, 2022
1 parent e3ce622 commit c3617d0
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 47 deletions.
67 changes: 34 additions & 33 deletions AMP.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ def val_settings(self):

import tokens
self.tokens = tokens
if not tokens.AMPurl.startswith('http://'):
self.logger.critical('** Please Append "http://" at the start of your AMPurl.')
if not tokens.AMPurl.startswith('http://') and not tokens.AMPurl.startswith('https://'):
self.logger.critical('** Please Verify your AMP Url **')
reset = True

if tokens.AMPurl.endswith('/') or tokens.AMPurl.endswith('\\'):
tokens.AMPurl = tokens.AMPurl.replace('/','').replace('\\','')
# if tokens.AMPurl.endswith('/') or tokens.AMPurl.endswith('\\'):
# tokens.AMPurl = tokens.AMPurl.replace('/','').replace('\\','')

if len(tokens.AMPAuth) < 7:
if tokens.AMPAuth == '':
Expand Down Expand Up @@ -166,7 +166,7 @@ def getAMPHandler(args:bool=False)-> AMPHandler:

class AMPInstance:
"""Base class for AMP"""
def __init__(self, instanceID=0, serverdata={}, Index=0, default_console=False, Handler=None):
def __init__(self, instanceID=0, serverdata={}, default_console=False, Handler=None):
self.Initialized = False

self.logger = logging.getLogger()
Expand All @@ -180,7 +180,7 @@ def __init__(self, instanceID=0, serverdata={}, Index=0, default_console=False,
self.DBConfig = self.DB.GetConfig()

self.SessionID = 0
self.Index = Index
#self.Index = Index
self.serverdata = serverdata
self.serverlist = {}

Expand Down Expand Up @@ -275,7 +275,8 @@ def __init__(self, instanceID=0, serverdata={}, Index=0, default_console=False,
#Not the main AMP Instance and the Bot Role Exists and we have the discord_bot role and we have super also!
if instanceID != 0 and self.AMP_BotRoleID != None and self.AMP_BotRoleID in self.AMP_userinfo['result']['Roles'] and self.super_AdminID in self.AMP_userinfo['result']['Roles']:
self.logger.warning(f'***ATTENTION*** `discord_bot` role exists and we have `Super Admins` - Setting up Instance permissions for {self.FriendlyName}')
self.setup_AMPpermissions()
if not self.check_AMPpermissions():
self.setup_AMPpermissions()

else:
self.logger.critical(f'***ATTENTION*** We are missing permissions for {self.APIModule} on {self.FriendlyName}! Please consider giving us `Super Admins` and the bot will set its own permissions and role!')
Expand Down Expand Up @@ -324,7 +325,7 @@ def check_AMPpermissions(self):
if self.APIModule == 'AMP':
self.logger.warning(f'The Bot is missing the permission {perm} Please check under Configuration -> User Management for the Bot.')
else:
end_point = self.AMPHandler.tokens.AMPurl.find(":",5)
end_point = self.AMPHandler.tokens.AMPurl.find(":", 5)
self.logger.warning(f'The Bot is missing the permission {perm} Please visit {self.AMPHandler.tokens.AMPurl[:end_point]}:{self.Port} under Configuration -> Role Management -> discord_bot')
failed = True

Expand All @@ -342,7 +343,7 @@ def __getattribute__(self, __name: str):
if self.Initialized and (self.InstanceID != 0) and __name in self.serverdata:
self.AMPHandler.AMP._updateInstanceAttributes()

return super().__getattribute__(__name)
return super().__getattribute__(__name)


def _setDBattr(self):
Expand Down Expand Up @@ -554,34 +555,34 @@ def getInstances(self):
parameters = {}
result = self.CallAPI('ADSModule/GetInstances',parameters)
serverlist = {}

if len(result["result"][0]['AvailableInstances']) != 0:

self.AMPHandler.InstancesFound = True
for i in range(0,len(result["result"][0]['AvailableInstances'])): #entry = name['result']['AvailableInstances'][0]['InstanceIDs']
instance = result["result"][0]['AvailableInstances'][i]

#This exempts the AMPTemplate Gatekeeper *hopefully*
flag_reg = re.search("(gatekeeper)", instance['FriendlyName'].lower())
if flag_reg != None:
if flag_reg.group():
continue

if instance['Module'] == 'ADS':
continue
for Target in result["result"]:
self.AMPHandler.InstancesFound = True
for amp_instance in Target['AvailableInstances']: #entry = name['result']['AvailableInstances'][0]['InstanceIDs']
#instance = result["result"][0]['AvailableInstances'][i]

#This exempts the AMPTemplate Gatekeeper *hopefully*
flag_reg = re.search("(gatekeeper)", amp_instance['FriendlyName'].lower())
if flag_reg != None:
if flag_reg.group():
continue

if amp_instance['Module'] == 'ADS':
continue

table_field = 'DisplayImageSource'
if instance[table_field] in self.AMPHandler.AMP_Modules:
name = str(self.AMPHandler.AMP_Modules[instance[table_field]]).split("'")[1]
self.logger.dev(f'Loaded __{name}__ for {instance["FriendlyName"]}')
#def __init__(self, instanceID = 0, serverdata = {}, Index = 0, default_console = False, Handler = None):
server = self.AMPHandler.AMP_Modules[instance[table_field]](instance['InstanceID'],instance,i,self.AMPHandler)
serverlist[server.InstanceID] = server
table_field = 'DisplayImageSource'
if amp_instance[table_field] in self.AMPHandler.AMP_Modules:
name = str(self.AMPHandler.AMP_Modules[amp_instance[table_field]]).split("'")[1]
self.logger.dev(f'Loaded __{name}__ for {amp_instance["FriendlyName"]}')
#def __init__(self, instanceID = 0, serverdata = {}, Index = 0, default_console = False, Handler = None):
server = self.AMPHandler.AMP_Modules[amp_instance[table_field]](amp_instance['InstanceID'],amp_instance,self.AMPHandler)
serverlist[server.InstanceID] = server

else:
self.logger.dev(f'Loaded __AMP_Generic__ for {instance["FriendlyName"]}')
server = self.AMPHandler.AMP_Modules['Generic'](instance['InstanceID'],instance,i,self.AMPHandler)
serverlist[server.InstanceID] = server
else:
self.logger.dev(f'Loaded __AMP_Generic__ for {amp_instance["FriendlyName"]}')
server = self.AMPHandler.AMP_Modules['Generic'](amp_instance['InstanceID'],amp_instance,self.AMPHandler)
serverlist[server.InstanceID] = server

return serverlist

Expand Down
4 changes: 2 additions & 2 deletions modules/Counter-Strike_Go/amp_csgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

DisplayImageSources = ['steam:730']
class AMPCsgo(AMP.AMPInstance):
def __init__(self, instanceID = 0, serverdata = {},Index = 0,Handler=None):
def __init__(self, instanceID = 0, serverdata = {},Handler=None):
self.perms = []
self.APIModule = 'Counterstrike_GO'

super().__init__(instanceID,serverdata,Index,Handler=Handler)
super().__init__(instanceID, serverdata, Handler=Handler)
self.Console = AMPCsgoConsole(AMPInstance = self)

self.default_background_banner_path = 'resources/banners/CS_Go_Banner_3.png'
Expand Down
4 changes: 2 additions & 2 deletions modules/Factorio/amp_factorio.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@

DisplayImageSources = ['steam:427520']
class AMPFactorio(AMP.AMPInstance):
def __init__(self, instanceID = 0, serverdata = {},Index = 0,Handler=None):
def __init__(self, instanceID = 0, serverdata = {},Handler=None):
self.perms = []
self.APIModule = 'Factorio'

super().__init__(instanceID,serverdata,Index,Handler=Handler)
super().__init__(instanceID,serverdata, Handler=Handler)
self.Console = AMPFactorioConsole(AMPInstance = self)

self.default_background_banner_path = 'resources/banners/Factorio_Banner.jpg'
Expand Down
4 changes: 2 additions & 2 deletions modules/Generic/amp_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

DisplayImageSources = ['Generic']
class AMPGeneric(AMP.AMPInstance):
def __init__(self, instanceID = 0, serverdata = {},Index = 0,Handler=None):
def __init__(self, instanceID = 0, serverdata = {},Handler=None):
self.APIModule = 'Generic'

super().__init__(instanceID,serverdata,Index,Handler=Handler)
super().__init__(instanceID, serverdata, Handler=Handler)
self.Console = AMPGenericConsole(AMPInstance = self)

self.default_background_banner_path = 'resources/banners/AMP_Banner.jpg'
Expand Down
4 changes: 2 additions & 2 deletions modules/Minecraft/amp_minecraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
DisplayImageSources = ["internal:MinecraftJava"]
class AMPMinecraft(AMP.AMPInstance):
"""This is Minecraft Specific API calls for AMP"""
def __init__(self, instanceID = 0, serverdata = {},Index = 0, Handler=None):
def __init__(self, instanceID = 0, serverdata = {}, Handler=None):
self.perms = ['Minecraft.*','Minecraft.InGameActions.*','-Minecraft.PluginManagement.*']
self.APIModule = 'MinecraftModule' #This is what AMP API calls the Module in the Web GUI API Documentation Browser


super().__init__(instanceID, serverdata, Index,Handler= Handler)
super().__init__(instanceID, serverdata,Handler= Handler)
self.Console = AMPMinecraftConsole(self)

self.default_background_banner_path = 'resources/banners/Minecraft_banner.png'
Expand Down
4 changes: 2 additions & 2 deletions modules/StarBound/amp_starbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

DisplayImageSources = ['steam:211820']
class AMPStarbound(AMP.AMPInstance):
def __init__(self, instanceID = 0, serverdata = {},Index = 0,Handler=None):
def __init__(self, instanceID = 0, serverdata = {}, Handler=None):
self.perms = []
self.APIModule = 'Starbound'

super().__init__(instanceID,serverdata,Index,Handler=Handler)
super().__init__(instanceID,serverdata, Handler=Handler)
self.Console = AMPStarboundConsole(AMPInstance = self)

self.default_background_banner_path = 'resources/banners/Starbound_banner.jpg'
Expand Down
4 changes: 2 additions & 2 deletions modules/Terraria/amp_terraria.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
#Resources - https://www.dexerto.com/gaming/terraria-console-commands-explained-a-simple-controls-guide-1663852/
DisplayImageSources = ['steam:105600']
class AMPTerraria(AMP.AMPInstance):
def __init__(self, instanceID = 0, serverdata = {},Index = 0,Handler=None):
def __init__(self, instanceID = 0, serverdata = {} ,Handler=None):
self.perms = []
self.APIModule = 'Terraria'

super().__init__(instanceID,serverdata,Index,Handler=Handler)
super().__init__(instanceID,serverdata, Handler=Handler)
self.Console = AMPTerrariaConsole(AMPInstance = self)

self.default_background_banner_path = 'resources/banners/Terraria_Banner.png'
Expand Down
4 changes: 2 additions & 2 deletions modules/Valheim/amp_valheim.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

DisplayImageSources = ['steam:892970']
class AMPValheim(AMP.AMPInstance):
def __init__(self, instanceID = 0, serverdata = {},Index = 0,Handler=None):
def __init__(self, instanceID = 0, serverdata = {}, Handler=None):
self.perms = []
self.APIModule = 'Valheim'

super().__init__(instanceID,serverdata,Index,Handler=Handler)
super().__init__(instanceID,serverdata, Handler=Handler)
self.Console = AMPValheimConsole(AMPInstance = self)

self.default_background_banner_path = 'resources/banners/Valheim_Banner.png'
Expand Down
Binary file modified requirements.txt
Binary file not shown.

0 comments on commit c3617d0

Please sign in to comment.