Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
innosflew committed Mar 9, 2017
1 parent 44858f6 commit 6eb2bb2
Showing 1 changed file with 53 additions and 20 deletions.
73 changes: 53 additions & 20 deletions DiscordNotifications/DiscordNotificationsCore.php
Expand Up @@ -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.
Expand Down Expand Up @@ -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),
Expand All @@ -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;
}

Expand All @@ -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");
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;

Expand All @@ -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 .= '}';
Expand Down Expand Up @@ -360,4 +390,7 @@ static function push_discord_notify($message, $user)
}
}
}

// some modifications by uzalu

?>

0 comments on commit 6eb2bb2

Please sign in to comment.