diff --git a/configuration.default.ini b/configuration.default.ini index e0c2ac7..8efa24c 100644 --- a/configuration.default.ini +++ b/configuration.default.ini @@ -241,7 +241,10 @@ paused = Music paused. stopped = Music stopped. cleared = Playlist emptied. database_dropped = Database dropped. All records have gone. -new_version_found =

Update Available!

New version of botamusique is available, send !update to update! +new_version_found =

Update Available!

Version {new_version} of botamusique is available!
+

Changelog

{changelog}
Send !update to update! +update_successful =

botamusique v{version} Installed!


+

Changelog

{changelog}
Visit our github repo for more details! start_updating = Start updating... file_missed = Music file '{file}' missed! This item has been removed from the playlist. unknown_mode = Unknown playback mode '{mode}'. It should be one of one-shot, repeat, random. diff --git a/mumbleBot.py b/mumbleBot.py index 61fcb26..280948f 100644 --- a/mumbleBot.py +++ b/mumbleBot.py @@ -67,12 +67,7 @@ class MumbleBot: # self.download_threads = [] self.wait_for_ready = False # flag for the loop are waiting for download to complete in the other thread self.on_killing = threading.Lock() # lock to acquire when killing ffmpeg thread is asked but ffmpeg is not - # killed yet - - if var.config.getboolean("bot", "auto_check_update"): - th = threading.Thread(target=self.check_update, name="UpdateThread") - th.daemon = True - th.start() + # killed yet if args.host: host = args.host @@ -131,7 +126,7 @@ class MumbleBot: self.ducking_release = time.time() self.last_volume_cycle_time = time.time() - if not var.db.has_option("bot", "ducking") and var.config.getboolean("bot", "ducking", fallback=False)\ + if not var.db.has_option("bot", "ducking") and var.config.getboolean("bot", "ducking", fallback=False) \ or var.config.getboolean("bot", "ducking"): self.is_ducking = True self.ducking_volume = var.config.getfloat("bot", "ducking_volume", fallback=0.05) @@ -156,6 +151,17 @@ class MumbleBot: self.redirect_ffmpeg_log = var.config.getboolean('debug', 'redirect_ffmpeg_log', fallback=True) + if var.config.getboolean("bot", "auto_check_update"): + th = threading.Thread(target=self.check_update, name="UpdateThread") + th.daemon = True + th.start() + + last_startup_version = var.db.get("bot", "version", fallback=None) + if not last_startup_version or version.parse(last_startup_version) < version.parse(self.version): + var.db.set("bot", "version", self.version) + changelog = util.fetch_changelog().replace("\n", "
") + self.send_channel_msg(constants.strings("update_successful", version=self.version, changelog=changelog)) + # Set the CTRL+C shortcut def ctrl_caught(self, signal, frame): self.log.info( @@ -178,8 +184,11 @@ class MumbleBot: self.log.debug("update: checking for updates...") new_version = util.new_release_version() if version.parse(new_version) > version.parse(self.version): + changelog = util.fetch_changelog() self.log.info("update: new version %s found, current installed version %s." % (new_version, self.version)) - self.send_channel_msg(constants.strings('new_version_found')) + self.log.info("update: changelog: " + changelog) + changelog = changelog.replace("\n", "
") + self.send_channel_msg(constants.strings('new_version_found', new_version=new_version, changelog=changelog)) else: self.log.debug("update: no new version found.") @@ -475,7 +484,7 @@ class MumbleBot: var.cache.free_and_delete(current.id) # move to the next song. - if not self.wait_for_ready: # if wait_for_ready flag is not true, move to the next song. + if not self.wait_for_ready: # if wait_for_ready flag is not true, move to the next song. if var.playlist.next(): current = var.playlist.current_item() try: @@ -545,10 +554,10 @@ class MumbleBot: self._max_rms = max(rms, self._max_rms) if self._display_rms: if rms < self.ducking_threshold: - print('%6d/%6d ' % (rms, self._max_rms) + '-'*int(rms/200), end='\r') + print('%6d/%6d ' % (rms, self._max_rms) + '-' * int(rms / 200), end='\r') else: - print('%6d/%6d ' % (rms, self._max_rms) + '-'*int(self.ducking_threshold/200) - + '+'*int((rms - self.ducking_threshold)/200), end='\r') + print('%6d/%6d ' % (rms, self._max_rms) + '-' * int(self.ducking_threshold / 200) + + '+' * int((rms - self.ducking_threshold) / 200), end='\r') if rms > self.ducking_threshold: if self.on_ducking is False: @@ -795,4 +804,3 @@ if __name__ == '__main__': # Start the main loop. var.bot.loop() - diff --git a/util.py b/util.py index 73fa741..1486e75 100644 --- a/util.py +++ b/util.py @@ -16,7 +16,7 @@ import youtube_dl from importlib import reload from sys import platform import traceback -import urllib.request +import requests from packaging import version log = logging.getLogger("bot") @@ -101,8 +101,15 @@ def get_user_ban(): def new_release_version(): - v = urllib.request.urlopen(urllib.request.Request("https://packages.azlux.fr/botamusique/version")).read() - return v.rstrip().decode() + r = requests.get("https://packages.azlux.fr/botamusique/version") + v = r.text + return v.rstrip() + + +def fetch_changelog(): + r = requests.get("https://packages.azlux.fr/botamusique/changelog") + c = r.text + return c def update(current_version):