From 6eb2bb2e54ebc209594b5608cd1cc2e865040102 Mon Sep 17 00:00:00 2001 From: innosflew Date: Thu, 9 Mar 2017 21:03:58 +0100 Subject: [PATCH] Add files via upload --- .../DiscordNotificationsCore.php | 73 ++++++++++++++----- 1 file changed, 53 insertions(+), 20 deletions(-) diff --git a/DiscordNotifications/DiscordNotificationsCore.php b/DiscordNotifications/DiscordNotificationsCore.php index 923f483..d4db5a4 100644 --- a/DiscordNotifications/DiscordNotificationsCore.php +++ b/DiscordNotifications/DiscordNotificationsCore.php @@ -8,7 +8,6 @@ private static function parseurl($url) { return str_replace(" ", "%20", $url); } - /** * Gets nice HTML text for user containing the link to user page * and also links to user site, groups editing, talk and contribs pages. @@ -124,7 +123,7 @@ static function discord_article_saved(WikiPage $article, $user, $content, $summa if ($isMinor && $wgDiscordIgnoreMinorEdits) return; $message = sprintf( - "%s has %s article %s %s", + "📝 %s has %s article %s %s", self::getDiscordUserText($user), $isMinor == true ? "made minor edit to" : "edited", self::getDiscordArticleText($article, true), @@ -135,7 +134,7 @@ static function discord_article_saved(WikiPage $article, $user, $content, $summa " (%+d bytes)", $article->getRevision()->getSize() - $article->getRevision()->getPrevious()->getSize()); } - self::push_discord_notify($message, $user); + self::push_discord_notify($message, $user, 'article_saved'); return true; } @@ -152,7 +151,7 @@ static function discord_article_inserted(WikiPage $article, $user, $text, $summa if ($article->getTitle()->getNsText() == "File") return true; $message = sprintf( - "%s has created article %s %s", + "📄 %s has created article %s %s", self::getDiscordUserText($user), self::getDiscordArticleText($article), $summary == "" ? "" : "Summary: $summary"); @@ -162,7 +161,7 @@ static function discord_article_inserted(WikiPage $article, $user, $text, $summa " (%d bytes)", $article->getRevision()->getSize()); } - self::push_discord_notify($message, $user); + self::push_discord_notify($message, $user, 'article_inserted'); return true; } @@ -176,11 +175,11 @@ static function discord_article_deleted(WikiPage $article, $user, $reason, $id) if (!$wgDiscordNotificationRemovedArticle) return; $message = sprintf( - "%s has deleted article %s Reason: %s", + "❌ %s has deleted article %s Reason: %s", self::getDiscordUserText($user), self::getDiscordArticleText($article), $reason); - self::push_discord_notify($message, $user); + self::push_discord_notify($message, $user, 'article_deleted'); return true; } @@ -194,12 +193,12 @@ static function discord_article_moved($title, $newtitle, $user, $oldid, $newid, if (!$wgDiscordNotificationMovedArticle) return; $message = sprintf( - "%s has moved article %s to %s. Reason: %s", + "➡ %s has moved article %s to %s. Reason: %s", self::getDiscordUserText($user), self::getDiscordTitleText($title), self::getDiscordTitleText($newtitle), $reason); - self::push_discord_notify($message, $user); + self::push_discord_notify($message, $user, 'article_moved'); return true; } @@ -213,12 +212,12 @@ static function discord_article_protected($article, $user, $protect, $reason, $m if (!$wgDiscordNotificationProtectedArticle) return; $message = sprintf( - "%s has %s article %s. Reason: %s", + "🔒 %s has %s article %s. Reason: %s", self::getDiscordUserText($user), $protect ? "changed protection of" : "removed protection of", self::getDiscordArticleText($article), $reason); - self::push_discord_notify($message, $user); + self::push_discord_notify($message, $user, 'article_protected'); return true; } @@ -249,10 +248,10 @@ static function discord_new_user_account($user, $byEmail) } $message = sprintf( - "New user account %s was just created %s", + "👥 New user account %s was just created %s", self::getDiscordUserText($user), $messageExtra); - self::push_discord_notify($message, $user); + self::push_discord_notify($message, $user, 'new_user_account'); return true; } @@ -267,15 +266,15 @@ static function discord_file_uploaded($image) global $wgWikiUrl, $wgWikiUrlEnding, $wgUser; $message = sprintf( - "%s has uploaded file <%s|%s> (format: %s, size: %s MB, summary: %s)", + "📤 %s has uploaded file <%s|%s> (format: %s, size: %s MB, summary: %s)", self::getDiscordUserText($wgUser->mName), - $wgWikiUrl . $wgWikiUrlEnding . $image->getLocalFile()->getTitle(), + self::parseurl($wgWikiUrl . $wgWikiUrlEnding . $image->getLocalFile()->getTitle()), $image->getLocalFile()->getTitle(), $image->getLocalFile()->getMimeType(), round($image->getLocalFile()->size / 1024 / 1024, 3), $image->getLocalFile()->getDescription()); - self::push_discord_notify($message, $wgUser); + self::push_discord_notify($message, $wgUser, 'file_uploaded'); return true; } @@ -290,13 +289,13 @@ static function discord_user_blocked(Block $block, $user) global $wgWikiUrl, $wgWikiUrlEnding, $wgWikiUrlEndingBlockList; $message = sprintf( - "%s has blocked %s %s Block expiration: %s. %s", + "🚫 %s has blocked %s %s Block expiration: %s. %s", self::getDiscordUserText($user), self::getDiscordUserText($block->getTarget()), $block->mReason == "" ? "" : "with reason '".$block->mReason."'.", $block->mExpiry, "<".self::parseurl($wgWikiUrl.$wgWikiUrlEnding.$wgWikiUrlEndingBlockList)."|List of all blocks>."); - self::push_discord_notify($message, $user); + self::push_discord_notify($message, $user, 'user_blocked'); return true; } @@ -305,7 +304,7 @@ static function discord_user_blocked(Block $block, $user) * @param message Message to be sent. * @see https://discordapp.com/developers/docs/resources/webhook#execute-webhook */ - static function push_discord_notify($message, $user) + static function push_discord_notify($message, $user, $action) { global $wgDiscordIncomingWebhookUrl, $wgDiscordFromName, $wgDiscordSendMethod, $wgExcludedPermission, $wgSitename; @@ -327,8 +326,39 @@ static function push_discord_notify($message, $user) $message = preg_replace("~(<)(http)([^|]*)(\|)([^\>]*)(>)~", "[$5]($2$3)", $message); $message = str_replace(array("\r", "\n"), '', $message); + + $colour = 11777212; + switch($action){ + case 'article_saved': + $colour = 2993970; + break; + case 'article_inserted': + $colour = 3580392; + break; + case 'article_deleted': + $colour = 15217973; + break; + case 'article_moved': + $colour = 14038504; + break; + case 'article_protected': + $colour = 3493864; + break; + case 'new_user_account': + $colour = 3580392; + break; + case 'file_uploaded': + $colour = 3580392; + break; + case 'user_blocked': + $colour = 15217973; + break; + default: + $colour = 11777212; + break; + } - $post = sprintf('{"content": "%s", "username": "%s"', + $post = sprintf('{"embeds": [{ "color" : "'.$colour.'" ,"description" : "%s"}], "username": "%s"', $message, $discordFromName); $post .= '}'; @@ -360,4 +390,7 @@ static function push_discord_notify($message, $user) } } } + +// some modifications by uzalu + ?>