Open Qzername opened 6 years ago
Issues isn't really for asking questions
roles are stored in the server and serverMember. However the current server class doesn't have roles or members.
So that library can't check users permissions?
It can but not easily. To do so you'll have to parse the server object to get the list of roles.
Then, what class I need to use?
You'll need a few things. I wouldn't call them classes as they are JSON object or number. We will need the Guild Member, which you'll need the server or server ID and user ID to get. This will give us the IDs of roles that the user has on a server. From there we check their permissions from their role.
Not to mention, channels can override permissions so you'll also need to check those as well.
Once you have the premission, you can check if the user has a specific permission using a bitwise and.
So I have ServerID and UserID, What now?
I would wait for me to make the above much easier. I've already done most of the work, however I ran into performance issues when dealing with large servers.
Sorry it took so long, I was working on other project also adding this feature also made the library use a bit more ram and cpu. On Debug, it's a massive difference, but on release, the difference is noticeable but not as big.
Other then that, in commit fb0e517, I added
Permission getPermissions(const Server& server, const ServerMember& member, const Channel& channel)
and
constexpr bool hasPremission(const Permission& target, const Permission& permission)
Here is an example,
SleepyDiscord::Permission permissions = SleepyDiscord::getPermissions(server, server.members[1], server.channels[0]);
if (hasPremission(permissions, SleepyDiscord::Permission::MANAGE_CHANNELS))
std::cout << "True\n";
possible output
True
No problem and Thanks
One problem, I have got that erros: https://pastebin.com/S0znVgH5 code
if (message.startsWith("test"))
{
SleepyDiscord::Permission permissions = SleepyDiscord::getPermissions(server, server.members[1], server.channels[0]);
if (hasPremission(permissions, SleepyDiscord::Permission::MANAGE_CHANNELS))
deleteChannel(message.channelID);
else
sendMessage(message.channelID, "Nope");
}
It looks like you declared server to be a std:: list. Can I see the declaration of server?
Maybe use server->members instead of server.member
using SleepyDiscord::DiscordClient::DiscordClient;
void onServer(SleepyDiscord::Server server) {
servers.push_front(server);
}
std::list<SleepyDiscord::Server> servers;
void onMessage(SleepyDiscord::Message message)
{
SleepyDiscord::Snowflake<SleepyDiscord::Server> serverID;
auto server = std::find_if(servers.begin(), servers.end(), [&message](SleepyDiscord::Server& server) {
auto result = message.channelID.findObject(server.channels);
return result != server.channels.end();
});
Ahh, I see. server is a std::list
I also recommend read up on find as well https://en.cppreference.com/w/cpp/algorithm/find.
How can I do it?
SleepyDiscord::getPermissions(*server, server->members[1], server->channels[0]);
You may also want to do if (server != servers.end())
to check if a server was found.
I recommend you read up on iterators and find_if and getting an understanding of what the code above is doing before blindly copying and pasting code to avoid confusion.
Works, but I have problem. It didn't refresh! Example:
Are those two the same user? Other then that, looking at your code, the behavior makes sense if that is the same user or you edited someone's role. Your servers variable is never updated when a member or role is edited. Now you can still do it but there's nothing in the library to make it easy to do yet. It's actually being worked on, but for now, you'll need to do it the hard way, which I think may be too technical for someone that doesn't know much about the Discord API.
So I have to wait for new update?
How I can check users permissions?