mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2025-01-31 12:56:11 +01:00
Allow custom bot naming
This commit is contained in:
parent
6a81a5b337
commit
a62252ed15
@ -3,7 +3,7 @@ from app.classes.web.webhooks.base_webhook import WebhookProvider
|
|||||||
|
|
||||||
|
|
||||||
class DiscordWebhook(WebhookProvider):
|
class DiscordWebhook(WebhookProvider):
|
||||||
def _construct_discord_payload(self, server_name, title, message, color):
|
def _construct_discord_payload(self, server_name, title, message, color, bot_name):
|
||||||
"""
|
"""
|
||||||
Constructs the payload required for sending a Discord webhook notification.
|
Constructs the payload required for sending a Discord webhook notification.
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ class DiscordWebhook(WebhookProvider):
|
|||||||
|
|
||||||
headers = {"Content-type": "application/json"}
|
headers = {"Content-type": "application/json"}
|
||||||
payload = {
|
payload = {
|
||||||
"username": self.WEBHOOK_USERNAME,
|
"username": bot_name,
|
||||||
"avatar_url": self.WEBHOOK_PFP_URL,
|
"avatar_url": self.WEBHOOK_PFP_URL,
|
||||||
"embeds": [
|
"embeds": [
|
||||||
{
|
{
|
||||||
@ -69,7 +69,8 @@ class DiscordWebhook(WebhookProvider):
|
|||||||
Exception: If there's an error in dispatching the webhook.
|
Exception: If there's an error in dispatching the webhook.
|
||||||
"""
|
"""
|
||||||
color = kwargs.get("color", "#005cd1") # Default to a color if not provided.
|
color = kwargs.get("color", "#005cd1") # Default to a color if not provided.
|
||||||
|
bot_name = kwargs.get("bot_name", self.WEBHOOK_USERNAME)
|
||||||
payload, headers = self._construct_discord_payload(
|
payload, headers = self._construct_discord_payload(
|
||||||
server_name, title, message, color
|
server_name, title, message, color, bot_name
|
||||||
)
|
)
|
||||||
return self._send_request(url, payload, headers)
|
return self._send_request(url, payload, headers)
|
||||||
|
@ -2,7 +2,7 @@ from app.classes.web.webhooks.base_webhook import WebhookProvider
|
|||||||
|
|
||||||
|
|
||||||
class MattermostWebhook(WebhookProvider):
|
class MattermostWebhook(WebhookProvider):
|
||||||
def _construct_mattermost_payload(self, server_name, title, message):
|
def _construct_mattermost_payload(self, server_name, title, message, bot_name):
|
||||||
"""
|
"""
|
||||||
Constructs the payload required for sending a Mattermost webhook notification.
|
Constructs the payload required for sending a Mattermost webhook notification.
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ class MattermostWebhook(WebhookProvider):
|
|||||||
headers = {"Content-Type": "application/json"}
|
headers = {"Content-Type": "application/json"}
|
||||||
payload = {
|
payload = {
|
||||||
"text": formatted_text,
|
"text": formatted_text,
|
||||||
"username": self.WEBHOOK_USERNAME,
|
"username": bot_name,
|
||||||
"icon_url": self.WEBHOOK_PFP_URL,
|
"icon_url": self.WEBHOOK_PFP_URL,
|
||||||
"props": {
|
"props": {
|
||||||
"card": (
|
"card": (
|
||||||
@ -65,7 +65,8 @@ class MattermostWebhook(WebhookProvider):
|
|||||||
- Mattermost's `config.json` setting is `"EnablePostUsernameOverride": true`
|
- Mattermost's `config.json` setting is `"EnablePostUsernameOverride": true`
|
||||||
- Mattermost's `config.json` setting is `"EnablePostIconOverride": true`
|
- Mattermost's `config.json` setting is `"EnablePostIconOverride": true`
|
||||||
"""
|
"""
|
||||||
|
bot_name = kwargs.get("bot_name", self.WEBHOOK_USERNAME)
|
||||||
payload, headers = self._construct_mattermost_payload(
|
payload, headers = self._construct_mattermost_payload(
|
||||||
server_name, title, message
|
server_name, title, message, bot_name
|
||||||
)
|
)
|
||||||
return self._send_request(url, payload, headers)
|
return self._send_request(url, payload, headers)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user