Skip to content

Commit

Permalink
Add exclude meta data for Discord webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
carlbennett committed Dec 28, 2019
1 parent 9fd3fd5 commit 4579124
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 41 deletions.
19 changes: 10 additions & 9 deletions etc/config.sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@
"battleforthenet": "",
"vultr": ""
},
"discord": {
"forward_event_log": {
"enabled": false,
"ignore_event_types": [3,5,7,8,9,10,11],
"webhook": null
},
"invite_code": "u87WVeu",
"server_id": 405789880749260820
},
"donations": {
"btc_address": "",
"paypal_url": ""
Expand Down Expand Up @@ -58,6 +49,16 @@
"username_length_min": 3
}
},
"discord": {
"forward_event_log": {
"enabled": false,
"exclude_meta_data": false,
"ignore_event_types": [3,5,7,8,9,10,11],
"webhook": null
},
"invite_code": "u87WVeu",
"server_id": 405789880749260820
},
"email": {
"recipient_from": [
"root@localhost",
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/Discord.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public function &run( Router &$router, View &$view, array &$args ) {
$model = new DiscordModel();

$model->discord_url = 'https://discord.gg/';
$model->discord_url .= Common::$config->bnetdocs->discord->invite_code;
$model->discord_server_id = Common::$config->bnetdocs->discord->server_id;
$model->discord_url .= Common::$config->discord->invite_code;
$model->discord_server_id = Common::$config->discord->server_id;

$view->render( $model );

Expand Down
62 changes: 32 additions & 30 deletions src/libraries/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static function logEvent(
}

protected static function dispatchDiscordWebhook($event_id) {
$c = Common::$config->bnetdocs->discord->forward_event_log;
$c = Common::$config->discord->forward_event_log;
if (!$c->enabled) return;

$event = new Event($event_id);
Expand All @@ -94,50 +94,52 @@ protected static function dispatchDiscordWebhook($event_id) {
$embed->setAuthor($author);
}

$data = json_decode($event->getMetadata(), true);
if (is_scalar($data)) {
if (!$c->exclude_meta_data) {
$data = json_decode($event->getMetadata(), true);
if (is_scalar($data)) {

if (is_string($data)) {
$f_value = substr($data, 0, DiscordEmbedField::MAX_VALUE - 3);
if (strlen($data) > DiscordEmbedField::MAX_VALUE - 3)
$f_value .= '...';
} else {
$f_value = $data;
}

$field = new DiscordEmbedField('Meta Data', $f_value, true);
$embed->addField($field);

if (is_string($data)) {
$f_value = substr($data, 0, DiscordEmbedField::MAX_VALUE - 3);
if (strlen($data) > DiscordEmbedField::MAX_VALUE - 3)
$f_value .= '...';
} else {
$f_value = $data;
}

$field = new DiscordEmbedField('Meta Data', $f_value, true);
$embed->addField($field);
foreach ($data as $key => $value) {

} else {
$f_key = substr($key, 0, DiscordEmbedField::MAX_NAME - 3);
if (strlen($key) > DiscordEmbedField::MAX_NAME - 3)
$f_key .= '...';

foreach ($data as $key => $value) {
if (is_scalar($value)) {

$f_key = substr($key, 0, DiscordEmbedField::MAX_NAME - 3);
if (strlen($key) > DiscordEmbedField::MAX_NAME - 3)
$f_key .= '...';
if (is_string($value)) {
$f_value = substr($value, 0, DiscordEmbedField::MAX_VALUE - 3);
if (strlen($value) > DiscordEmbedField::MAX_VALUE - 3)
$f_value .= '...';
} else {
$f_value = $value;
}

if (is_scalar($value)) {
$field = new DiscordEmbedField($f_key, $f_value, true);

if (is_string($value)) {
$f_value = substr($value, 0, DiscordEmbedField::MAX_VALUE - 3);
if (strlen($value) > DiscordEmbedField::MAX_VALUE - 3)
$f_value .= '...';
} else {
$f_value = $value;
}

$field = new DiscordEmbedField($f_key, $f_value, true);

} else {
$field = new DiscordEmbedField($f_key, gettype($value), true);

$field = new DiscordEmbedField($f_key, gettype($value), true);
}
$embed->addField($field);

if ($embed->fieldCount() >= DiscordEmbed::MAX_FIELDS) break;
}
$embed->addField($field);

if ($embed->fieldCount() >= DiscordEmbed::MAX_FIELDS) break;
}

}

$webhook->addEmbed($embed);
Expand Down

0 comments on commit 4579124

Please sign in to comment.