-
Notifications
You must be signed in to change notification settings - Fork 27
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
feature: Message->getAllowedMentions #11
base: master
Are you sure you want to change the base?
Conversation
Has this been tested? According to the documentation, this implementation is incorrect the The right way of implementing this is to make a new class called the parse array would be handled by that class, adding make sure to make it |
That's rather weird, last time I've read the docs to the allowed_mentions field it might've been different? Technically could check them by the github repo, but yes I have tested it. public function webhook(): void {
$webhook = new Webhook("<webhook>");
$messageOne = new Message();
$messageOne->setContent("Message One: @everyone");
$webhook->send($messageOne);
$messageTwo = new Message();
$messageTwo->setAllowedMentions(false, false, false);
$messageTwo->setContent("Message Two: @everyone");
$webhook->send($messageTwo);
} |
I didn’t check the roles and users yet I will do it after I’m getting home again |
Okay, back at home I checked it again with users and roles and it works completely fine, my sample code is public function webhook(): void {
$webhook = new Webhook("webhook");
$messageOne = new Message();
$messageOne->setContent("Message One: @everyone - User: <@216199376077455360> | Role: <@&719009266559746079>");
$webhook->send($messageOne);
$messageTwo = new Message();
$messageTwo->setAllowedMentions(false, false, false);
$messageTwo->setContent("Message Two: @everyone - User: <@216199376077455360> | Role: <@&719009266559746079>");
$webhook->send($messageTwo);
} |
Works perfectly fine! |
I still think it's better to implement the actual API's class instead of relying on undocumented behavior 🤔 |
The following commit adds a few functions
The class took reference from here |
Perhaps include tests and some sample code into README.md Looks good to me, just needs documentation and tests |
This should be included into the PM4-branch. |
Was being busy with school until now. |
Sample testing code: protected function onEnable(): void
{
$webhook = new Webhook(self::URL);
// test @everyone
$msg1 = new Message();
$msg1->setContent("Hello! @everyone");
$msg1->getAllowedMentions(); // explain the behavior of the readme
$msg2 = new Message();
$msg2->setContent("Hello! @everyone");
$msg2->getAllowedMentions()->suppressAll();
$webhook->send($msg1);
usleep(100);
$webhook->send($msg2);
sleep(1);
// test user mentions, expected behavior: only mention martin not japanlover, 2nd mention both
$msg3 = new Message();
$msg3->setContent("<@216199376077455360> <@846158172191850516>");
$msg3->getAllowedMentions()->addUser("216199376077455360");
$msg4 = new Message();
$msg4->setContent("<@216199376077455360> <@846158172191850516>");
$webhook->send($msg3);
usleep(100);
$webhook->send($msg4);
sleep(1);
// role id: first is called first, second is called second. martin has first, japanlover has second
// test role mentions, expected behavior: only mention @first, 2nd mention both
$msg5 = new Message();
$msg5->setContent("<@&1104850989795790879> <@&1104851010893123694>");
$msg5->getAllowedMentions()->addRole("1104850989795790879");
$msg6 = new Message();
$msg6->setContent("<@&1104850989795790879> <@&1104851010893123694>");
$webhook->send($msg5);
usleep(100);
$webhook->send($msg6);
sleep(1);
} Second picture with higher delay from JapanLover POV because it was set too low and send the other one before the second one. (2s delay) The left side is @martin (216199376077455360), the right side is @Japanlover (846158172191850516) Ignore the cringe name |
stop using |
@xqwtxon I am very much aware, it is just way more readable using sleep in a single function then other approaches and this is just meant to showcase it |
This function adds the allowed_mentions field from the Execute Webhook request (Message->setAllowedMentions)
The function takes 3 parameters - Roles, Users and Everyone and all of them are set by default to false
Resources: