mirror of
https://gitlab.com/chicken-riders/RcGcDw.git
synced 2025-02-22 00:14:10 +00:00
migrate config from falsy values to null
This commit is contained in:
parent
6881838ba5
commit
36c4ba2b7c
|
@ -141,7 +141,7 @@ _DiscordMessage is a class taking care of creation of Discord messages that can
|
||||||
DiscordMessage object when created with message_type == embed will take all assignments and reads using object[key] as ones reading/setting the actual embed object.
|
DiscordMessage object when created with message_type == embed will take all assignments and reads using object[key] as ones reading/setting the actual embed object.
|
||||||
DiscordMessage consists of the following:
|
DiscordMessage consists of the following:
|
||||||
- `__init__(message_type: str, event_type: str, webhook_url: str, content=None)` – constructor which takes message type (can be either `embed` or `compact`), event_type (for example `protect/protect`), webhook_url (full URL of webhook message is intended to be sent to), content optional parameter used in compact messages as main body
|
- `__init__(message_type: str, event_type: str, webhook_url: str, content=None)` – constructor which takes message type (can be either `embed` or `compact`), event_type (for example `protect/protect`), webhook_url (full URL of webhook message is intended to be sent to), content optional parameter used in compact messages as main body
|
||||||
- `set_author(name, url, icon_url="")` – a method that can be used to set username, URL to their profile and optionally an icon for the embed
|
- `set_author(name, url, icon_url=None)` – a method that can be used to set username, URL to their profile and optionally an icon for the embed
|
||||||
- `add_field(name, value, inline=False)` – a method to add a field with given name and value, optional inline argument can be set if field should be inline
|
- `add_field(name, value, inline=False)` – a method to add a field with given name and value, optional inline argument can be set if field should be inline
|
||||||
- `set_avatar(url)` – sets avatar for WEBHOOK MESSAGE (not to be confused with actual embed)
|
- `set_avatar(url)` – sets avatar for WEBHOOK MESSAGE (not to be confused with actual embed)
|
||||||
- `set_name(name)` – sets name for WEBHOOK MESSAGE
|
- `set_name(name)` – sets name for WEBHOOK MESSAGE
|
||||||
|
|
|
@ -282,7 +282,7 @@ class AdvancedSettings:
|
||||||
if settings["show_updown_messages"]:
|
if settings["show_updown_messages"]:
|
||||||
option = default_or_custom(
|
option = default_or_custom(
|
||||||
input("Provide a link for a custom webhook avatar when the wiki goes DOWN. (default: no avatar)\n"),
|
input("Provide a link for a custom webhook avatar when the wiki goes DOWN. (default: no avatar)\n"),
|
||||||
"")
|
None)
|
||||||
try:
|
try:
|
||||||
if option:
|
if option:
|
||||||
response = requests.head(option, timeout=10.0)
|
response = requests.head(option, timeout=10.0)
|
||||||
|
@ -295,7 +295,7 @@ class AdvancedSettings:
|
||||||
option = default_or_custom(
|
option = default_or_custom(
|
||||||
input(
|
input(
|
||||||
"Provide a link for a custom webhook avatar when the connection to the wiki is RESTORED. (default: no avatar)\n"),
|
"Provide a link for a custom webhook avatar when the connection to the wiki is RESTORED. (default: no avatar)\n"),
|
||||||
"")
|
None)
|
||||||
try:
|
try:
|
||||||
if option:
|
if option:
|
||||||
response = requests.head(option, timeout=10.0)
|
response = requests.head(option, timeout=10.0)
|
||||||
|
|
|
@ -24,7 +24,7 @@ from src.configloader import settings
|
||||||
class DiscordMessage:
|
class DiscordMessage:
|
||||||
"""A class defining a typical Discord JSON representation of webhook payload."""
|
"""A class defining a typical Discord JSON representation of webhook payload."""
|
||||||
def __init__(self, message_type: str, event_type: str, webhook_url: str, content=None):
|
def __init__(self, message_type: str, event_type: str, webhook_url: str, content=None):
|
||||||
self.webhook_object = dict(allowed_mentions={"parse": []}, avatar_url=settings["avatars"].get(message_type, ""))
|
self.webhook_object = dict(allowed_mentions={"parse": []}, avatar_url=settings["avatars"].get(message_type, None))
|
||||||
self.webhook_url = webhook_url
|
self.webhook_url = webhook_url
|
||||||
|
|
||||||
if message_type == "embed":
|
if message_type == "embed":
|
||||||
|
@ -78,7 +78,7 @@ class DiscordMessage:
|
||||||
if len(self.embed["title"]) > 254:
|
if len(self.embed["title"]) > 254:
|
||||||
self.embed["title"] = self.embed["title"][0:253] + "…"
|
self.embed["title"] = self.embed["title"][0:253] + "…"
|
||||||
|
|
||||||
def set_author(self, name, url, icon_url=""):
|
def set_author(self, name, url, icon_url=None):
|
||||||
self.embed["author"]["name"] = name
|
self.embed["author"]["name"] = name
|
||||||
self.embed["author"]["url"] = url
|
self.embed["author"]["url"] = url
|
||||||
self.embed["author"]["icon_url"] = icon_url
|
self.embed["author"]["icon_url"] = icon_url
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
__all__ = ["11311"]
|
__all__ = ["11311", "falsytypes"]
|
||||||
|
|
40
src/migrations/falsytypes.py
Normal file
40
src/migrations/falsytypes.py
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
from src.configloader import settings, load_settings
|
||||||
|
import logging
|
||||||
|
import shutil
|
||||||
|
import time
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
|
logger = logging.getLogger("rcgcdw.migrations.falsytypes")
|
||||||
|
new_settings = settings.copy()
|
||||||
|
|
||||||
|
def run():
|
||||||
|
change = False
|
||||||
|
try:
|
||||||
|
if "avatars" in new_settings:
|
||||||
|
avatars = new_settings["avatars"]
|
||||||
|
for key, value in avatars.items():
|
||||||
|
if not value and value is not None:
|
||||||
|
new_settings["avatars"][key] = None
|
||||||
|
change = True
|
||||||
|
if "event_appearance" in new_settings:
|
||||||
|
events = new_settings["event_appearance"]
|
||||||
|
for key, value in events.items():
|
||||||
|
if not value.get("icon", None) and value.get("icon", None) is not None:
|
||||||
|
new_settings["event_appearance"][key]["icon"] = None
|
||||||
|
change = True
|
||||||
|
except KeyError:
|
||||||
|
logger.exception("Failed to migrate falsy types.")
|
||||||
|
sys.exit(1)
|
||||||
|
if change:
|
||||||
|
logger.info("Running migration falsytypes")
|
||||||
|
shutil.copy("settings.json", "settings.json.{}.bak".format(int(time.time())))
|
||||||
|
with open("settings.json", "w", encoding="utf-8") as new_write:
|
||||||
|
new_write.write(json.dumps(new_settings, indent=4))
|
||||||
|
load_settings()
|
||||||
|
logger.info("Migration falsytypes has been successful.")
|
||||||
|
else:
|
||||||
|
logger.debug("Ignoring migration falsytypes")
|
||||||
|
|
||||||
|
|
||||||
|
run()
|
|
@ -80,7 +80,7 @@ class DataFile:
|
||||||
misc_logger.info("The data file could not be found. Generating a new one...")
|
misc_logger.info("The data file could not be found. Generating a new one...")
|
||||||
if not command_args.nowelcome:
|
if not command_args.nowelcome:
|
||||||
send_simple("welcome", _("RcGcDw is now running and checking {wiki}.").format(wiki=settings["wikiname"]),
|
send_simple("welcome", _("RcGcDw is now running and checking {wiki}.").format(wiki=settings["wikiname"]),
|
||||||
_("Welcome"), settings["avatars"].get("welcome", ""))
|
_("Welcome"), settings["avatars"].get("welcome", None))
|
||||||
return data_template
|
return data_template
|
||||||
|
|
||||||
def save_datafile(self):
|
def save_datafile(self):
|
||||||
|
|
|
@ -402,7 +402,7 @@ class Wiki(object):
|
||||||
else:
|
else:
|
||||||
if (time.time() - self.last_downtime) > 1800 and self.check_connection(): # check if last downtime happened within 30 minutes, if yes, don't send a message
|
if (time.time() - self.last_downtime) > 1800 and self.check_connection(): # check if last downtime happened within 30 minutes, if yes, don't send a message
|
||||||
send_simple("down_detector", _("{wiki} seems to be down or unreachable.").format(wiki=settings["wikiname"]),
|
send_simple("down_detector", _("{wiki} seems to be down or unreachable.").format(wiki=settings["wikiname"]),
|
||||||
_("Connection status"), settings["avatars"]["connection_failed"])
|
_("Connection status"), settings["avatars"].get("connection_failed", None))
|
||||||
self.last_downtime = time.time()
|
self.last_downtime = time.time()
|
||||||
self.streak = 0
|
self.streak = 0
|
||||||
else:
|
else:
|
||||||
|
@ -414,7 +414,7 @@ class Wiki(object):
|
||||||
self.streak = -1
|
self.streak = -1
|
||||||
send_simple("down_detector", _("Connection to {wiki} seems to be stable now.").format(
|
send_simple("down_detector", _("Connection to {wiki} seems to be stable now.").format(
|
||||||
wiki=settings["wikiname"]),
|
wiki=settings["wikiname"]),
|
||||||
_("Connection status"), settings["avatars"]["connection_restored"])
|
_("Connection status"), settings["avatars"].get("connection_restored", None))
|
||||||
|
|
||||||
def clear_cache(self):
|
def clear_cache(self):
|
||||||
self.map_ips = {}
|
self.map_ips = {}
|
||||||
|
|
Loading…
Reference in a new issue