From ce43535741e189a1bfc37d2f5b51b17d0b621945 Mon Sep 17 00:00:00 2001 From: Frisk Date: Sat, 23 Jun 2018 16:14:37 +0200 Subject: [PATCH 1/2] Fixed critial error on startup --- rcgcdw.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/rcgcdw.py b/rcgcdw.py index b16d492..ffb0987 100644 --- a/rcgcdw.py +++ b/rcgcdw.py @@ -32,7 +32,7 @@ with open("settings.json") as sfile: logging.basicConfig(level=settings["verbose_level"]) if settings["limitrefetch"] != -1 and os.path.exists("lastchange.txt") == False: with open("lastchange.txt", 'w') as sfile: - sfile.write("") + sfile.write("99999999999") logging.info("Current settings: {settings}".format(settings=settings)) if settings["lang"] != "en" or settings["lang"] == "": lang = gettext.translation('rcgcdw', localedir='locale', languages=[settings["lang"]]) @@ -531,8 +531,13 @@ class recent_changes_class(object): clock = 0 if settings["limitrefetch"] != -1: with open("lastchange.txt", "r") as record: - file_id = int(record.read().strip()) - logging.debug("File_id is {val}".format(val=file_id)) + file_content = record.read().strip() + if file_content: + file_id = int(file_content) + logging.debug("File_id is {val}".format(val=file_id)) + else: + logging.debug("File is empty") + file_id = 999999999 else: file_id = 999999999 #such value won't cause trouble, and it will make sure no refetch happens def add_cache(self, change): From b8a372b2435259a600cfa71f311c987826821bbd Mon Sep 17 00:00:00 2001 From: Frisk Date: Sat, 23 Jun 2018 16:27:57 +0200 Subject: [PATCH 2/2] Provided max value for limit and limitrefetch values in the config, made the cooldown between recent messages higher due to Discord rate-limiting --- README.md | 30 +++++++++++++++--------------- rcgcdw.py | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index e7d433f..0229a06 100644 --- a/README.md +++ b/README.md @@ -16,24 +16,24 @@ Recent changes Gamepedia compatible Discord webhook is a project made from earli ### settings.json ### Explanation for settings: -`cooldown` – interval for how often changes are retrieved from the wiki (due to used solutions, the real interval is ~1 sec longer) -`wiki` – wiki prefix the bot is supposed to work with (for example, for English Minecraft Wiki it's minecraft (https://**minecraft**.gamepedia.com) and for Polish Minecraft Wiki minecraft-pl (https://**minecraft-pl**.gamepedia.com -`lang` – language for the messages, currently available options are: de, en, fr, pl +`cooldown` – interval for how often changes are retrieved from the wiki (due to used solutions, the real interval is ~1 sec longer). +`wiki` – wiki prefix the bot is supposed to work with (for example, for English Minecraft Wiki it's minecraft (https://**minecraft**.gamepedia.com) and for Polish Minecraft Wiki minecraft-pl (https://**minecraft-pl**.gamepedia.com) +`lang` – language for the messages, currently available options are: de, en, fr, pl. `header` – it's recommended to leave this value as it is, it's a header the script will use to communicate with Gamepedia. Please note that without it, no communication will be possible. -`limit` – amount of actions retrieved every `cooldown` amount of seconds. The higher it is the more network data will be used and the data will be processed longer, setting it to higher values is not recommended unless cooldown value is higher. -`webhookURL` – webhook URL you can get using [channel settings in Discord](https://support.discordapp.com/hc/en-us/articles/228383668-Intro-to-Webhooks) -`limitrefetch` – limit of how many changes can be retrieved when refetch happens, cannot be lower than limit. -1 if you want to disable auto-refetch -`wikiname` – a name of the wiki the bot will work on, required in some messages -`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 -* `no_event` – error message when the event couldn't be recognized by the script -* `embed` – every embed message showing changes +`limit` – amount of actions retrieved every `cooldown` amount of seconds. The higher it is the more network data will be used and the data will be processed longer, setting it to higher values is not recommended unless cooldown value is higher it also cannot be higher than 500. +`webhookURL` – webhook URL you can get using [channel settings in Discord](https://support.discordapp.com/hc/en-us/articles/228383668-Intro-to-Webhooks). +`limitrefetch` – limit of how many changes can be retrieved when refetch happens, cannot be lower than limit. -1 if you want to disable auto-refetch. Value cannot be higher than 500. +`wikiname` – a name of the wiki the bot will work on, required in some messages. +`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. +* `no_event` – error message when the event couldn't be recognized by the script. +* `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) -`show_updown_messages` – bool value, depending on this settings the messages whenever the wiki goes up and down will be sent to the channel +`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. `appearience` – section with different types of actions and logs, and corresponding to them colors/icons. In here you can set custom icon or color! -`overview` – bool value, sends a day overview to the channel if true -`overview_time` – **local machine time** at which the day overview will be sent +`overview` – bool value, sends a day overview to the channel if true. +`overview_time` – **local machine time** at which the day overview will be sent. ### How to use ### Make sure you have installed all of dependencies and **filled settings.json properly**. You can also use `pip install -r requirements.txt` to install dependencies automatically. If you are using Raspberry Pi you won't have newest Python version installed, you can use [this guide](https://gist.github.com/dschep/24aa61672a2092246eaca2824400d37f). diff --git a/rcgcdw.py b/rcgcdw.py index ffb0987..49a147c 100644 --- a/rcgcdw.py +++ b/rcgcdw.py @@ -580,7 +580,7 @@ class recent_changes_class(object): logging.debug("Rejected {val}".format(val=change["rcid"])) continue first_pass(change) - time.sleep(1.0) + time.sleep(3.0) #sadly, the time here needs to be quite high, otherwise we are being rate-limited by the Discord, especially during re-fetch return change["rcid"] def safe_request(self, url): try: