Jump to content
McKay Development

Recommended Posts

12 hours ago, vrtgn said:

Check if the incoming message is only from those "group members" by using their steam ID 64.

can you code sample?

 

For example, I want to use the !help command only by people who are members of the group.
Link to post
Share on other sites
let groupMembers = [""] // an array containing steamid64's as strings of those group members

client.on('friendMessage', (steamID, message) => {
    if (groupMembers.includes(steamID.getSteamID64())) {
        // code here
    }
})

Alternatively you could ensure that the only people that can add the bot are the group members and then you wouldn't need the if statement. 

You may also want to get the group members using some method as if there are new ones you will have to add them manually and for convenience you should store their SteamID64 values in a file, perhaps a .json.  

Link to post
Share on other sites
client.on("friendMessage"function(steamIDmessage) {
if (message == "!help") {
                //code
        }
 
    } else if (message == "!info") {
 
 
I want to do I want only the members of the group to use the !help command.
 
I want people who are not members of the group to send a "you must be a member of the group" message
Link to post
Share on other sites

 

 

I'm sorry I couldn't understand what you said

 

not a steam chat room group people who add the steam bot must be a member of the group to use all commands

@vrtgn

 

and, i want people who are not members of the group to send a "you must be a member of the group" message

 
it starts like this
client.on("friendMessage"function(steamIDmessage) {
if (message == "!help") {
client.chatMessage(steamID"message);
}
    } else if (message == "!info") {
client.chatMessage(steamID"message");
 
..
..
..

 

how can i add as i said?

 

please help me

Link to post
Share on other sites
On 5/3/2020 at 11:10 AM, xLeeJYx said:

use getSteamGroup to get the group details and then getMembers to get the steamids of the members in your group. You can store the array somewhere in the code or anywhere u want it. Then check if the id is present in that array when a message is received

 

how can i do that can you help me please i need it

@xLeeJYx

Link to post
Share on other sites
const steamCommunity = require('steamcommunity');
const client = new steamUser();
let community = new SteamCommunity();
let groupmembers;
// https://steamcommunity.com/groups/reddit 's group name would be "reddit" as a string
// call getGroup on your code on client loggedOn event or somewhere else you want
function getGroup(groupName) {
    community.getSteamGroup(groupName, (err, group) => {
        if (err) {
            console.log("Couldn't get the Group Retrying");
            setTimeout(getGroup, 5000);
        } else group.getMembers((err, members) => {
            if (err) {
                console.log("Couldn't get the Group Retrying..");
                setTimeout(getGroup, 5000);
            } else {
                groupmembers = members;
            }
        });
    });
}

client.on("friendMessage", (steamID,msg) => {
  if(groupmembers.includes(steamID.getSteamID64())){
    //do your thing
  }
  else client.chatMessage(steamID,"You have to join our steam group bla bla to use this bot or idk");
});

this should work if you still have problems please let me know

Edited by Perport
Link to post
Share on other sites
12 hours ago, Perport said:
const steamCommunity = require('steamcommunity');
const client = new steamUser();
let community = new SteamCommunity();
let groupmembers;
// https://steamcommunity.com/groups/reddit 's group name would be "reddit" as a string
// call getGroup on your code on client loggedOn event or somewhere else you want
function getGroup(groupName) {
    community.getSteamGroup(groupName, (err, group) => {
        if (err) {
            console.log("Couldn't get the Group Retrying");
            setTimeout(getGroup, 5000);
        } else group.getMembers((err, members) => {
            if (err) {
                console.log("Couldn't get the Group Retrying..");
                setTimeout(getGroup, 5000);
            } else {
                groupmembers = members;
            }
        });
    });
}

client.on("friendMessage", (steamID,msg) => {
  if(groupmembers.includes(steamID.getSteamID64())){
    //do your thing
  }
  else client.chatMessage(steamID,"You have to join our steam group bla bla to use this bot or idk");
});

this should work if you still have problems please let me know

Cannot read property 'includes' of undefined

Link to post
Share on other sites
2 hours ago, Perport said:

Did you call the getGroup function ? Like

client.on("loggedOn",()=>{

getGroup("reddit");

}

if(groupmembers.includes(steamID.getSteamID64())){

 

I'm still getting this error :(

Cannot read property 'includes' of undefined

client.on('loggedOn', () => {
    getGroup("mygroupname");
    client.setPersona(SteamUser.EPersonaState.LookingToTrade);
    client.gamesPlayed(["Test Bot",730]);
});

let groupmembers;
function getGroup(groupName) {
    community.getSteamGroup(groupName, (err, group) => {
        if (err) {
            console.log("Couldn't get the Group Retrying");
            setTimeout(getGroup, 5000);
        } else group.getMembers((err, members) => {
            if (err) {
                console.log("Couldn't get the Group Retrying..");
                setTimeout(getGroup, 5000);
            } else {
                groupmembers = members;
            }
        });
    });
}

client.on("friendMessage", function(steamID, message) {
    if (message == "!test") {
    if(groupmembers.includes(steamID.getSteamID64())){
        client.chatMessage(steamID, "Test Message");
    }
    else client.chatMessage(steamID,"You have to join our steam group bla bla to use this bot or idk");
    }})

 

I did it this way but I get the error I said

Link to post
Share on other sites
5 hours ago, Emily said:
if(groupmembers.includes(steamID.getSteamID64())){

 

I'm still getting this error :(

Cannot read property 'includes' of undefined

client.on('loggedOn', () => {
    getGroup("mygroupname");
    client.setPersona(SteamUser.EPersonaState.LookingToTrade);
    client.gamesPlayed(["Test Bot",730]);
});

let groupmembers;
function getGroup(groupName) {
    community.getSteamGroup(groupName, (err, group) => {
        if (err) {
            console.log("Couldn't get the Group Retrying");
            setTimeout(getGroup, 5000);
        } else group.getMembers((err, members) => {
            if (err) {
                console.log("Couldn't get the Group Retrying..");
                setTimeout(getGroup, 5000);
            } else {
                groupmembers = members;
            }
        });
    });
}

client.on("friendMessage", function(steamID, message) {
    if (message == "!test") {
    if(groupmembers.includes(steamID.getSteamID64())){
        client.chatMessage(steamID, "Test Message");
    }
    else client.chatMessage(steamID,"You have to join our steam group bla bla to use this bot or idk");
    }})

 

I did it this way but I get the error I said

I justed tested it on a bigger group.

It takes about a minute or so to load it so I though printing it to a console would help.

Made the groupmembers var array from the beginning so it won't give you an error when someone types while it's still loading.

Fixed few things about what bot does when it fails to get the group or its members.

And made the array keep their accountids instead of steamid objects.

Here is the code :

client.on('loggedOn', () => {
    console.log("LoggedOn");
    getGroup("yourgroupname");
    client.setPersona(SteamUser.EPersonaState.LookingToTrade);
    client.gamesPlayed(["Test Bot", 730]);
});
let groupmembers = [];
function getGroup(groupName) {
    community.getSteamGroup(groupName, (err, group) => {
        if (err) {
            console.log("Couldn't get the Group Retrying");
            setTimeout((groupName) => { getGroup(groupName) }, 5000);
        } else group.getMembers((err, members) => {
            if (err) {
                console.log("Couldn't get the Group Retrying..");
                setTimeout((groupName) => { getGroup(groupName) }, 5000);
            } else {
                members.forEach(member => {
                    groupmembers.push(member.accountid);
                });
                console.log("Loaded The Group Members");
            }
        });
    });

}

client.on("friendMessage", function (steamID, message) {
    if (groupmembers.length > 0) {
        if (message == "!test") {
            if (groupmembers.includes(steamID.accountid)) {
                client.chatMessage(steamID, "Test Message");
            }
            else client.chatMessage(steamID, "You have to join our steam group bla bla to use this bot or idk");
        }
    }
    else {
        client.chatMessage(steamID, "bot is still loading message");
    }
});

If you still have problems or questions feel free to ask

Link to post
Share on other sites

 

Thank you man how long have I been looking for this code now the person who is a member of the group is using it, but there is another problem, when this person leaves the group, he still continues to use that command.

@Perport

 

and I can't use this command after joining the group

Link to post
Share on other sites
2 hours ago, Emily said:

 

Thank you man how long have I been looking for this code now the person who is a member of the group is using it, but there is another problem, when this person leaves the group, he still continues to use that command.

@Perport

 

and I can't use this command after joining the group

Then calling the getgroup function everytime someone messages you would help but probably slow down the response time but if you want to do it then this should work.

And you can remove the getGroup from loggedOn event.

 

function getGroup(groupName,callback) {
  groupmembers = [];
    community.getSteamGroup(groupName, (err, group) => {
        if (err) {
            console.log("Couldn't get the Group Retrying");
            setTimeout((groupName) => { getGroup(groupName,callback) }, 5000);
        } else group.getMembers((err, members) => {
            if (err) {
                console.log("Couldn't get the Group Retrying..");
                setTimeout((groupName) => { getGroup(groupName,callback) }, 5000);
            } else {
                members.forEach(member => {
                    groupmembers.push(member.accountid);
                });
              callback(groupmembers);
                console.log("Loaded The Group Members");
            }
        });
    });

}

client.on("friendMessage", function (steamID, message) {
	getGroup("yourGroupName",members => {
    	if (members.length > 0) {
        	if (message == "!test") {
            	if (members.includes(steamID.accountid)) {
                	client.chatMessage(steamID, "Test Message");
            	}
            	else client.chatMessage(steamID, "You have to join our steam group bla bla to use this bot or idk");
        	}
    	}
    	else {
        	client.chatMessage(steamID, "bot is still loading message");
    	}
    });
});

 

Link to post
Share on other sites
6 hours ago, Emily said:

 

ok ReferenceError: members is not defined i solved your mistake 

my current problem is that I want one command to use only group member, doesn't recognize other commands

I couldn't get that can you explain a little more ?

Link to post
Share on other sites

so i mean

function getGroup(groupName,callback) {
  groupmembers = [];
    community.getSteamGroup(groupName, (err, group) => {
        if (err) {
            console.log("Couldn't get the Group Retrying");
            setTimeout((groupName) => { getGroup(groupName,callback) }, 5000);
        } else group.getMembers((err, members) => {
            if (err) {
                console.log("Couldn't get the Group Retrying..");
                setTimeout((groupName) => { getGroup(groupName,callback) }, 5000);
            } else {
                members.forEach(member => {
                    groupmembers.push(member.accountid);
                });
              callback(groupmembers);
                console.log("Loaded The Group Members");
            }
        });
    });

}

client.on("friendMessage", function (steamID, message) {
	getGroup("mygroupname",members => {
    	if (members.length > 0) {
        	if (message == "!test") {
            	if (members.includes(steamID.accountid)) {
                	client.chatMessage(steamID, "Test Message");
            	}
            	else client.chatMessage(steamID, "You have to join our steam group");
        	}
    	}
    	else {
        	client.chatMessage(steamID, "bot is still loading message");
    	}

    } else if (message == "!help") {
        client.chatMessage(steamID, "Test Message");
      
          } else {
        client.chatMessage(steamID, "You wrote an unknown command. You can type !commands to learn commands.");
    }
        console.log("Message Sender steamID: " + steamID.getSteam3RenderedID() + ": " + message);
});

 

this is the sample code 

I can only use the first command, I want everyone to use the other commands, but other commands don't work

so !help doesn't work

I hope you understand thanks in advance <3

 

Link to post
Share on other sites
client.on("friendMessage", function (steamID, message) {
  if(message == "!test" || message == "!put these commands like this here you want only groupmembers to use" || message == "!anothercmd"){
	getGroup("mygroupname",members => {
    	if (members.length > 0) {
        	if (message == "!test") {
            	if (members.includes(steamID.accountid)) {
                	client.chatMessage(steamID, "Test Message");
            	}
            	else client.chatMessage(steamID, "You have to join our steam group");
        	}
            else if(message == "!membercmd2"){
             	// 
            }
    	}
    	else {
        	client.chatMessage(steamID, "bot is still loading message");
    	}

    });
  }
  else if(message == "!help"){
    
  }
  else if (message == "!idk"){
    
  }
  else{
    console.log("Unknown command type \"!help\" to see available commands")
  }
});

This should I might have made some mistakes here and there I'm currently on mobile so I can't test it so try it and let me know.

And Please indent this code or something it's starting to look weird.

Link to post
Share on other sites

 

Thank you I checked the coding again and corrected my shortcomings now everyone can use other commands

 

I have a question When the person leaves the group, he can still use that command, and someone who joins the group waits for a few minutes to use that command. Can we set this wait time?

so I don't want him to use the command instantly when he leaves the group

 

and the person joining the group should not wait, use that command directly

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...