Skip to content

Update guild.py (automod things) #76

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

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -3639,6 +3639,28 @@ async def automod_rules(self) -> List[AutoModRule]:
for rule in data:
self._add_automod_rule(AutoModRule(state=self._state, guild=self, **rule)) # TODO: Advanced caching
return self.cached_automod_rules

async def fetch_automod_rule(self, rule_id: int) -> AutoModRule:
"""|coro|

Fetches a Auto Moderation rule for this guild by their ID
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick (llm): There's a minor grammatical error in the documentation. It should be 'Fetches an Auto Moderation rule for this guild by its ID' instead of 'Fetches a Auto Moderation rule for this guild by their ID'.


Raises
-------
Forbidden
You do not have permissions to fetch the rule.
HTTPException
Fetching the rule failed.

Returns
--------
:class:`~discord.AutoModRule`
The AutoMod rule
"""
data = await self._state.http.get_automod_rule(self.id, rule_id)
rule = AutoModRule(state=self._state, guild=self, **data)
self._add_automod_rule(rule)
return rule

async def create_automod_rule(
self,
Expand Down Expand Up @@ -3693,20 +3715,19 @@ async def create_automod_rule(
"""
data = {
'name': name,
'event_type': int(event_type),
'trigger_type': int(trigger_type),
'event_type': event_type if isinstance(event_type, int) else event_type.value,
'trigger_type': trigger_type if isinstance(trigger_type, int) else trigger_type.value,
'trigger_metadata': trigger_metadata.to_dict(),
'actions': [a.to_dict() for a in actions],
'enabled': enabled,
'exempt_roles': [str(r.id) for r in exempt_roles] # type: ignore
'exempt_roles': [str(r.id) for r in exempt_roles], # type: ignore
}
for action in actions: # Add the channels where messages should be logged to, to the exempted channels
if action.type.send_alert_message and action.channel_id not in exempt_channels:
exempt_channels.append(action.channel_id)
exempt_channels = [str(c.id) for c in exempt_channels]
data['exempt_channels'] = exempt_channels
data['exempt_channels'] = [str(r.id) for r in exempt_channels]
rule_data = await self._state.http.create_automod_rule(guild_id=self.id, data=data, reason=reason)
rule = AutoModRule(state=self._state, guild=self, data=rule_data)
rule = AutoModRule(state=self._state, guild=self, **rule_data)
self._add_automod_rule(rule)
return rule

Expand Down