Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

Commit

Permalink
♻️ Added remove_none() for headers too
Browse files Browse the repository at this point in the history
  • Loading branch information
darvil82 committed Jan 2, 2022
1 parent 4cc0767 commit a35acb4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion pincer/core/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ async def __send(
data=data,
headers={
"Content-Type": content_type,
**(headers or {})
**(remove_none(headers) or {})
},
params=remove_none(params)
) as res:
Expand Down
18 changes: 9 additions & 9 deletions pincer/objects/guild/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ async def edit_permissions(
"""
await self._http.put(
f"channels/{self.id}/permissions/{overwrite.id}",
headers=remove_none({"X-Audit-Log-Reason": reason}),
headers={"X-Audit-Log-Reason": reason},
data={"allow": allow, "deny": deny, "type": type},
)

Expand All @@ -323,7 +323,7 @@ async def delete_permission(
"""
await self._http.delete(
f"channels/{self.id}/permissions/{overwrite.id}",
headers=remove_none({"X-Audit-Log-Reason": reason}),
headers={"X-Audit-Log-Reason": reason},
)

async def follow_news_channel(
Expand Down Expand Up @@ -389,7 +389,7 @@ async def pin_message(
"""
await self._http.put(
f"channels/{self.id}/pins/{message.id}",
headers=remove_none({"X-Audit-Log-Reason": reason}),
headers={"X-Audit-Log-Reason": reason},
)

async def unpin_message(
Expand All @@ -400,7 +400,7 @@ async def unpin_message(
"""
await self._http.delete(
f"channels/{self.id}/pins/{message.id}",
headers=remove_none({"X-Audit-Log-Reason": reason}),
headers={"X-Audit-Log-Reason": reason},
)

async def group_dm_add_recipient(
Expand Down Expand Up @@ -459,7 +459,7 @@ async def bulk_delete_messages(
"""
await self._http.post(
f"channels/{self.id}/messages/bulk_delete",
headers=remove_none({"X-Audit-Log-Reason": reason}),
headers={"X-Audit-Log-Reason": reason},
data={"messages": messages},
)

Expand All @@ -484,7 +484,7 @@ async def delete(

await self._http.delete(
f"channels/{channel_id}",
headers=remove_none({"X-Audit-Log-Reason": reason}),
headers={"X-Audit-Log-Reason": reason},
)

async def __post_send_handler(self, message: UserMessage):
Expand Down Expand Up @@ -621,7 +621,7 @@ async def create_invite(
self._client,
await self._http.post(
f"channels/{self.id}/invites",
headers=remove_none({"X-Audit-Log-Reason": reason}),
headers={"X-Audit-Log-Reason": reason},
data={
"max_age": max_age,
"max_uses": max_uses,
Expand Down Expand Up @@ -955,7 +955,7 @@ async def start(
self._client,
await self._http.post(
f"channels/{self.id}/threads",
headers=remove_none({"X-Audit-Log-Reason": reason}),
headers={"X-Audit-Log-Reason": reason},
data={
"name": name,
"auto_archive_duration": auto_archive_duration,
Expand Down Expand Up @@ -1018,7 +1018,7 @@ async def start_with_message(
self._client,
await self._http.post(
f"channels/{self.id}/messages/{message.id}/threads",
headers=remove_none({"X-Audit-Log-Reason": reason}),
headers={"X-Audit-Log-Reason": reason},
data={
"name": name,
"auto_archive_duration": auto_archive_duration,
Expand Down
42 changes: 21 additions & 21 deletions pincer/objects/guild/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ async def modify_member(self, _id: int, reason=None, **kwargs) -> GuildMember:
data = await self._http.patch(
f"guilds/{self.id}/members/{_id}",
data=kwargs,
headers=remove_none({"X-Audit-Log-Reason": reason})
headers={"X-Audit-Log-Reason": reason}
)
return GuildMember.from_dict(construct_client_dict(self._client, data))

Expand Down Expand Up @@ -568,7 +568,7 @@ async def create_channel(
data = await self._http.post(
f"guilds/{self.id}/channels",
data=kwargs,
headers=remove_none({"X-Audit-Log-Reason": reason})
headers={"X-Audit-Log-Reason": reason}
)
return Channel.from_dict(construct_client_dict(self._client, data))

Expand All @@ -594,7 +594,7 @@ async def modify_channel_positions(
await self._http.patch(
f"guilds/{self.id}/channels",
data=channel,
headers=remove_none({"X-Audit-Log-Reason":reason})
headers={"X-Audit-Log-Reason":reason}
)

async def list_active_threads(self) -> Tuple[
Expand Down Expand Up @@ -738,7 +738,7 @@ async def add_guild_member(
data = await self._http.put(
f"guilds/{self.id}/members/{user_id}",
data=kwargs,
headers=remove_none({"X-Audit-Log-Reason": reason})
headers={"X-Audit-Log-Reason": reason}
)

return GuildMember.from_dict(
Expand Down Expand Up @@ -767,7 +767,7 @@ async def modify_current_member(
data = self._http.patch(
f"guilds/{self.id}/members/@me",
{"nick": nick},
headers=remove_none({"X-Audit-Log-Reason":reason})
headers={"X-Audit-Log-Reason":reason}
)
return GuildMember.from_dict(construct_client_dict(self._client, data))

Expand All @@ -791,7 +791,7 @@ async def add_guild_member_role(
"""
data = await self._http.put(
f"guilds/{self.id}/{user_id}/roles/{role_id}",
headers=remove_none({"X-Audit-Log-Reason": reason})
headers={"X-Audit-Log-Reason": reason}
)

async def remove_guild_member_role(
Expand All @@ -814,7 +814,7 @@ async def remove_guild_member_role(
"""
await self._http.delete(
f"guilds/{self.id}/{user_id}/roles/{role_id}",
headers=remove_none({"X-Audit-Log-Reason": reason})
headers={"X-Audit-Log-Reason": reason}
)

async def remove_guild_member(
Expand All @@ -834,7 +834,7 @@ async def remove_guild_member(
"""
await self._http.delete(
f"guilds/{self.id}/members/{user_id}",
headers=remove_none({"X-Audit-Log-Reason": reason})
headers={"X-Audit-Log-Reason": reason}
)

async def ban(
Expand Down Expand Up @@ -955,7 +955,7 @@ async def create_role(self, reason: Optional[str] = None, **kwargs) -> Role:
await self._http.post(
f"guilds/{self.id}/roles",
data=kwargs,
headers=remove_none({"X-Audit-Log-Reason": reason}),
headers={"X-Audit-Log-Reason": reason},
),
)
)
Expand Down Expand Up @@ -986,7 +986,7 @@ async def edit_role_position(
data = await self._http.patch(
f"guilds/{self.id}/roles",
data={"id": id, "position": position},
headers=remove_none({"X-Audit-Log-Reason": reason}),
headers={"X-Audit-Log-Reason": reason},
)
for role_data in data:
yield Role.from_dict(construct_client_dict(self._client, role_data))
Expand Down Expand Up @@ -1050,7 +1050,7 @@ async def edit_role(
await self._http.patch(
f"guilds/{self.id}/roles/{id}",
data=kwargs,
headers=remove_none({"X-Audit-Log-Reason": reason}),
headers={"X-Audit-Log-Reason": reason},
),
)
)
Expand All @@ -1069,7 +1069,7 @@ async def delete_role(self, id: Snowflake, reason: Optional[str] = None):
"""
await self._http.delete(
f"guilds/{self.id}/roles/{id}",
headers=remove_none({"X-Audit-Log-Reason": reason}),
headers={"X-Audit-Log-Reason": reason},
)

async def get_bans(self) -> AsyncGenerator[Ban, None]:
Expand Down Expand Up @@ -1119,7 +1119,7 @@ async def unban(self, id: Snowflake, reason: Optional[str] = None):
"""
await self._http.delete(
f"guilds/{self.id}/bans/{id}",
headers=remove_none({"X-Audit-Log-Reason": reason}),
headers={"X-Audit-Log-Reason": reason},
)

@overload
Expand Down Expand Up @@ -1290,7 +1290,7 @@ async def prune(
"compute_prune_days": compute_prune_days,
"include_roles": include_roles,
},
headers=remove_none({"X-Audit-Log-Reason": reason}),
headers={"X-Audit-Log-Reason": reason},
)["pruned"]

async def get_voice_regions(self) -> AsyncGenerator[VoiceRegion, None]:
Expand Down Expand Up @@ -1356,7 +1356,7 @@ async def delete_integration(
"""
await self._http.delete(
f"guilds/{self.id}/integrations/{integration.id}",
headers=remove_none({"X-Audit-Log-Reason": reason}),
headers={"X-Audit-Log-Reason": reason},
)

async def get_widget_settings(self) -> GuildWidget:
Expand Down Expand Up @@ -1397,7 +1397,7 @@ async def modify_widget(
data = await self._http.patch(
f"guilds/{self.id}/widget",
data=kwargs,
headers=remove_none({"X-Audit-Log-Reason": reason}),
headers={"X-Audit-Log-Reason": reason},
)
return GuildWidget.from_dict(construct_client_dict(self._client, data))

Expand Down Expand Up @@ -1509,7 +1509,7 @@ async def modify_welcome_screen(
"welcome_channels": welcome_channels,
"description": description,
},
headers=remove_none({"X-Audit-Log-Reason": reason}),
headers={"X-Audit-Log-Reason": reason},
)
return WelcomeScreen.from_dict(
construct_client_dict(self._client, data)
Expand Down Expand Up @@ -1672,7 +1672,7 @@ async def create_emoji(
data = await self._http.post(
f"guilds/{self.id}/emojis",
data={"name": name, "image": image.uri, "roles": roles},
headers=remove_none({"X-Audit-Log-Reason": reason}),
headers={"X-Audit-Log-Reason": reason},
)
return Emoji.from_dict(construct_client_dict(self._client, data))

Expand Down Expand Up @@ -1707,7 +1707,7 @@ async def edit_emoji(
data = await self._http.patch(
f"guilds/{self.id}/emojis/{id}",
data={"name": name, "roles": roles},
headers=remove_none({"X-Audit-Log-Reason": reason}),
headers={"X-Audit-Log-Reason": reason},
)
return Emoji.from_dict(construct_client_dict(self._client, data))

Expand All @@ -1727,7 +1727,7 @@ async def delete_emoji(
"""
await self._http.delete(
f"guilds/{self.id}/emojis/{id}",
headers=remove_none({"X-Audit-Log-Reason": reason}),
headers={"X-Audit-Log-Reason": reason},
)

async def get_templates(self) -> AsyncIterator[GuildTemplate]:
Expand Down Expand Up @@ -1931,7 +1931,7 @@ async def create_sticker(
sticker = await self._http.post(
f"guilds/{self.id}/stickers",
data=payload,
headers=remove_none({"X-Audit-Log-Reason": reason}),
headers={"X-Audit-Log-Reason": reason},
content_type=payload.content_type
)

Expand Down
2 changes: 1 addition & 1 deletion pincer/objects/message/sticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ async def modify(
data=remove_none(
{"name": name, "description": description, "tags": tags}
),
headers=remove_none({"X-Audit-Log-Reason": reason}),
headers={"X-Audit-Log-Reason": reason},
)

return Sticker.from_dict(sticker)
Expand Down

0 comments on commit a35acb4

Please sign in to comment.