Skip to content

Commit

Permalink
Merge pull request #316 from sepalani/gs_message
Browse files Browse the repository at this point in the history
create_gamespy_message refactored
  • Loading branch information
AdmiralCurtiss committed Jul 31, 2016
2 parents 89495ca + f77afa3 commit f3339f8
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions gamespy/gs_query.py
Expand Up @@ -123,26 +123,21 @@ def create_gamespy_message_from_list(messages):

def create_gamespy_message(messages, id=None):
"""Create a message based on a dictionary (or list) of parameters."""
query = ""

if isinstance(messages, dict):
messages = create_gamespy_message_from_dict(messages)

# Check for an id if the id needs to be updated.
# If it already exists in the list then update it, else add it
if id is not None:
for message in messages:
for i, message in enumerate(messages):
# If it already exists in the list then update it
if message[0] == "id":
messages.pop(messages.index(message))
messages.append(("id", str(id)))
id = None # Updated id, so don't add it to the query later
break # Found id, stop searching list
messages[i] = ("id", str(id))
break
else:
# Otherwise, add it in the list
messages.append(("id", str(id)))

query = create_gamespy_message_from_list(messages)

if id is not None:
query += create_gamespy_message_from_list([("id", id)])

query += "\\final\\"

return query

0 comments on commit f3339f8

Please sign in to comment.