Advertisement Create a free account

[Script] isGM(id) function. Auto-populated.

1402457840

Edited 1407497652
The Aaron
Forum Champion
API Scripter
This script creates a function, isGM(id) , which is accessible by other scripts to identify players vs. GMs. GM info is automatically collected by comparing the msg.who from non-api messages to the player._displayname. Since non-api chat messages append ' (GM)' to GMs in msg.who , comparing the two will only be equal if a player is NOT a gm. ( This works regardless of if the player adds '(GM)' to their name. ) Once each player has said something in chat, they well all be identified as GM or not. isGM(id) only checks who is in the list of GMs, so even unidentified players who issue api commands that depend on the function will be denied. ( GMs should be sure to say something once after installing the script or calling !reset-isgm . ) Messages are only considered while there are unknown players. Data is cached in the state object (in a sub object named IsGM). Players that are added after the state is setup will be added to the list of unknown players on restart of the javascript sandbox. If players are promoted to GM status after being identified as players, the state can be reset with the !reset-isgm command. In the case where no GM is identified, the state can be rest with a password. ( Instructions are provided in the reply message from the !reset-isgm command. Even if players were able to reset the state, they would still not be allowed GM access. ) Usage Example : if( isGM( msg.playerid ) ) { sendChat('','/w '+msg.who+' you are a GM!'); } else { sendChat('','/w '+msg.who+' you are NOT GM!'); } GIST: <a href="https://gist.github.com/shdwjk/8d5bb062abab1846362" rel="nofollow">https://gist.github.com/shdwjk/8d5bb062abab1846362</a>...
1402543976

Edited 1402544000
The Aaron
Forum Champion
API Scripter
I just fixed a bug that would cause players initially speaking as a character to be misidentified as a GM. The script now verifies that players are speaking as themselves before identifying them as a GM. Please download the latest version from the gist.
1402585076
The Aaron
Forum Champion
API Scripter
Just out of curiosity, is there any community interest in a more fine-grained permission system? Possibly something where a GM can grant a named permission to a collection of players, allowing them to use associated commands? &gt; !grant Bob turn-order And in an API script: if(hasPermission('turn-order',msg.playerid)) { // allow some operation on turn order to occur } That kind of thing.
1402589526
Brian
Sheet Author
API Scripter
I'm certain somebody could make use of such a permissions system.
1402589890
The Aaron
Forum Champion
API Scripter
Cool. Anyone have specific requirements or use cases or more complex permission needs?
1402603856
Brian
Sheet Author
API Scripter
Prototyping the permission check onto the Roll20 object would be neat (player.hasPermission(...) instead of hasPermission(..., player)), but I don't think that's possible for us. has, hasAny, hasAll, hasNone would be useful convenience functions to avoid potentially long conditionals.
1402604892
The Aaron
Forum Champion
API Scripter
Adding a function to the player prototype would be cool. I agree on the convenience functions. Probably some rudimentary matching would be nice.
1402605981
Brian
Sheet Author
API Scripter
Just did a quick test; it seems the Roll20 objects are defined using anonymous functions (player.constructor.name == ""), which as far as I'm aware means it's not possible to extend with prototype.
1402624493
The Aaron
Forum Champion
API Scripter
Yeah, I actually confirmed that before replying as well. I'm pretty sure there isn't a way of doing it.
1406073825
The Aaron
Forum Champion
API Scripter
Here's a suggestion for making sure your script tells people if they don't have the isGM module installed: on('ready', function() { var Has_IsGM=false, scriptName='MyScript'; try { _.isFunction(isGM); Has_IsGM=true; } catch (err) { log('--------------------------------------------------------------'); log( scriptName + 'requires the isGM module to work.'); log('isGM GIST: <a href="https://gist.github.com/shdwjk/8d5bb062abab184636" rel="nofollow">https://gist.github.com/shdwjk/8d5bb062abab184636</a>... log('--------------------------------------------------------------'); } if( Has_IsGM ){ // perform initialization code } });
1407474387
Hi. I'm a complete noob at all the API stuff and could use a few pointers since your other script for turn markers interested me a lot (I actually have no idea what this one here does). But yeah thing is when I get this one in my API box I get an error that says " document is not defined "... Could you help me out? Thanks man!
1407483721
BoomerET
KS Backer
Try this link, the two links here seem to be messed up, at least when I click on them they are. isGM
1407497929

Edited 1407498047
The Aaron
Forum Champion
API Scripter
Thanks BoomerET for jumping in and helping! That's weird about that link not working. I've updated the link above. Zentsuki, to answer your question about what this does: It handles the task of determining if someone is a GM. There isn't a way in the API to determine this. People have come up with various ways of doing it in the past, such as adding people as owners of a particular journal file or maintaining a manually entered list of IDs for people that are GMs. This script doesn't require any of that to determine if a player is a GM, it only requires them to speak as themselves once, and it will know if they are a GM or not based on information the API gets from that message. Rather than duplicate the same logic across all my scripts, I just have them all use this script for that determination. Let me know if you have any other problems!
1407559911
BoomerET
KS Backer
Glad to help, your stuff works so well I don't want anyone to be left out in the cold &lt;grin&gt;
1407589724
The Aaron
Forum Champion
API Scripter
Thanks! :D
1407730712
Thanks! I'm gonna have fun with that.