This commit is contained in:
Frisk 2020-10-18 11:39:16 +02:00
parent e1eb34565f
commit 81792315ab
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC
4 changed files with 16 additions and 22 deletions

View file

@ -31,6 +31,7 @@
"show_added_categories": true, "show_added_categories": true,
"show_bots": false, "show_bots": false,
"show_abuselog": false, "show_abuselog": false,
"discord_message_cooldown": 0,
"logging": { "logging": {
"version": 1, "version": 1,
"disable_existing_loggers": false, "disable_existing_loggers": false,

View file

@ -38,6 +38,7 @@ WIKI_API_PATH: str = ""
WIKI_ARTICLE_PATH: str = "" WIKI_ARTICLE_PATH: str = ""
WIKI_SCRIPT_PATH: str = "" WIKI_SCRIPT_PATH: str = ""
WIKI_JUST_DOMAIN: str = "" WIKI_JUST_DOMAIN: str = ""
rate_limit = 0
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")} 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")}
@ -124,7 +125,6 @@ class MessageQueue:
str(item))) str(item)))
if send_to_discord_webhook(item) < 2: if send_to_discord_webhook(item) < 2:
misc_logger.debug("Sending message succeeded") misc_logger.debug("Sending message succeeded")
time.sleep(2.5)
else: else:
misc_logger.debug("Sending message failed") misc_logger.debug("Sending message failed")
break break
@ -324,12 +324,24 @@ def send_simple(msgtype, message, name, avatar):
send_to_discord(discord_msg) send_to_discord(discord_msg)
def update_ratelimit(request):
"""Updates rate limit time"""
global rate_limit
rate_limit = 0 if int(request.headers.get('x-ratelimit-remaining', "-1")) > 0 else int(request.headers.get(
'x-ratelimit-reset-after', 0))
rate_limit += settings.get("discord_message_cooldown", 0)
def send_to_discord_webhook(data): def send_to_discord_webhook(data):
global rate_limit
header = settings["header"] header = settings["header"]
header['Content-Type'] = 'application/json' header['Content-Type'] = 'application/json'
try: try:
time.sleep(rate_limit)
rate_limit = 0
result = requests.post(data.webhook_url, data=repr(data), result = requests.post(data.webhook_url, data=repr(data),
headers=header, timeout=10) headers=header, timeout=10)
update_ratelimit(result)
except requests.exceptions.Timeout: except requests.exceptions.Timeout:
misc_logger.warning("Timeouted while sending data to the webhook.") misc_logger.warning("Timeouted while sending data to the webhook.")
return 3 return 3
@ -362,7 +374,6 @@ def send_to_discord(data):
time.sleep(5.0) time.sleep(5.0)
messagequeue.add_message(data) messagequeue.add_message(data)
elif code < 2: elif code < 2:
time.sleep(2.0)
pass pass
class DiscordMessage(): class DiscordMessage():

View file

@ -104,16 +104,6 @@ class Recent_Changes_Class(object):
storage["abuse_log_id"] = last_check[1] if last_check[1] else storage["abuse_log_id"] storage["abuse_log_id"] = last_check[1] if last_check[1] else storage["abuse_log_id"]
storage.save_datafile() storage.save_datafile()
self.initial_run_complete = True self.initial_run_complete = True
# If the request succeeds the last_check will be the last rcid from recentchanges query
# if last_check is not None:
# self.recent_id = last_check
# # Assigns self.recent_id the last rcid if request succeeded, otherwise set the id from the file
# if settings["limitrefetch"] != -1 and self.recent_id != self.file_id and self.recent_id != 0: # if saving to database is disabled, don't save the recent_id
# self.file_id = self.recent_id
# storage["rcid"] = self.recent_id
# datafile.save_datafile()
# logger.debug("Most recent rcid is: {}".format(self.recent_id))
# return self.recent_id
def fetch_recentchanges_request(self, amount): def fetch_recentchanges_request(self, amount):
"""Make a typical MW request for rc/abuselog """Make a typical MW request for rc/abuselog
@ -221,12 +211,6 @@ class Recent_Changes_Class(object):
abuselog_processing(entry, self) abuselog_processing(entry, self)
return entry["id"] return entry["id"]
# def filter_logic(self, clean_status, change_id, file_id):
# """Function that filers which changes should be sent and which not. Returns True if to send, False otherwise"""
# if clean_status and not change_id > file_id:
# return False
# return True
def fetch_changes(self, amount): def fetch_changes(self, amount):
"""Fetches the :amount: of changes from the wiki. """Fetches the :amount: of changes from the wiki.
Returns None on error and int of rcid of latest change if succeeded""" Returns None on error and int of rcid of latest change if succeeded"""

View file

@ -46,7 +46,7 @@ logging.config.dictConfig(settings["logging"])
logger = logging.getLogger("rcgcdw") logger = logging.getLogger("rcgcdw")
logger.debug("Current settings: {settings}".format(settings=settings)) logger.debug("Current settings: {settings}".format(settings=settings))
storage = datafile.data storage = datafile
# Remove previous data holding file if exists and limitfetch allows # Remove previous data holding file if exists and limitfetch allows
@ -247,9 +247,7 @@ if 1 == 2: # additional translation strings in unreachable code
if TESTING: if TESTING:
logger.debug("DEBUGGING ") logger.debug("DEBUGGING ")
recent_changes.recent_id -= 5 storage["rcid"] = 1
recent_changes.file_id -= 5
recent_changes.ids = [1]
recent_changes.fetch(amount=5) recent_changes.fetch(amount=5)
day_overview() day_overview()
import src.discussions import src.discussions