From 427ba332bd135fe2d73d88c7f29d4c723ab769c9 Mon Sep 17 00:00:00 2001 From: Frisk Date: Fri, 22 Jun 2018 12:18:22 +0200 Subject: [PATCH] Added and closing #10, updated settings example --- rcgcdw.py | 26 +++++++++++++++----------- settings.json.example | 2 ++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/rcgcdw.py b/rcgcdw.py index c80aea1..c969730 100644 --- a/rcgcdw.py +++ b/rcgcdw.py @@ -1,9 +1,6 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -#WARNING! SHITTY CODE AHEAD. ENTER ONLY IF YOU ARE SURE YOU CAN TAKE IT -#You have been warned - #Recent changes Gamepedia compatible Discord webhook is a project for using a webhook as recent changes page from MediaWiki. #Copyright (C) 2018 Frisk @@ -20,6 +17,9 @@ #You should have received a copy of the GNU Affero General Public License #along with this program. If not, see . +#WARNING! SHITTY CODE AHEAD. ENTER ONLY IF YOU ARE SURE YOU CAN TAKE IT +#You have been warned + import time, logging, json, requests, datetime, re, gettext, math, random, os.path, schedule, sys from bs4 import BeautifulSoup from collections import defaultdict, Counter @@ -163,13 +163,16 @@ def webhook_formatter(action, STATIC, **params): user = params["blocked_user"].split(':')[1] embed["title"] = _("Unblocked {blocked_user}").format(blocked_user=user) elif action == 25: - link = "https://{wiki}.gamepedia.com/UserProfile:{target}".format(wiki=settings["wiki"], target=params["target"].replace(" ", "_").replace(')', '\)')) + link = "https://{wiki}.gamepedia.com/Special:CommentPermalink/{commentid}".format(wiki=settings["wiki"], commentid=params["commentid"]) + #link = "https://{wiki}.gamepedia.com/UserProfile:{target}".format(wiki=settings["wiki"], target=params["target"].replace(" ", "_").replace(')', '\)')) old way of linking embed["title"] = _("Left a comment on {target}'s profile").format(target=params["target"]) elif action == 29: - link = "https://{wiki}.gamepedia.com/UserProfile:{target}".format(wiki=settings["wiki"], target=params["target"].replace(" ", "_").replace(')', '\)')) + #link = "https://{wiki}.gamepedia.com/UserProfile:{target}".format(wiki=settings["wiki"], target=params["target"].replace(" ", "_").replace(')', '\)')) + link = "https://{wiki}.gamepedia.com/Special:CommentPermalink/{commentid}".format(wiki=settings["wiki"], commentid=params["commentid"]) embed["title"] = _("Replied to a comment on {target}'s profile").format(target=params["target"]) elif action == 26: - link = "https://{wiki}.gamepedia.com/UserProfile:{target}".format(wiki=settings["wiki"], target=params["target"].replace(" ", "_").replace(')', '\)')) + #link = "https://{wiki}.gamepedia.com/UserProfile:{target}".format(wiki=settings["wiki"], target=params["target"].replace(" ", "_").replace(')', '\)')) + link = "https://{wiki}.gamepedia.com/Special:CommentPermalink/{commentid}".format(wiki=settings["wiki"], commentid=params["commentid"]) embed["title"] = _("Edited a comment on {target}'s profile").format(target=params["target"]) elif action == 28: link = "https://{wiki}.gamepedia.com/UserProfile:{target}".format(wiki=settings["wiki"], target=params["target"].replace(" ", "_").replace(')', '\)')) @@ -200,7 +203,8 @@ def webhook_formatter(action, STATIC, **params): embed["title"] = _("Edited {target}'s profile").format(target=params["target"]) params["desc"] = _("{field} field changed to: {desc}").format(field=field, desc=params["desc"]) elif action == 27: - link = "https://{wiki}.gamepedia.com/UserProfile:{target}".format(wiki=settings["wiki"], target=params["target"].replace(" ", "_").replace(')', '\)')) + link = "https://{wiki}.gamepedia.com/Special:CommentPermalink/{commentid}".format(wiki=settings["wiki"], commentid=params["commentid"]) + #link = "https://{wiki}.gamepedia.com/UserProfile:{target}".format(wiki=settings["wiki"], target=params["target"].replace(" ", "_").replace(')', '\)')) embed["title"] = _("Deleted a comment on {target}'s profile").format(target=params["target"]) elif action == 20: link = "https://{wiki}.gamepedia.com/"+params["user"].replace(" ", "_").replace(')', '\)') @@ -369,15 +373,15 @@ def first_pass(change): #I've decided to split the embed formatter and change ha elif logtype=="interwiki" and logaction=="iw_delete": webhook_formatter(24, STATIC_VARS, user=change["user"], desc=parsedcomment, prefix=change["logparams"]['0']) elif logtype=="curseprofile" and logaction=="comment-created": - webhook_formatter(25, STATIC_VARS, user=change["user"], target=change["title"].split(':')[1]) + webhook_formatter(25, STATIC_VARS, user=change["user"], target=change["title"].split(':')[1], commentid=change["logparams"]["0"]) elif logtype=="curseprofile" and logaction=="comment-edited": - webhook_formatter(26, STATIC_VARS, user=change["user"], target=change["title"].split(':')[1]) + webhook_formatter(26, STATIC_VARS, user=change["user"], target=change["title"].split(':')[1], commentid=change["logparams"]["0"]) elif logtype=="curseprofile" and logaction=="comment-deleted": - webhook_formatter(27, STATIC_VARS, user=change["user"], target=change["title"].split(':')[1]) + webhook_formatter(27, STATIC_VARS, user=change["user"], target=change["title"].split(':')[1], commentid=change["logparams"]["0"]) elif logtype=="curseprofile" and logaction=="profile-edited": webhook_formatter(28, STATIC_VARS, user=change["user"], target=change["title"].split(':')[1], field=change["logparams"]['0'], desc=change["parsedcomment"]) elif logtype=="curseprofile" and logaction=="comment-replied": - webhook_formatter(29, STATIC_VARS, user=change["user"], target=change["title"].split(':')[1]) + webhook_formatter(29, STATIC_VARS, user=change["user"], target=change["title"].split(':')[1], commentid=change["logparams"]["0"]) elif logtype=="contentmodel" and logaction=="change": webhook_formatter(30, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment, oldmodel=change["logparams" ]["oldmodel"], newmodel=change["logparams" ]["newmodel"]) elif logtype=="sprite" and logaction=="sprite": diff --git a/settings.json.example b/settings.json.example index b6e4861..9797d12 100644 --- a/settings.json.example +++ b/settings.json.example @@ -16,6 +16,8 @@ }, "verbose_level": 0, "show_updown_messages": true, + "overview": false, + "overview_UTC_time": "00:00", "appearance":{ "daily_overview": { "color": 16312092,