diff --git a/app/main/controller/api/map.php b/app/main/controller/api/map.php index fcd3b528..3b2e49af 100644 --- a/app/main/controller/api/map.php +++ b/app/main/controller/api/map.php @@ -207,6 +207,11 @@ class Map extends Controller\AccessController { 'status' => (bool)Config::getPathfinderData('slack.status') ]; + // Slack integration status ------------------------------------------------------------------------------- + $return->discord = [ + 'status' => (bool)Config::getPathfinderData('discord.status') + ]; + $f3->set(self::CACHE_KEY_INIT, $return, $expireTimeCache ); } diff --git a/app/main/controller/api/system.php b/app/main/controller/api/system.php index 6349aa3c..c6ea1c8e 100644 --- a/app/main/controller/api/system.php +++ b/app/main/controller/api/system.php @@ -431,6 +431,7 @@ class System extends Controller\AccessController { $rallyData['pokeDesktop'] = $rallyData['pokeDesktop'] === '1'; $rallyData['pokeMail'] = $rallyData['pokeMail'] === '1'; $rallyData['pokeSlack'] = $rallyData['pokeSlack'] === '1'; + $rallyData['pokeDiscord'] = $rallyData['pokeDiscord'] === '1'; $rallyData['message'] = trim($rallyData['message']); $system->sendRallyPoke($rallyData, $activeCharacter); diff --git a/app/main/controller/setup.php b/app/main/controller/setup.php index 7bb83f73..f8a10d16 100644 --- a/app/main/controller/setup.php +++ b/app/main/controller/setup.php @@ -806,6 +806,14 @@ class Setup extends Controller { $label = ' Rally point poke Slack'; $tooltip = 'If "enabled", map admins can set a Slack channel for rally point pokes.'; break; + case 'send_history_discord_enabled': + $label = ' History log Discord'; + $tooltip = 'If "enabled", map admins can set a Discord channel were map logs get piped to.'; + break; + case 'send_rally_discord_enabled': + $label = ' Rally point poke Discord'; + $tooltip = 'If "enabled", map admins can set a Discord channel for rally point pokes.'; + break; case 'send_rally_mail_enabled': $label = ' Rally point poke Email'; $tooltip = 'If "enabled", rally point pokes can be send by Email (SMTP config + recipient address required).'; diff --git a/app/main/lib/Monolog.php b/app/main/lib/Monolog.php index 667c465e..9fd71659 100644 --- a/app/main/lib/Monolog.php +++ b/app/main/lib/Monolog.php @@ -36,6 +36,8 @@ class Monolog extends \Prefab { 'mail' => 'Monolog\Handler\SwiftMailerHandler', 'slackMap' => 'lib\logging\handler\SlackMapWebhookHandler', 'slackRally' => 'lib\logging\handler\SlackRallyWebhookHandler', + 'discordMap' => 'lib\logging\handler\SlackMapWebhookHandler', // use Slack handler for Discord + 'discordRally' => 'lib\logging\handler\SlackRallyWebhookHandler', // use Slack handler for Discord 'zmq' => 'lib\logging\handler\ZMQHandler' ]; diff --git a/app/main/lib/logging/AbstractLog.php b/app/main/lib/logging/AbstractLog.php index 670daa01..2a84fc8d 100644 --- a/app/main/lib/logging/AbstractLog.php +++ b/app/main/lib/logging/AbstractLog.php @@ -250,6 +250,8 @@ abstract class AbstractLog implements LogInterface { break; case 'slackMap': case 'slackRally': + case 'discordMap': + case 'discordRally': $params = $this->getHandlerParamsSlack($handlerKey); break; default: diff --git a/app/main/model/mapmodel.php b/app/main/model/mapmodel.php index 390d2815..8f1ba81e 100644 --- a/app/main/model/mapmodel.php +++ b/app/main/model/mapmodel.php @@ -25,6 +25,7 @@ class MapModel extends AbstractMapTrackingModel { const DATA_CACHE_KEY_CHARACTER = 'CHARACTERS'; const ERROR_SLACK_CHANNEL = 'Invalid #Slack channel column [%s]'; + const ERROR_DISCORD_CHANNEL = 'Invalid #Discord channel column [%s]'; protected $fieldConf = [ 'active' => [ @@ -133,6 +134,24 @@ class MapModel extends AbstractMapTrackingModel { 'default' => '', 'activity-log' => true ], + 'discordUsername' => [ + 'type' => Schema::DT_VARCHAR128, + 'nullable' => false, + 'default' => '', + 'activity-log' => true + ], + 'discordWebHookURLRally' => [ + 'type' => Schema::DT_VARCHAR256, + 'nullable' => false, + 'default' => '', + 'validate' => true + ], + 'discordWebHookURLHistory' => [ + 'type' => Schema::DT_VARCHAR256, + 'nullable' => false, + 'default' => '', + 'validate' => true + ], 'systems' => [ 'has-many' => ['Model\SystemModel', 'mapId'] ], @@ -191,59 +210,65 @@ class MapModel extends AbstractMapTrackingModel { if(is_null($mapDataAll)){ // no cached map data found - $mapData = (object) []; - $mapData->id = $this->id; - $mapData->name = $this->name; - $mapData->icon = $this->icon; - $mapData->deleteExpiredConnections = $this->deleteExpiredConnections; - $mapData->deleteEolConnections = $this->deleteEolConnections; - $mapData->persistentAliases = $this->persistentAliases; + $mapData = (object) []; + $mapData->id = $this->id; + $mapData->name = $this->name; + $mapData->icon = $this->icon; + $mapData->deleteExpiredConnections = $this->deleteExpiredConnections; + $mapData->deleteEolConnections = $this->deleteEolConnections; + $mapData->persistentAliases = $this->persistentAliases; // map scope - $mapData->scope = (object) []; - $mapData->scope->id = $this->scopeId->id; - $mapData->scope->name = $this->scopeId->name; - $mapData->scope->label = $this->scopeId->label; + $mapData->scope = (object) []; + $mapData->scope->id = $this->scopeId->id; + $mapData->scope->name = $this->scopeId->name; + $mapData->scope->label = $this->scopeId->label; // map type - $mapData->type = (object) []; - $mapData->type->id = $this->typeId->id; - $mapData->type->name = $this->typeId->name; - $mapData->type->classTab = $this->typeId->classTab; + $mapData->type = (object) []; + $mapData->type->id = $this->typeId->id; + $mapData->type->name = $this->typeId->name; + $mapData->type->classTab = $this->typeId->classTab; // map logging - $mapData->logging = (object) []; - $mapData->logging->activity = $this->isActivityLogEnabled(); - $mapData->logging->history = $this->isHistoryLogEnabled(); + $mapData->logging = (object) []; + $mapData->logging->activity = $this->isActivityLogEnabled(); + $mapData->logging->history = $this->isHistoryLogEnabled(); // map Slack logging - $mapData->logging->slackHistory = $this->isSlackChannelEnabled('slackChannelHistory'); - $mapData->logging->slackRally = $this->isSlackChannelEnabled('slackChannelRally'); - $mapData->logging->slackWebHookURL = $this->slackWebHookURL; - $mapData->logging->slackUsername = $this->slackUsername; - $mapData->logging->slackIcon = $this->slackIcon; - $mapData->logging->slackChannelHistory = $this->slackChannelHistory; - $mapData->logging->slackChannelRally = $this->slackChannelRally; + $mapData->logging->slackHistory = $this->isSlackChannelEnabled('slackChannelHistory'); + $mapData->logging->slackRally = $this->isSlackChannelEnabled('slackChannelRally'); + $mapData->logging->slackWebHookURL = $this->slackWebHookURL; + $mapData->logging->slackUsername = $this->slackUsername; + $mapData->logging->slackIcon = $this->slackIcon; + $mapData->logging->slackChannelHistory = $this->slackChannelHistory; + $mapData->logging->slackChannelRally = $this->slackChannelRally; + + // map Discord logging + $mapData->logging->discordRally = $this->isDiscordChannelEnabled('discordWebHookURLRally'); + $mapData->logging->discordUsername = $this->discordUsername; + $mapData->logging->discordWebHookURLRally = $this->discordWebHookURLRally; + $mapData->logging->discordWebHookURLHistory = $this->discordWebHookURLHistory; // map mail logging - $mapData->logging->mailRally = $this->isMailSendEnabled('RALLY_SET'); + $mapData->logging->mailRally = $this->isMailSendEnabled('RALLY_SET'); // map access - $mapData->access = (object) []; - $mapData->access->character = []; - $mapData->access->corporation = []; - $mapData->access->alliance = []; + $mapData->access = (object) []; + $mapData->access->character = []; + $mapData->access->corporation = []; + $mapData->access->alliance = []; - $mapData->created = (object) []; - $mapData->created->created = strtotime($this->created); + $mapData->created = (object) []; + $mapData->created->created = strtotime($this->created); if(is_object($this->createdCharacterId)){ - $mapData->created->character = $this->createdCharacterId->getData(); + $mapData->created->character = $this->createdCharacterId->getData(); } - $mapData->updated = (object) []; - $mapData->updated->updated = strtotime($this->updated); + $mapData->updated = (object) []; + $mapData->updated->updated = strtotime($this->updated); if(is_object($this->updatedCharacterId)){ - $mapData->updated->character = $this->updatedCharacterId->getData(); + $mapData->updated->character = $this->updatedCharacterId->getData(); } // get access object data --------------------------------------------------------------------------------- @@ -315,11 +340,50 @@ class MapModel extends AbstractMapTrackingModel { * @throws \Exception\ValidationException */ protected function validate_slackWebHookURL(string $key, string $val): bool { + return $this->validate_WebHookURL($key, $val, 'slack'); + } + + /** + * validate Discord History WebHook URL + * @param string $key + * @param string $val + * @return bool + * @throws \Exception\ValidationException + */ + protected function validate_discordWebHookURLHistory(string $key, string $val): bool { + return $this->validate_WebHookURL($key, $val, 'discord'); + } + + /** + * validate Discord Rally WebHook URL + * @param string $key + * @param string $val + * @return bool + * @throws \Exception\ValidationException + */ + protected function validate_discordWebHookURLRally(string $key, string $val): bool { + return $this->validate_WebHookURL($key, $val, 'discord'); + } + + /** + * validate Slack/Discord WebHook URL + * @param string $key + * @param string $val + * @param string $type + * @return bool + * @throws \Exception\ValidationException + */ + protected function validate_WebHookURL(string $key, string $val, string $type): bool { $valid = true; if( !empty($val) ){ + $hosts = [ + 'slack' => 'hooks.slack.com', + 'discord' => 'discordapp.com' + ]; + if( !\Audit::instance()->url($val) || - parse_url($val, PHP_URL_HOST) !== 'hooks.slack.com' + parse_url($val, PHP_URL_HOST) !== $hosts[$type] ){ $valid = false; $this->throwValidationException($key); @@ -873,6 +937,13 @@ class MapModel extends AbstractMapTrackingModel { $log->addHandlerGroup('slackMap'); } + // send map history to Discord channel ------------------------------------------------------------------------ + $discordChannelKey = 'discordWebHookURLHistory'; + if($this->isDiscordChannelEnabled($discordChannelKey)){ + $log->addHandler('discordMap', null, $this->getDiscordWebHookConfig($discordChannelKey)); + $log->addHandlerGroup('discordMap'); + } + // update map activity ---------------------------------------------------------------------------------------- $log->logActivity($this->isActivityLogEnabled()); @@ -959,6 +1030,34 @@ class MapModel extends AbstractMapTrackingModel { return $enabled; } + /** + * check if "Discord WebHook" is enabled for this map type + * @param string $channel + * @return bool + * @throws PathfinderException + */ + public function isDiscordChannelEnabled(string $channel): bool { + $enabled = false; + // check global Slack status + if((bool)Config::getPathfinderData('discord.status')){ + // check global map default config for this channel + switch($channel){ + case 'discordWebHookURLHistory': $defaultMapConfigKey = 'send_history_discord_enabled'; break; + case 'discordWebHookURLRally': $defaultMapConfigKey = 'send_rally_discord_enabled'; break; + default: throw new PathfinderException(sprintf(self::ERROR_DISCORD_CHANNEL, $channel)); + } + + if((bool) Config::getMapsDefaultConfig($this->typeId->name)[$defaultMapConfigKey]){ + $config = $this->getDiscordWebHookConfig($channel); + if($config->slackWebHookURL){ + $enabled = true; + } + } + } + + return $enabled; + } + /** * check if "E-Mail" Log is enabled for this map * @param string $type @@ -1018,6 +1117,20 @@ class MapModel extends AbstractMapTrackingModel { return $config; } + /** + * get Config for Discord WebHook cURL calls + * @param string $channel + * @return \stdClass + */ + public function getDiscordWebHookConfig(string $channel = ''): \stdClass { + $config = (object) []; + $config->slackUsername = $this->discordUsername; + if($channel && $this->exists($channel)){ + $config->slackWebHookURL = $this->$channel . '/slack'; + } + return $config; + } + /** * get Config for SMTP connection and recipient address * @param string $type diff --git a/app/main/model/systemmodel.php b/app/main/model/systemmodel.php index 884b4b95..879d81ca 100644 --- a/app/main/model/systemmodel.php +++ b/app/main/model/systemmodel.php @@ -565,6 +565,7 @@ class SystemModel extends AbstractMapTrackingModel { /** * send rally point poke to various "APIs" * -> send to a Slack channel + * -> send to a Discord channel * -> send to an Email * @param array $rallyData * @param CharacterModel $characterModel @@ -585,6 +586,17 @@ class SystemModel extends AbstractMapTrackingModel { $log->addHandler('slackRally', null, $this->getMap()->getSlackWebHookConfig($slackChannelKey)); } + // Discord poke --------------------------------------------------------------------------- + $discordChannelKey = 'discordWebHookURLRally'; + if( + $rallyData['pokeDiscord'] === true && + $this->getMap()->isDiscordChannelEnabled($discordChannelKey) + ){ + $isValidLog = true; + + $log->addHandler('discordRally', null, $this->getMap()->getDiscordWebHookConfig($discordChannelKey)); + } + // Mail poke ------------------------------------------------------------------------------ $mailAddressKey = 'RALLY_SET'; if( diff --git a/app/pathfinder.ini b/app/pathfinder.ini index 3ca94805..81bc6ba6 100644 --- a/app/pathfinder.ini +++ b/app/pathfinder.ini @@ -36,6 +36,11 @@ ALLIANCE = ; Global Slack API status, check PATHFINDER.MAP section for individual control (0=disabled, 1=enabled) STATUS = 1 +; Slack API integration =========================================================================== +[PATHFINDER.DISCORD] +; Global Discord API status, check PATHFINDER.MAP section for individual control (0=disabled, 1=enabled) +STATUS = 1 + ; View ============================================================================================ [PATHFINDER.VIEW] ; static page templates @@ -82,6 +87,8 @@ LOG_ACTIVITY_ENABLED = 1 LOG_HISTORY_ENABLED = 1 SEND_HISTORY_SLACK_ENABLED = 0 SEND_RALLY_SLACK_ENABLED = 1 +SEND_HISTORY_DISCORD_ENABLED = 0 +SEND_RALLY_DISCORD_ENABLED = 1 SEND_RALLY_Mail_ENABLED = 0 [PATHFINDER.MAP.CORPORATION] @@ -93,6 +100,8 @@ LOG_ACTIVITY_ENABLED = 1 LOG_HISTORY_ENABLED = 1 SEND_HISTORY_SLACK_ENABLED = 1 SEND_RALLY_SLACK_ENABLED = 1 +SEND_HISTORY_DISCORD_ENABLED = 1 +SEND_RALLY_DISCORD_ENABLED = 1 SEND_RALLY_Mail_ENABLED = 0 [PATHFINDER.MAP.ALLIANCE] @@ -104,6 +113,8 @@ LOG_ACTIVITY_ENABLED = 0 LOG_HISTORY_ENABLED = 1 SEND_HISTORY_SLACK_ENABLED = 1 SEND_RALLY_SLACK_ENABLED = 1 +SEND_HISTORY_DISCORD_ENABLED = 1 +SEND_RALLY_DISCORD_ENABLED = 1 SEND_RALLY_Mail_ENABLED = 0 ; Route search ==================================================================================== diff --git a/js/app/map/system.js b/js/app/map/system.js index 3aa6b03a..71b6020d 100644 --- a/js/app/map/system.js +++ b/js/app/map/system.js @@ -24,6 +24,7 @@ define([ dialogRallyPokeDesktopId: 'pf-rally-dialog-poke-desktop', // id for "desktop" poke checkbox dialogRallyPokeSlackId: 'pf-rally-dialog-poke-slack', // id for "Slack" poke checkbox + dialogRallyPokeDiscordId: 'pf-rally-dialog-poke-discord', // id for "Discord" poke checkbox dialogRallyPokeMailId: 'pf-rally-dialog-poke-mail', // id for "mail" poke checkbox dialogRallyMessageId: 'pf-rally-dialog-message', // id for "message" textarea @@ -88,11 +89,13 @@ define([ dialogRallyPokeDesktopId: config.dialogRallyPokeDesktopId, dialogRallyPokeSlackId: config.dialogRallyPokeSlackId, + dialogRallyPokeDiscordId: config.dialogRallyPokeDiscordId, dialogRallyPokeMailId: config.dialogRallyPokeMailId, dialogRallyMessageId: config.dialogRallyMessageId , desktopRallyEnabled: true, slackRallyEnabled: Boolean(Util.getObjVal(mapData, 'config.logging.slackRally')), + discordRallyEnabled: Boolean(Util.getObjVal(mapData, 'config.logging.discordRally')), mailRallyEnabled: Boolean(Util.getObjVal(mapData, 'config.logging.mailRally')), dialogRallyMessageDefault: config.dialogRallyMessageDefault, @@ -132,6 +135,8 @@ define([ } }); + rallyDialog.initTooltips(); + // after modal is shown ================================================================================== rallyDialog.on('shown.bs.modal', function(e){ // set event for checkboxes diff --git a/js/app/mappage.js b/js/app/mappage.js index a7c4bccf..30da223c 100644 --- a/js/app/mappage.js +++ b/js/app/mappage.js @@ -69,6 +69,7 @@ define([ Init.routes = initData.routes; Init.url = initData.url; Init.slack = initData.slack; + Init.discord = initData.discord; Init.routeSearch = initData.routeSearch; Init.programMode = initData.programMode; diff --git a/js/app/ui/dialog/map_settings.js b/js/app/ui/dialog/map_settings.js index 6a4a2dff..8a5ce284 100644 --- a/js/app/ui/dialog/map_settings.js +++ b/js/app/ui/dialog/map_settings.js @@ -33,6 +33,10 @@ define([ slackChannelHistoryId: 'pf-map-dialog-slack-channel-history', // id for Slack channel "history" slackChannelRallyId: 'pf-map-dialog-slack-channel-rally', // id for Slack channel "rally" + discordUsernameId: 'pf-map-dialog-discord-username', // id for Discord "username" + discordWebHookURLRallyId: 'pf-map-dialog-discord-url-rally', // id for Discord "rally" webHookUrl + discordWebHookURLHistoryId: 'pf-map-dialog-discord-url-history', // id for Discord "history" webHookUrl + characterSelectId: 'pf-map-dialog-character-select', // id for "character" select corporationSelectId: 'pf-map-dialog-corporation-select', // id for "corporation" select allianceSelectId: 'pf-map-dialog-alliance-select', // id for "alliance" select @@ -133,6 +137,14 @@ define([ let slackRallyEnabled = false; let slackSectionShow = false; + let discordUsername = ''; + let discordWebHookURLRally = ''; + let discordWebHookURLHistory = ''; + let discordEnabled = false; + let discordRallyEnabled = false; + let discordHistoryEnabled = false; + let discordSectionShow = false; + if(mapData !== false){ // set current map information contentEditMap.find('input[name="id"]').val( mapData.config.id ); @@ -162,6 +174,14 @@ define([ slackRallyEnabled = slackEnabled && Boolean(Util.getObjVal(Init.mapTypes, mapData.config.type.name + '.defaultConfig.send_rally_slack_enabled')); slackSectionShow = (slackEnabled && slackWebHookURL.length > 0); + discordUsername = Util.getObjVal(mapData, 'config.logging.discordUsername'); + discordWebHookURLRally = Util.getObjVal(mapData, 'config.logging.discordWebHookURLRally'); + discordWebHookURLHistory = Util.getObjVal(mapData, 'config.logging.discordWebHookURLHistory'); + discordEnabled = Boolean(Util.getObjVal(Init, 'discord.status')); + discordRallyEnabled = discordEnabled && Boolean(Util.getObjVal(Init.mapTypes, mapData.config.type.name + '.defaultConfig.send_rally_discord_enabled')); + discordHistoryEnabled = discordEnabled && Boolean(Util.getObjVal(Init.mapTypes, mapData.config.type.name + '.defaultConfig.send_history_discord_enabled')); + discordSectionShow = (discordEnabled && (discordWebHookURLRally.length > 0 || discordWebHookURLHistory.length > 0)); + // remove "#" from Slack channels slackChannelHistory = slackChannelHistory.indexOf('#') === 0 ? slackChannelHistory.substr(1) : slackChannelHistory; slackChannelRally = slackChannelRally.indexOf('#') === 0 ? slackChannelRally.substr(1) : slackChannelRally; @@ -221,6 +241,17 @@ define([ slackRallyEnabled: slackRallyEnabled, slackSectionShow: slackSectionShow, + discordUsernameId: config.discordUsernameId, + discordWebHookURLRallyId: config.discordWebHookURLRallyId, + discordWebHookURLHistoryId: config.discordWebHookURLHistoryId, + discordUsername: discordUsername, + discordWebHookURLRally: discordWebHookURLRally, + discordWebHookURLHistory: discordWebHookURLHistory, + discordEnabled: discordEnabled, + discordRallyEnabled: discordRallyEnabled, + discordHistoryEnabled: discordHistoryEnabled, + discordSectionShow: discordSectionShow, + characterSelectId: config.characterSelectId, corporationSelectId: config.corporationSelectId, allianceSelectId: config.allianceSelectId, diff --git a/public/js/v1.3.2/app/map/system.js b/public/js/v1.3.2/app/map/system.js index 3aa6b03a..71b6020d 100644 --- a/public/js/v1.3.2/app/map/system.js +++ b/public/js/v1.3.2/app/map/system.js @@ -24,6 +24,7 @@ define([ dialogRallyPokeDesktopId: 'pf-rally-dialog-poke-desktop', // id for "desktop" poke checkbox dialogRallyPokeSlackId: 'pf-rally-dialog-poke-slack', // id for "Slack" poke checkbox + dialogRallyPokeDiscordId: 'pf-rally-dialog-poke-discord', // id for "Discord" poke checkbox dialogRallyPokeMailId: 'pf-rally-dialog-poke-mail', // id for "mail" poke checkbox dialogRallyMessageId: 'pf-rally-dialog-message', // id for "message" textarea @@ -88,11 +89,13 @@ define([ dialogRallyPokeDesktopId: config.dialogRallyPokeDesktopId, dialogRallyPokeSlackId: config.dialogRallyPokeSlackId, + dialogRallyPokeDiscordId: config.dialogRallyPokeDiscordId, dialogRallyPokeMailId: config.dialogRallyPokeMailId, dialogRallyMessageId: config.dialogRallyMessageId , desktopRallyEnabled: true, slackRallyEnabled: Boolean(Util.getObjVal(mapData, 'config.logging.slackRally')), + discordRallyEnabled: Boolean(Util.getObjVal(mapData, 'config.logging.discordRally')), mailRallyEnabled: Boolean(Util.getObjVal(mapData, 'config.logging.mailRally')), dialogRallyMessageDefault: config.dialogRallyMessageDefault, @@ -132,6 +135,8 @@ define([ } }); + rallyDialog.initTooltips(); + // after modal is shown ================================================================================== rallyDialog.on('shown.bs.modal', function(e){ // set event for checkboxes diff --git a/public/js/v1.3.2/app/mappage.js b/public/js/v1.3.2/app/mappage.js index a7c4bccf..30da223c 100644 --- a/public/js/v1.3.2/app/mappage.js +++ b/public/js/v1.3.2/app/mappage.js @@ -69,6 +69,7 @@ define([ Init.routes = initData.routes; Init.url = initData.url; Init.slack = initData.slack; + Init.discord = initData.discord; Init.routeSearch = initData.routeSearch; Init.programMode = initData.programMode; diff --git a/public/js/v1.3.2/app/ui/dialog/map_settings.js b/public/js/v1.3.2/app/ui/dialog/map_settings.js index 6a4a2dff..8a5ce284 100644 --- a/public/js/v1.3.2/app/ui/dialog/map_settings.js +++ b/public/js/v1.3.2/app/ui/dialog/map_settings.js @@ -33,6 +33,10 @@ define([ slackChannelHistoryId: 'pf-map-dialog-slack-channel-history', // id for Slack channel "history" slackChannelRallyId: 'pf-map-dialog-slack-channel-rally', // id for Slack channel "rally" + discordUsernameId: 'pf-map-dialog-discord-username', // id for Discord "username" + discordWebHookURLRallyId: 'pf-map-dialog-discord-url-rally', // id for Discord "rally" webHookUrl + discordWebHookURLHistoryId: 'pf-map-dialog-discord-url-history', // id for Discord "history" webHookUrl + characterSelectId: 'pf-map-dialog-character-select', // id for "character" select corporationSelectId: 'pf-map-dialog-corporation-select', // id for "corporation" select allianceSelectId: 'pf-map-dialog-alliance-select', // id for "alliance" select @@ -133,6 +137,14 @@ define([ let slackRallyEnabled = false; let slackSectionShow = false; + let discordUsername = ''; + let discordWebHookURLRally = ''; + let discordWebHookURLHistory = ''; + let discordEnabled = false; + let discordRallyEnabled = false; + let discordHistoryEnabled = false; + let discordSectionShow = false; + if(mapData !== false){ // set current map information contentEditMap.find('input[name="id"]').val( mapData.config.id ); @@ -162,6 +174,14 @@ define([ slackRallyEnabled = slackEnabled && Boolean(Util.getObjVal(Init.mapTypes, mapData.config.type.name + '.defaultConfig.send_rally_slack_enabled')); slackSectionShow = (slackEnabled && slackWebHookURL.length > 0); + discordUsername = Util.getObjVal(mapData, 'config.logging.discordUsername'); + discordWebHookURLRally = Util.getObjVal(mapData, 'config.logging.discordWebHookURLRally'); + discordWebHookURLHistory = Util.getObjVal(mapData, 'config.logging.discordWebHookURLHistory'); + discordEnabled = Boolean(Util.getObjVal(Init, 'discord.status')); + discordRallyEnabled = discordEnabled && Boolean(Util.getObjVal(Init.mapTypes, mapData.config.type.name + '.defaultConfig.send_rally_discord_enabled')); + discordHistoryEnabled = discordEnabled && Boolean(Util.getObjVal(Init.mapTypes, mapData.config.type.name + '.defaultConfig.send_history_discord_enabled')); + discordSectionShow = (discordEnabled && (discordWebHookURLRally.length > 0 || discordWebHookURLHistory.length > 0)); + // remove "#" from Slack channels slackChannelHistory = slackChannelHistory.indexOf('#') === 0 ? slackChannelHistory.substr(1) : slackChannelHistory; slackChannelRally = slackChannelRally.indexOf('#') === 0 ? slackChannelRally.substr(1) : slackChannelRally; @@ -221,6 +241,17 @@ define([ slackRallyEnabled: slackRallyEnabled, slackSectionShow: slackSectionShow, + discordUsernameId: config.discordUsernameId, + discordWebHookURLRallyId: config.discordWebHookURLRallyId, + discordWebHookURLHistoryId: config.discordWebHookURLHistoryId, + discordUsername: discordUsername, + discordWebHookURLRally: discordWebHookURLRally, + discordWebHookURLHistory: discordWebHookURLHistory, + discordEnabled: discordEnabled, + discordRallyEnabled: discordRallyEnabled, + discordHistoryEnabled: discordHistoryEnabled, + discordSectionShow: discordSectionShow, + characterSelectId: config.characterSelectId, corporationSelectId: config.corporationSelectId, allianceSelectId: config.allianceSelectId, diff --git a/public/templates/dialog/map.html b/public/templates/dialog/map.html index fb3e5801..7ba3f385 100644 --- a/public/templates/dialog/map.html +++ b/public/templates/dialog/map.html @@ -111,15 +111,15 @@ {{! Slack notification --------------------------------------------- }} -