This commit is contained in:
Frisk 2018-06-18 23:31:53 +02:00
parent d3f1646804
commit 546907fa84
No known key found for this signature in database
GPG key ID: 0E9A7D3C0A01586C
3 changed files with 243 additions and 87 deletions

View file

@ -2,9 +2,9 @@
Recent changes Gamepedia compatible Discord webhook is a project made from earlier recent changes module of FriskBot. It has been remade as independent script for public usage. Recent changes Gamepedia compatible Discord webhook is a project made from earlier recent changes module of FriskBot. It has been remade as independent script for public usage.
### Dependencies ### ### Dependencies ###
* **Python3 3.6>** * **Python 3.6>**
* requests 2.18.4> * requests 2.18.4>
* beautifulsoup4 4.6.0> * beautifulsoup 4.6.0>
* lxml 4.2.1> * lxml 4.2.1>
### Features ### ### Features ###
@ -26,7 +26,8 @@ Explanation for settings:
`avatars` this section makes specific types of messages overwrite the default webhook avatar `avatars` this section makes specific types of messages overwrite the default webhook avatar
* `connection_failed` message printed when script fails connection with the wiki several times * `connection_failed` message printed when script fails connection with the wiki several times
* `no_event` error message when the event couldn't be recognized by the script * `no_event` error message when the event couldn't be recognized by the script
* `embed` every embed message showing changes * `embed` every embed message showing changes
`verbose_level` a number (min 0, max 50) identifying the type of messages that will be written into the console. (CRITICAL 50, ERROR 40, WARNING 30, INFO 20, DEBUG 10) `verbose_level` a number (min 0, max 50) identifying the type of messages that will be written into the console. (CRITICAL 50, ERROR 40, WARNING 30, INFO 20, DEBUG 10)
`show_updown_messages` bool value, depending on this settings the messages whenever the wiki goes up and down will be sent to the channel `show_updown_messages` bool value, depending on this settings the messages whenever the wiki goes up and down will be sent to the channel
@ -37,6 +38,7 @@ When you are sure, use `python rcgcdw.py` command to run the script.
### Credits ### ### Credits ###
Translators: Translators:
* MarkusRost for German translation * MarkusRost for German translation
* Minecraft Wiki English Discord server community, most notably Jack McKalling for input on how the script should work, especially formatting and what information should be there
### Other ### ### Other ###
Script seem to use about 17MB of RAM and negligible amount of CPU when fetching changes. Script seem to use about 17MB of RAM and negligible amount of CPU when fetching changes.

126
rcgcdw.py
View file

@ -44,8 +44,9 @@ def safe_read(request, *keys):
return None return None
return request return request
def webhook_formatter(action, timestamp, **params): def webhook_formatter(action, STATIC, **params):
colornumber = None logging.debug("Received things: {thing}".format(thing=params))
colornumber = None if isinstance(STATIC["color"], str) else STATIC["color"]
data = {} data = {}
data["embeds"] = [] data["embeds"] = []
embed = defaultdict(dict) embed = defaultdict(dict)
@ -82,10 +83,6 @@ def webhook_formatter(action, timestamp, **params):
elif editsize == 0: elif editsize == 0:
colornumber = 8750469 colornumber = 8750469
link = "https://{wiki}.gamepedia.com/index.php?title={article}&curid={pageid}&diff={diff}&oldid={oldrev}".format(wiki=settings["wiki"], pageid=params["pageid"], diff=params["diff"], oldrev=params["oldrev"], article=article_encoded) link = "https://{wiki}.gamepedia.com/index.php?title={article}&curid={pageid}&diff={diff}&oldid={oldrev}".format(wiki=settings["wiki"], pageid=params["pageid"], diff=params["diff"], oldrev=params["oldrev"], article=article_encoded)
if action == 1:
embed["author"]["icon_url"] = "https://d1u5p3l4wpay3k.cloudfront.net/minecraft_pl_gamepedia/d/df/Ksi%C4%85%C5%BCka_z_pi%C3%B3rem.png?version=d2b085f15fb5713091ed06f92f81c360"
else:
embed["author"]["icon_url"] = "https://framapic.org/VBVcOznftNsV/4a0fbBL7wkUo.png"
embed["title"] = "{article} ({new}{minor}{editsize})".format(article=params["title"], editsize="+"+str(editsize) if editsize>0 else editsize, new= _("(N!) ") if action == 37 else "", minor=_("m ") if action == 1 and params["minor"] else "") embed["title"] = "{article} ({new}{minor}{editsize})".format(article=params["title"], editsize="+"+str(editsize) if editsize>0 else editsize, new= _("(N!) ") if action == 37 else "", minor=_("m ") if action == 1 and params["minor"] else "")
elif action == 5: #sending files elif action == 5: #sending files
urls = safe_read(recent_changes.safe_request("https://{wiki}.gamepedia.com/api.php?action=query&format=json&prop=imageinfo&list=&meta=&titles={filename}&iiprop=timestamp%7Curl&iilimit=2".format(wiki=settings["wiki"], filename=params["title"])), "query", "pages") urls = safe_read(recent_changes.safe_request("https://{wiki}.gamepedia.com/api.php?action=query&format=json&prop=imageinfo&list=&meta=&titles={filename}&iiprop=timestamp%7Curl&iilimit=2".format(wiki=settings["wiki"], filename=params["title"])), "query", "pages")
@ -97,7 +94,6 @@ def webhook_formatter(action, timestamp, **params):
else: else:
return return
if params["overwrite"]: if params["overwrite"]:
colornumber = 12390624
img_timestamp = [x for x in img_info[1]["timestamp"] if x.isdigit()] img_timestamp = [x for x in img_info[1]["timestamp"] if x.isdigit()]
undolink = "https://{wiki}.gamepedia.com/index.php?title={filename}&action=revert&oldimage={timestamp}%21{filenamewon}".format(wiki=settings["wiki"], filename=article_encoded, timestamp="".join(img_timestamp), filenamewon = article_encoded[5:]) undolink = "https://{wiki}.gamepedia.com/index.php?title={filename}&action=revert&oldimage={timestamp}%21{filenamewon}".format(wiki=settings["wiki"], filename=article_encoded, timestamp="".join(img_timestamp), filenamewon = article_encoded[5:])
embed["title"] = _("Uploaded a new version of {name}").format(name=params["title"]) embed["title"] = _("Uploaded a new version of {name}").format(name=params["title"])
@ -121,46 +117,33 @@ def webhook_formatter(action, timestamp, **params):
params["desc"] = _("{desc}\nLicense: {license}").format(desc=params["desc"], license=license) params["desc"] = _("{desc}\nLicense: {license}").format(desc=params["desc"], license=license)
elif action == 6: elif action == 6:
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded) link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded)
embed["author"]["icon_url"] = "https://framapic.org/9Rgw6Vkx1L1b/R9WrMWJ6umeX.png"
colornumber = 1
embed["title"] = _("Deleted page {article}").format(article=params["title"]) embed["title"] = _("Deleted page {article}").format(article=params["title"])
elif action == 7: elif action == 7:
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded) link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded)
embed["author"]["icon_url"] = "https://framapic.org/9Rgw6Vkx1L1b/R9WrMWJ6umeX.png"
colornumber = 1
embed["title"] = _("Deleted redirect {article} by overwriting").format(article=params["title"]) embed["title"] = _("Deleted redirect {article} by overwriting").format(article=params["title"])
elif action == 14: elif action == 14:
link = params["targetlink"] link = params["targetlink"]
embed["author"]["icon_url"] = "https://i.imgur.com/ZX02KBf.png"
params["desc"] = "{supress}. {desc}".format(desc=params["desc"], supress=_("No redirect has been made") if params["supress"] == True else _("A redirect has been made")) params["desc"] = "{supress}. {desc}".format(desc=params["desc"], supress=_("No redirect has been made") if params["supress"] == True else _("A redirect has been made"))
embed["title"] = _("Moved {article} to {target}").format(article = params["title"], target=params["target"]) embed["title"] = _("Moved {article} to {target}").format(article = params["title"], target=params["target"])
elif action == 15: elif action == 15:
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded) link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded)
embed["title"] = _("Moved {article} to {title} over redirect").format(article=params["title"], title=params["target"]) embed["title"] = _("Moved {article} to {title} over redirect").format(article=params["title"], title=params["target"])
embed["author"]["icon_url"]= "https://i.imgur.com/ZX02KBf.png"
elif action == 16: elif action == 16:
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded) link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded)
embed["title"] = _("Moved protection settings from {article} to {title}").format(article=params["title"], title=params["target"]) embed["title"] = _("Moved protection settings from {article} to {title}").format(article=params["title"], title=params["target"])
embed["author"]["icon_url"]= "https://i.imgur.com/ZX02KBf.png"
elif action == 17: elif action == 17:
link = "https://{wiki}.gamepedia.com/{user}".format(wiki=settings["wiki"], user=params["blocked_user"].replace(" ", "_").replace(')', '\)')) link = "https://{wiki}.gamepedia.com/{user}".format(wiki=settings["wiki"], user=params["blocked_user"].replace(" ", "_").replace(')', '\)'))
user = params["blocked_user"].split(':')[1] user = params["blocked_user"].split(':')[1]
time =_( "infinity and beyond") if params["duration"] == "infinite" else params["duration"] time =_( "infinity and beyond") if params["duration"] == "infinite" else params["duration"]
embed["title"] = _("Blocked {blocked_user} for {time}").format(blocked_user=user, time=time) embed["title"] = _("Blocked {blocked_user} for {time}").format(blocked_user=user, time=time)
colornumber = 1
embed["author"]["icon_url"] = "https://i.imgur.com/g7KgZHf.png"
elif action == 19: elif action == 19:
link = "https://{wiki}.gamepedia.com/{user}".format(wiki=settings["wiki"], user=params["blocked_user"].replace(" ", "_").replace(')', '\)')) link = "https://{wiki}.gamepedia.com/{user}".format(wiki=settings["wiki"], user=params["blocked_user"].replace(" ", "_").replace(')', '\)'))
user = params["blocked_user"].split(':')[1] user = params["blocked_user"].split(':')[1]
embed["title"] = _("Changed block settings for {blocked_user}").format(blocked_user=user) embed["title"] = _("Changed block settings for {blocked_user}").format(blocked_user=user)
colornumber = 1
embed["author"]["icon_url"] = "https://i.imgur.com/g7KgZHf.png"
elif action == 18: elif action == 18:
link = "https://{wiki}.gamepedia.com/{user}".format(wiki=settings["wiki"], user=params["blocked_user"].replace(" ", "_").replace(')', '\)')) link = "https://{wiki}.gamepedia.com/{user}".format(wiki=settings["wiki"], user=params["blocked_user"].replace(" ", "_").replace(')', '\)'))
user = params["blocked_user"].split(':')[1] user = params["blocked_user"].split(':')[1]
embed["title"] = _("Unblocked {blocked_user}").format(blocked_user=user) embed["title"] = _("Unblocked {blocked_user}").format(blocked_user=user)
colornumber = 1
embed["author"]["icon_url"] = "https://i.imgur.com/g7KgZHf.png"
elif action == 25: elif action == 25:
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(')', '\)'))
embed["title"] = _("Left a comment on {target}'s profile").format(target=params["target"]) embed["title"] = _("Left a comment on {target}'s profile").format(target=params["target"])
@ -215,17 +198,14 @@ def webhook_formatter(action, timestamp, **params):
elif action == 2: elif action == 2:
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded) link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded)
embed["title"] = _("Protected {target}").format(target=params["title"]) embed["title"] = _("Protected {target}").format(target=params["title"])
embed["author"]["icon_url"] ="https://i.imgur.com/Lfk0wuw.png"
params["desc"] = params["settings"] + " | " + params["desc"] params["desc"] = params["settings"] + " | " + params["desc"]
elif action == 3: elif action == 3:
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded) link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded)
embed["title"] = _("Changed protection level for {article}").format(article=params["title"]) embed["title"] = _("Changed protection level for {article}").format(article=params["title"])
params["desc"] = params["settings"] + " | " + params["desc"] params["desc"] = params["settings"] + " | " + params["desc"]
embed["author"]["icon_url"] ="https://i.imgur.com/Lfk0wuw.png"
elif action == 4: elif action == 4:
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded) link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded)
embed["title"] = _("Removed protection from {article}").format(article=params["title"]) embed["title"] = _("Removed protection from {article}").format(article=params["title"])
embed["author"]["icon_url"] ="https://i.imgur.com/Lfk0wuw.png"
elif action == 9: elif action == 9:
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded) link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded)
embed["title"] = _("Changed visibility of revision(s) on page {article} ").format(article=params["title"]) embed["title"] = _("Changed visibility of revision(s) on page {article} ").format(article=params["title"])
@ -288,12 +268,13 @@ def webhook_formatter(action, timestamp, **params):
logging.warning("No entry for {event} with params: {params}".format(event=action, params=params)) logging.warning("No entry for {event} with params: {params}".format(event=action, params=params))
embed["author"]["name"] = params["user"] embed["author"]["name"] = params["user"]
embed["author"]["url"] = author_url embed["author"]["url"] = author_url
embed["auther"]["icon"] = STATIC["icon"]
embed["url"] = link embed["url"] = link
if "desc" not in params: if "desc" not in params:
params["desc"] = "" params["desc"] = ""
embed["description"] = params["desc"] embed["description"] = params["desc"]
embed["color"] = random.randrange(1, 16777215) if colornumber is None else math.floor(colornumber) embed["color"] = random.randrange(1, 16777215) if colornumber is None else math.floor(colornumber)
embed["timestamp"] = timestamp embed["timestamp"] = STATIC["timestamp"]
data["embeds"].append(dict(embed)) data["embeds"].append(dict(embed))
data['avatar_url'] = settings["avatars"]["embed"] data['avatar_url'] = settings["avatars"]["embed"]
formatted_embed = json.dumps(data, indent=4) formatted_embed = json.dumps(data, indent=4)
@ -301,92 +282,102 @@ def webhook_formatter(action, timestamp, **params):
#logging.debug(data) #logging.debug(data)
result = requests.post(settings["webhookURL"], data=formatted_embed, headers=headers) result = requests.post(settings["webhookURL"], data=formatted_embed, headers=headers)
def first_pass(change): def first_pass(change): #I've decided to split the embed formatter and change handler, maybe it's more messy this way, I don't know
parsedcomment = (BeautifulSoup(change["parsedcomment"], "lxml")).get_text() parsedcomment = (BeautifulSoup(change["parsedcomment"], "lxml")).get_text()
logging.debug(change) logging.debug(change)
STATIC_VARS = {"timestamp": change["timestamp"]}
if not parsedcomment: if not parsedcomment:
parsedcomment = _("No description provided") parsedcomment = _("No description provided")
if change["type"] == "edit": if change["type"] == "edit":
webhook_formatter(1, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment, oldrev=change["old_revid"], pageid=change["pageid"], diff=change["revid"], size=change["newlen"]-change["oldlen"], minor= True if "minor" in change else False) STATIC_VARS = {**STATIC_VARS ,**{"color": settings["appearance"]["edit"]["color"], "icon": settings["appearance"]["edit"]["icon"]}}
webhook_formatter(1, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment, oldrev=change["old_revid"], pageid=change["pageid"], diff=change["revid"], size=change["newlen"]-change["oldlen"], minor= True if "minor" in change else False)
elif change["type"] == "log": elif change["type"] == "log":
logtype = change["logtype"] logtype = change["logtype"]
logaction = change["logaction"] logaction = change["logaction"]
combination = "{logtype}/{logaction}".format(logtype=logtype, logaction=logaction)
logging.debug("combination is {}".format(combination))
try:
settings["appearance"][combination]
except KeyError:
STATIC_VARS = {**STATIC_VARS ,**{"color": "", "icon": ""}}
logging.error("No value in the settings has been given for {}".format(combination))
STATIC_VARS = {**STATIC_VARS ,**{"color": settings["appearance"][combination]["color"], "icon": settings["appearance"][combination]["icon"]}}
if logtype=="protect" and logaction=="protect": if logtype=="protect" and logaction=="protect":
webhook_formatter(2, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment, settings=change["logparams"]["description"]) webhook_formatter(2, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment, settings=change["logparams"]["description"])
elif logtype=="protect" and logaction=="modify": elif logtype=="protect" and logaction=="modify":
webhook_formatter(3, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment, settings=change["logparams"]["description"]) webhook_formatter(3, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment, settings=change["logparams"]["description"])
elif logtype=="protect" and logaction=="unprotect": elif logtype=="protect" and logaction=="unprotect":
webhook_formatter(4, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment) webhook_formatter(4, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment)
elif logtype=="upload" and logaction=="overwrite": elif logtype=="upload" and logaction=="overwrite":
webhook_formatter(5, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment, overwrite=True) webhook_formatter(5, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment, overwrite=True)
elif logtype=="upload": elif logtype=="upload":
webhook_formatter(5, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment, overwrite=False) webhook_formatter(5, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment, overwrite=False)
elif logtype=="delete" and logaction=="delete": elif logtype=="delete" and logaction=="delete":
webhook_formatter(6, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment) webhook_formatter(6, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment)
elif logtype=="delete" and logaction=="delete_redir": elif logtype=="delete" and logaction=="delete_redir":
webhook_formatter(7, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment) webhook_formatter(7, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment)
elif logtype=="delete" and logaction=="restore": elif logtype=="delete" and logaction=="restore":
webhook_formatter(8, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment) webhook_formatter(8, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment)
elif logtype=="delete" and logaction=="revision": elif logtype=="delete" and logaction=="revision":
webhook_formatter(9, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment) webhook_formatter(9, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment)
elif logtype=="delete" and logaction=="event": elif logtype=="delete" and logaction=="event":
webhook_formatter(10, change["timestamp"], user=change["user"], desc=parsedcomment) webhook_formatter(10, STATIC_VARS, user=change["user"], desc=parsedcomment)
elif logtype=="import" and logaction=="upload": elif logtype=="import" and logaction=="upload":
webhook_formatter(11, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment, amount=change["logparams"]["count"]) webhook_formatter(11, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment, amount=change["logparams"]["count"])
elif logtype=="import" and logaction=="interwiki": elif logtype=="import" and logaction=="interwiki":
webhook_formatter(12, change["timestamp"], user=change["user"], desc=parsedcomment) webhook_formatter(12, STATIC_VARS, user=change["user"], desc=parsedcomment)
elif logtype=="merge" : elif logtype=="merge" :
webhook_formatter(13, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment, destination=change["logparams"]["dest_title"]) webhook_formatter(13, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment, destination=change["logparams"]["dest_title"])
elif logtype=="move" and logaction=="move": elif logtype=="move" and logaction=="move":
webhook_formatter(14, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment, supress=True if "suppressredirect" in change["logparams"] else False, target=change["logparams"]['target_title'], targetlink="https://{wiki}.gamepedia.com/".format(wiki=settings["wiki"]) + change["logparams"]['target_title'].replace(" ", "_")) #TODO Remove the link making in here webhook_formatter(14, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment, supress=True if "suppressredirect" in change["logparams"] else False, target=change["logparams"]['target_title'], targetlink="https://{wiki}.gamepedia.com/".format(wiki=settings["wiki"]) + change["logparams"]['target_title'].replace(" ", "_")) #TODO Remove the link making in here
elif logtype=="move" and logaction=="move_redir": elif logtype=="move" and logaction=="move_redir":
webhook_formatter(15, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment, target=change["logparams"]["target_title"]) webhook_formatter(15, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment, target=change["logparams"]["target_title"])
elif logtype=="protect" and logaction=="move_prot": elif logtype=="protect" and logaction=="move_prot":
webhook_formatter(16, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment, target=change["logparams"]["oldtitle_title"]) webhook_formatter(16, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment, target=change["logparams"]["oldtitle_title"])
elif logtype=="block" and logaction=="block": elif logtype=="block" and logaction=="block":
webhook_formatter(17, change["timestamp"], user=change["user"], blocked_user=change["title"], desc=parsedcomment, duration=change["logparams"]["duration"]) webhook_formatter(17, STATIC_VARS, user=change["user"], blocked_user=change["title"], desc=parsedcomment, duration=change["logparams"]["duration"])
elif logtype=="block" and logaction=="unblock": elif logtype=="block" and logaction=="unblock":
webhook_formatter(18, change["timestamp"], user=change["user"], blocked_user=change["title"], desc=parsedcomment) webhook_formatter(18, STATIC_VARS, user=change["user"], blocked_user=change["title"], desc=parsedcomment)
elif logtype=="block": elif logtype=="block":
webhook_formatter(19, change["timestamp"], user=change["user"], blocked_user=change["title"], desc=parsedcomment) webhook_formatter(19, STATIC_VARS, user=change["user"], blocked_user=change["title"], desc=parsedcomment)
elif logtype=="rights": elif logtype=="rights":
webhook_formatter(20, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment, old_groups=' '.join(change["logparams"]["oldgroups"]), new_groups=' '.join(change["logparams"]["newgroups"])) webhook_formatter(20, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment, old_groups=' '.join(change["logparams"]["oldgroups"]), new_groups=' '.join(change["logparams"]["newgroups"]))
elif logtype=="abusefilter": elif logtype=="abusefilter":
webhook_formatter(21, change["timestamp"], user=change["user"], desc=parsedcomment, filternr=change["logparams"]['1']) webhook_formatter(21, STATIC_VARS, user=change["user"], desc=parsedcomment, filternr=change["logparams"]['1'])
elif logtype=="interwiki" and logaction=="iw_add": elif logtype=="interwiki" and logaction=="iw_add":
webhook_formatter(22, change["timestamp"], user=change["user"], desc=parsedcomment, prefix=change["logparams"]['0'], website=change["logparams"]['1']) webhook_formatter(22, STATIC_VARS, user=change["user"], desc=parsedcomment, prefix=change["logparams"]['0'], website=change["logparams"]['1'])
elif logtype=="interwiki" and logaction=="iw_edit": elif logtype=="interwiki" and logaction=="iw_edit":
webhook_formatter(23, change["timestamp"], user=change["user"], desc=parsedcomment, prefix=change["logparams"]['0'], website=change["logparams"]['1']) webhook_formatter(23, STATIC_VARS, user=change["user"], desc=parsedcomment, prefix=change["logparams"]['0'], website=change["logparams"]['1'])
elif logtype=="interwiki" and logaction=="iw_delete": elif logtype=="interwiki" and logaction=="iw_delete":
webhook_formatter(24, change["timestamp"], user=change["user"], desc=parsedcomment, prefix=change["logparams"]['0']) webhook_formatter(24, STATIC_VARS, user=change["user"], desc=parsedcomment, prefix=change["logparams"]['0'])
elif logtype=="curseprofile" and logaction=="comment-created": elif logtype=="curseprofile" and logaction=="comment-created":
webhook_formatter(25, change["timestamp"], user=change["user"], target=change["title"].split(':')[1]) webhook_formatter(25, STATIC_VARS, user=change["user"], target=change["title"].split(':')[1])
elif logtype=="curseprofile" and logaction=="comment-edited": elif logtype=="curseprofile" and logaction=="comment-edited":
webhook_formatter(26, change["timestamp"], user=change["user"], target=change["title"].split(':')[1]) webhook_formatter(26, STATIC_VARS, user=change["user"], target=change["title"].split(':')[1])
elif logtype=="curseprofile" and logaction=="comment-deleted": elif logtype=="curseprofile" and logaction=="comment-deleted":
webhook_formatter(27, change["timestamp"], user=change["user"], target=change["title"].split(':')[1]) webhook_formatter(27, STATIC_VARS, user=change["user"], target=change["title"].split(':')[1])
elif logtype=="curseprofile" and logaction=="profile-edited": elif logtype=="curseprofile" and logaction=="profile-edited":
webhook_formatter(28, change["timestamp"], user=change["user"], target=change["title"].split(':')[1], field=change["logparams"]['0'], desc=change["parsedcomment"]) 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": elif logtype=="curseprofile" and logaction=="comment-replied":
webhook_formatter(29, change["timestamp"], user=change["user"], target=change["title"].split(':')[1]) webhook_formatter(29, STATIC_VARS, user=change["user"], target=change["title"].split(':')[1])
elif logtype=="contentmodel" and logaction=="change": elif logtype=="contentmodel" and logaction=="change":
webhook_formatter(30, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment, oldmodel=change["logparams" ]["oldmodel"], newmodel=change["logparams" ]["newmodel"]) 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": #spritesheet extension present on English Minecraft Wiki elif logtype=="sprite" and logaction=="sprite":
webhook_formatter(31, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment) webhook_formatter(31, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment)
elif logtype=="sprite" and logaction=="sheet": elif logtype=="sprite" and logaction=="sheet":
webhook_formatter(32, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment) webhook_formatter(32, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment)
elif logtype=="sprite" and logaction=="slice": elif logtype=="sprite" and logaction=="slice":
webhook_formatter(33, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment) webhook_formatter(33, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment)
elif logtype=="managetags" and logaction=="create": elif logtype=="managetags" and logaction=="create":
webhook_formatter(34, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment, additional=change["logparams"]) webhook_formatter(34, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment, additional=change["logparams"])
elif logtype=="managetags" and logaction=="delete": elif logtype=="managetags" and logaction=="delete":
webhook_formatter(35, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment, additional=change["logparams"]) webhook_formatter(35, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment, additional=change["logparams"])
elif logtype=="managetags" and logaction=="activate": elif logtype=="managetags" and logaction=="activate":
webhook_formatter(36, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment, additional=change["logparams"]) webhook_formatter(36, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment, additional=change["logparams"])
elif logtype=="managetags" and logaction=="deactivate": elif logtype=="managetags" and logaction=="deactivate":
webhook_formatter(38, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment, additional=change["logparams"]) webhook_formatter(38, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment, additional=change["logparams"])
elif logtype=="tag" and logaction=="update": elif logtype=="tag" and logaction=="update":
webhook_formatter(39, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment) webhook_formatter(39, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment)
else: else:
logging.warning("No entry matches given change!") logging.warning("No entry matches given change!")
print (change) print (change)
@ -397,7 +388,8 @@ def first_pass(change):
print (change) print (change)
return return
elif change["type"] == "new": #new page elif change["type"] == "new": #new page
webhook_formatter(37, change["timestamp"], user=change["user"], title=change["title"], desc=parsedcomment, oldrev=change["old_revid"], pageid=change["pageid"], diff=change["revid"], size=change["newlen"]) STATIC_VARS = {**STATIC_VARS ,**{"color": settings["appearance"]["new"]["color"], "icon": settings["appearance"]["new"]["icon"]}}
webhook_formatter(37, STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment, oldrev=change["old_revid"], pageid=change["pageid"], diff=change["revid"], size=change["newlen"])
class recent_changes(object): class recent_changes(object):
starttime = time.time() starttime = time.time()
@ -412,7 +404,7 @@ class recent_changes(object):
file_id = int(record.read().strip()) file_id = int(record.read().strip())
logging.debug("File_id is {val}".format(val=file_id)) logging.debug("File_id is {val}".format(val=file_id))
else: else:
file_id = 999999999 file_id = 999999999 #such value won't cause trouble, and it will make sure no refetch happens
def add_cache(self, change): def add_cache(self, change):
self.ids.append(change["rcid"]) self.ids.append(change["rcid"])
#self.recent_id = change["rcid"] #self.recent_id = change["rcid"]

View file

@ -1,19 +1,181 @@
{ {
"cooldown": 30, "cooldown": 30,
"wiki": "minecraft", "wiki": "minecraft",
"lang": "en", "lang": "en",
"header": { "header": {
"user-agent": "FrisksRcGcDw/0.5" "user-agent": "FrisksRcGcDw/0.5"
}, },
"limit": 11, "limit": 11,
"webhookURL": "https://discordapp.com/api/webhooks/111111111111111111/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "webhookURL": "https://discordapp.com/api/webhooks/111111111111111111/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"limitrefetch": 28, "limitrefetch": 28,
"wikiname": "Minecraft Wiki", "wikiname": "Minecraft Wiki",
"avatars": { "avatars": {
"connection_failed": "https://i.imgur.com/2jWQEt1.png", "connection_failed": "https://i.imgur.com/2jWQEt1.png",
"no_event": "", "no_event": "",
"embed": "" "embed": ""
}, },
"verbose_level": 0, "verbose_level": 0,
"show_updown_messages": true "show_updown_messages": true,
"appearance":{
"new":{
"icon":"https://framapic.org/VBVcOznftNsV/4a0fbBL7wkUo.png",
"color":"THIS COLOR DEPENDS ON EDIT SIZE, PLEASE DON'T CHANGE"
},
"edit":{
"icon":"https://d1u5p3l4wpay3k.cloudfront.net/minecraft_pl_gamepedia/d/df/Ksi%C4%85%C5%BCka_z_pi%C3%B3rem.png?version=d2b085f15fb5713091ed06f92f81c360",
"color":"THIS COLOR DEPENDS ON EDIT SIZE, PLEASE DON'T CHANGE"
},
"upload/overwrite":{
"icon":"",
"color":12390624
},
"upload/upload":{
"icon":"",
"color":null
},
"delete/delete":{
"icon":"https://framapic.org/9Rgw6Vkx1L1b/R9WrMWJ6umeX.png",
"color":1
},
"delete/delete_redir":{
"icon":"https://framapic.org/9Rgw6Vkx1L1b/R9WrMWJ6umeX.png",
"color":1
},
"delete/restore":{
"icon":"",
"color":null
},
"delete/revision":{
"icon":"",
"color":null
},
"delete/event":{
"icon":"",
"color":null
},
"merge/merge":{
"icon":"",
"color":null
},
"move/move":{
"icon":"https://i.imgur.com/ZX02KBf.png",
"color":null
},
"move/move_redir":{
"icon":"https://i.imgur.com/ZX02KBf.png",
"color":null
},
"block/block":{
"icon":"https://i.imgur.com/g7KgZHf.png",
"color":1
},
"block/unblock":{
"icon":"https://i.imgur.com/g7KgZHf.png",
"color":1
},
"block/reblock":{
"icon":"https://i.imgur.com/g7KgZHf.png",
"color":1
},
"protect/protect":{
"icon":"https://i.imgur.com/Lfk0wuw.png",
"color":null
},
"protect/modify":{
"icon":"https://i.imgur.com/Lfk0wuw.png",
"color":null
},
"protect/move_prot":{
"icon":"https://i.imgur.com/ZX02KBf.png",
"color":null
},
"protect/unprotect":{
"icon":"https://i.imgur.com/Lfk0wuw.png",
"color":null
},
"import/upload":{
"icon":"",
"color":null
},
"import/interwiki":{
"icon":"",
"color":null
},
"rights/rights":{
"icon":"",
"color":null
},
"abusefilter/abusefilter":{
"icon":"",
"color":null
},
"interwiki/iw_add":{
"icon":"",
"color":null
},
"interwiki/iw_edit":{
"icon":"",
"color":null
},
"interwiki/iw_delete":{
"icon":"",
"color":null
},
"curseprofile/comment-created":{
"icon":"",
"color":null
},
"curseprofile/comment-edited":{
"icon":"",
"color":null
},
"curseprofile/comment-deleted":{
"icon":"",
"color":null
},
"curseprofile/comment-replied":{
"icon":"",
"color":null
},
"curseprofile/profile-edited":{
"icon":"",
"color":null
},
"contentmodel/change":{
"icon":"",
"color":null
},
"sprite/sprite":{
"icon":"",
"color":null
},
"sprite/sheet":{
"icon":"",
"color":null
},
"sprite/slice":{
"icon":"",
"color":null
},
"managetags/create":{
"icon":"",
"color":null
},
"managetags/delete":{
"icon":"",
"color":null
},
"managetags/activate":{
"icon":"",
"color":null
},
"managetags/deactivate":{
"icon":"",
"color":null
},
"tag/update":{
"icon":"",
"color":null
}
}
} }