Merge branch 'welcome' into 'testing'

Send welcome message

See merge request piotrex43/RcGcDw!114
This commit is contained in:
Frisk 2022-11-10 14:43:21 +00:00
commit 45bcb716b2
3 changed files with 14 additions and 8 deletions

View file

@ -13,6 +13,7 @@
"avatars": {
"connection_failed": "https://i.imgur.com/2jWQEt1.png",
"connection_restored": "",
"welcome": "",
"no_event": "",
"embed": "",
"compact": ""

View file

@ -17,6 +17,7 @@ import argparse
parser = argparse.ArgumentParser(description="Start RcGcDw")
parser.add_argument("--test", action='store_true', help="mode used for testing, sends only 5 entries of both rc and discussion changes and sends daily overview")
parser.add_argument("--nowelcome", action='store_true', help="don't send a welcome message when a new data file is created")
parser.add_argument("--settings", default="settings.json", type=argparse.FileType(encoding='utf8'), help="provides a path to settings file (default ./settings.json)")
command_args, unknown = parser.parse_known_args()

View file

@ -20,6 +20,7 @@ from html.parser import HTMLParser
from urllib.parse import urlparse, urlunparse
import requests
from src.argparser import command_args
from src.configloader import settings
import src.api.util
from src.discord.message import DiscordMessage, DiscordMessageMetadata
@ -45,6 +46,14 @@ WIKI_JUST_DOMAIN: str = ""
profile_fields = {"profile-location": _("Location"), "profile-aboutme": _("About me"), "profile-link-google": _("Google link"), "profile-link-facebook":_("Facebook link"), "profile-link-twitter": _("Twitter link"), "profile-link-reddit": _("Reddit link"), "profile-link-twitch": _("Twitch link"), "profile-link-psn": _("PSN link"), "profile-link-vk": _("VK link"), "profile-link-xbl": _("XBL link"), "profile-link-steam": _("Steam link"), "profile-link-discord": _("Discord handle"), "profile-link-battlenet": _("Battle.net handle")}
def send_simple(msgtype, message, name, avatar):
discord_msg = DiscordMessage("compact", msgtype, settings["webhookURL"], content=message)
discord_msg.set_avatar(avatar)
discord_msg.set_name(name)
messagequeue.resend_msgs()
send_to_discord(discord_msg, meta=DiscordMessageMetadata("POST"))
class DataFile:
"""Data class which instance of is shared by multiple modules to remain consistent and do not cause too many IO operations."""
def __init__(self):
@ -72,6 +81,9 @@ class DataFile:
except FileNotFoundError:
self.generate_datafile()
misc_logger.info("The data file could not be found. Generating a new one...")
if not command_args.nowelcome:
send_simple("welcome", _("RcGcDw is now running and checking {wiki}.").format(wiki=settings["wikiname"]),
_("Welcome"), settings["avatars"].get("welcome", ""))
return data_template
def save_datafile(self):
@ -303,14 +315,6 @@ def prepare_paths(path: str, dry=False):
prepare_paths(settings["wiki_url"])
def send_simple(msgtype, message, name, avatar):
discord_msg = DiscordMessage("compact", msgtype, settings["webhookURL"], content=message)
discord_msg.set_avatar(avatar)
discord_msg.set_name(name)
messagequeue.resend_msgs()
send_to_discord(discord_msg, meta=DiscordMessageMetadata("POST"))
def run_hooks(hooks, *arguments):
for hook in hooks:
try: