Skip to content

Commit

Permalink
Add Thread total_message_sent and position, Add `APPLICATION_COMM…
Browse files Browse the repository at this point in the history
…AND_BADGE`, Add mention spam type and limits (#864)

* Add thread total_message_sent and message_count

* Add APPLICATION_COMMAND_BADGE

* Add mention spam type

* fix actions array createable attributes
  • Loading branch information
SQKo authored Jul 22, 2022
1 parent f84970e commit c0d231a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/Discord/Parts/Channel/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
* @property Thread|null $thread The thread that the message was sent in.
* @property Collection|Component[]|null $components Sent if the message contains components like buttons, action rows, or other interactive components.
* @property Collection|Sticker[]|null $sticker_items Stickers attached to the message.
* @property int|null $position A generally increasing integer (there may be gaps or duplicates) that represents the approximate position of the message in a thread, it can be used to estimate the relative position of the messsage in a thread in company with `total_message_sent` on parent thread.
* @property bool $crossposted Message has been crossposted.
* @property bool $is_crosspost Message is a crosspost from another channel.
* @property bool $suppress_embeds Do not include embeds when serializing message.
Expand Down Expand Up @@ -169,6 +170,7 @@ class Message extends Part
'components',
'sticker_items',
'stickers',
'position',
];

/**
Expand Down
16 changes: 16 additions & 0 deletions src/Discord/Parts/Guild/AutoModeration/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,20 @@ class Action extends Part
public const TYPE_BLOCK_MESSAGE = 1;
public const TYPE_SEND_ALERT_MESSAGE = 2;
public const TYPE_TIMEOUT = 3;

/**
* @inheritdoc
*/
public function getCreatableAttributes(): array
{
$attr = [
'type' => $this->type,
];

if (isset($this->attributes['metadata'])) {
$attr['metadata'] = $this->metadata;
}

return $attr;
}
}
9 changes: 6 additions & 3 deletions src/Discord/Parts/Guild/AutoModeration/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @property User|null $creator The user which first created this rule.
* @property int $event_type The rule event type.
* @property int $trigger_type The rule trigger type.
* @property object $trigger_metadata The rule trigger metadata (may contain `keyword_filter`, `presets`, and `allow_list`).
* @property object $trigger_metadata The rule trigger metadata (may contain `keyword_filter`, `presets`, `allow_list`, and `mention_total_limit`).
* @property Collection|Action[] $actions The actions which will execute when the rule is triggered.
* @property bool $enabled Whether the rule is enabled.
* @property array $exempt_roles The role ids that should not be affected by the rule (Maximum of 20).
Expand Down Expand Up @@ -59,6 +59,7 @@ class Rule extends Part
public const TRIGGER_TYPE_HARMFUL_LINK = 2;
public const TRIGGER_TYPE_SPAM = 3;
public const TRIGGER_TYPE_KEYWORD_PRESET = 4;
public const TRIGGER_TYPE_MENTION_SPAM = 5;

public const KEYWORD_PRESET_TYPE_PROFANITY = 1;
public const KEYWORD_PRESET_TYPE_SEXUAL_CONTENT = 2;
Expand Down Expand Up @@ -111,10 +112,12 @@ public function getCreatableAttributes(): array
'name' => $this->name,
'event_type' => $this->event_type,
'trigger_type' => $this->trigger_type,
'actions' => $this->actions,
'actions' => array_values($this->actions->map(function (Action $overwrite) {
return $overwrite->getCreatableAttributes();
})->toArray()),
];

if (in_array($this->trigger_type, [self::TRIGGER_TYPE_KEYWORD, self::TRIGGER_TYPE_KEYWORD_PRESET])) {
if (in_array($this->trigger_type, [self::TRIGGER_TYPE_KEYWORD, self::TRIGGER_TYPE_KEYWORD_PRESET, self::TRIGGER_TYPE_MENTION_SPAM])) {
$attr['trigger_metadata'] = $this->trigger_metadata;
}

Expand Down
1 change: 1 addition & 0 deletions src/Discord/Parts/OAuth/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class Application extends Part
public const EMBEDDED = (1 << 17);
public const GATEWAY_MESSAGE_CONTENT = (1 << 18);
public const GATEWAY_MESSAGE_CONTENT_LIMITED = (1 << 19);
public const APPLICATION_COMMAND_BADGE = (1 << 23);

/**
* @inheritdoc
Expand Down
4 changes: 3 additions & 1 deletion src/Discord/Parts/Thread/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
* @property int $rate_limit_per_user Amount of seconds a user has to wait before sending a new message.
* @property string $owner_id The ID of the owner of the thread.
* @property string $parent_id The ID of the channel which the thread was started in.
* @property int $message_count An approximate count of the number of messages sent in the thread. Stops counting at 50.
* @property int $message_count Number of messages (not including the initial message or deleted messages) in a thread (if the thread was created before July 1, 2022, it stops counting at 50).
* @property int $member_count An approximate count of the number of members in the thread. Stops counting at 50.
* @property Guild|null $guild The guild which the thread belongs to.
* @property User|null $owner The owner of the thread.
Expand All @@ -54,6 +54,7 @@
* @property int|null $auto_archive_duration The number of minutes of inactivity until the thread is automatically archived.
* @property int|null $flags Channel flags combined as a bitfield. `PINNED` can only be set for threads in forum channels.
* @property Carbon $archive_timestamp The time that the thread's archive status was changed.
* @property int|null $total_message_sent Number of messages ever sent in a thread, it's similar to `message_count` on message creation, but will not decrement the number when a message is deleted.
* @property MessageRepository $messages Repository of messages sent in the thread.
* @property MemberRepository $members Repository of members in the thread.
*
Expand All @@ -79,6 +80,7 @@ class Thread extends Part
'member_count',
'thread_metadata',
'flags',
'total_message_sent',
];

/**
Expand Down

0 comments on commit c0d231a

Please sign in to comment.