Compare commits

..

2 Commits

Author SHA1 Message Date
Jayden Bailey fa9149165d Bump version and update readme 2019-06-16 13:39:56 +01:00
Jayden Bailey ca3a5f8047 Add option to include timestamps on messages
Closes #11
2019-06-16 13:38:15 +01:00
5 changed files with 25 additions and 5 deletions
+1
View File
@@ -49,6 +49,7 @@ This extension can be configured using the `LocalSettings.php` file in your Medi
| `$wgDiscordDisabledHooks` | array | List of hooks to disable sending webhooks for (see [below](#hooks-used)) | `[]`
| `$wgDiscordDisabledNS` | array | List of namespaces to disable sending webhooks for | `[]`
| `$wgDiscordDisabledUsers` | array | List of users whose performed actions shouldn't send webhooks | `[]`
| `$wgDiscordPrependTimestamp` | bool | Prepend a timestamp (in UTC) to all sent messages. The format can be changed by editing the MediaWiki message `discord-timestampformat` | `false`
## Hooks used
- `PageContentSaveComplete` - New edits to pages and page creations
+3 -2
View File
@@ -4,7 +4,7 @@
"[https://github.com/jaydenkieran Jayden Bailey]"
],
"url": "https://github.com/jaydenkieran/mw-discord",
"version": "1.0.5",
"version": "1.0.6",
"descriptionmsg": "discord-desc",
"license-name": "MIT",
"manifest_version": 1,
@@ -17,7 +17,8 @@
"DiscordMaxChars": null,
"DiscordDisabledHooks": [],
"DiscordDisabledNS": [],
"DiscordDisabledUsers": []
"DiscordDisabledUsers": [],
"DiscordPrependTimestamp": false
},
"AutoloadClasses": {
"DiscordHooks": "src/DiscordHooks.php",
+7 -1
View File
@@ -1,4 +1,9 @@
{
"@metadata": {
"authors": [
"Jayden Bailey"
]
},
"discord-desc": "Sends messages to a Discord channel when certain events occur",
"discord-userlinks": "$1 ($2|$3)",
"discord-revisionlinks": "($1) $2 $3",
@@ -23,5 +28,6 @@
"discord-uploadnewver": "new version of",
"discord-uploadcomplete": "$1 uploaded $2 $3 $4 ($5, $6x$7, $8)",
"discord-filedeletecomplete": "$1 deleted a version of file $2 $3",
"discord-fileundeletecomplete": "$1 restored some versions of file $2 $3"
"discord-fileundeletecomplete": "$1 restored some versions of file $2 $3",
"discord-timestampformat": "**H:i e:**"
}
+7 -1
View File
@@ -1,4 +1,9 @@
{
"@metadata": {
"authors": [
"Jayden Bailey"
]
},
"discord-desc": "The description used for the Discord extension",
"discord-userlinks": "Used for display of the user links. Parameters\n* $1 - User page link\n* $2 - discord-talk\n* $3 - discord-contribs",
"discord-revisionlinks": "Used for display of revision links. Parameters\n* $1 - discord-diff\n* $2 - discord-minor\n* $3 - discord-size",
@@ -23,5 +28,6 @@
"discord-uploadnewver": "Used as the text for $2 in discord-uploadcomplete",
"discord-uploadcomplete": "Message sent to Discord when an upload is made. Parameters:\n$1 - discord-userlinks\n$2 - discord-uploadnewver\n$3 - File link\n$4 - Comment (always surrounded in tildes)\n$5 - Size (formatted as KB/MB/GB)\n$6 - File width\n$7 - File height\n$8 - File MIME type",
"discord-filedeletecomplete": "Message sent to Discord when a file version is deleted (not an entire file). Parameters:\n$1 - discord-userlinks\n$2 - File link\n$3 - Comment (always surrounded in tildes)",
"discord-fileundeletecomplete": "Message sent to Discord when a file version is restored (not an entire file). Parameters:\n$1 - discord-userlinks\n$2 - File link\n$3 - Comment (always surrounded in tildes)"
"discord-fileundeletecomplete": "Message sent to Discord when a file version is restored (not an entire file). Parameters:\n$1 - discord-userlinks\n$2 - File link\n$3 - Comment (always surrounded in tildes)",
"discord-timestampformat": "The formatting used in the gmtime() function for displaying the time an event happened in UTC."
}
+7 -1
View File
@@ -46,7 +46,7 @@ class DiscordUtils {
* Handles sending a webhook to Discord using cURL
*/
public static function handleDiscord ($msg) {
global $wgDiscordWebhookURL;
global $wgDiscordWebhookURL, $wgDiscordPrependTimestamp;
if ( !$wgDiscordWebhookURL ) {
// There's nothing in here, so we won't do anything
@@ -67,6 +67,12 @@ class DiscordUtils {
// Strip whitespace to just one space
$stripped = preg_replace('/\s+/', ' ', $msg);
if ( $wgDiscordPrependTimestamp ) {
// Add timestamp
$dateString = gmdate( wfMessage( 'discord-timestampformat' )->text() );
$stripped = $dateString . ' ' . $stripped;
}
DeferredUpdates::addCallableUpdate( function() use ( $stripped, $urls ) {
$json_data = [ 'content' => "$stripped" ];
$json = json_encode($json_data);