Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update groups.groovy #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Update groups.groovy #3

wants to merge 1 commit into from

Conversation

DavidtKate
Copy link
Contributor

Group JSON files can now be read in as:

{
	"groups": [
		{
			"name": "<GROUPNAME>",
			"discordID": "<DISCORD_ID>",
			"swarmID": ["<SWARM_ID>", "<SWARM_ID>"],
			"type": "<GROUPTYPE>"
		}
	]
}

@DavidtKate
Copy link
Contributor Author

swarm.groovy also requires changes to GetGroupMembers

Comment on lines +46 to 52
if(discordID?.trim()) {
mentionString += "${tagTemplate.replace('[id]', discordID)}, ";
}

// Not needed anymore?
Remove trailing ', '
message = message.substring(0, message.length() - 2);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose the , at the end of the mention string might not be needed at all if this now tags a single Discord ID rather than a list of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea

Comment on lines +18 to +24
groupsParsed.groups.each { group ->
if (group.name == groupName)
{
groupType = group.type
discordID = group.discordID
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to break out of this loop prematurely?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking out of for-each loops in Groovy is illegal ([https://stackoverflow.com/questions/3049790/can-you-break-from-a-groovy-each-closure]). However using find ([https://www.tutorialspoint.com/groovy/groovy_find.htm]) we can break out of the loop prematurely using return true.

}
def groupType = ""
def discordID = ""
def groupsParsed = new JsonSlurper().parseText(groups)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't loadGroups already parse the groups?

If you're passing the full group json into this function, maybe split loadGroups up into loadGroupsFromFile and loadGroupsFromString, or have loadGroups return the json string rather than a parsed version. (This would also mean that saveGroups shouldn't convert the groups to json, as they would already be in that format).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah missed that function. I suppose we can remove loadGroups (and pass file as string as argument) or convert loadGroups to just reading in the file and parsing it using JsonSlurper and return the JsonObject.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants