1
0
mirror of https://github.com/azlux/botamusique synced 2024-11-23 13:56:17 +00:00

Compare commits

..

2 Commits

Author SHA1 Message Date
Terry Geng
6faadd6669
feat: Add config option redirect_stderr.
Proposed in #282.
2021-05-26 11:29:22 +08:00
Terry Geng
efab8928f5
fix: Failure caused by welcome message sent by the server.
Fixes #281.
2021-05-26 09:25:04 +08:00
2 changed files with 11 additions and 2 deletions

View File

@ -84,7 +84,10 @@ port = 64738
#pip3_path = venv/bin/pip
# 'logfile': write logs into this file.
# 'redirect_strerr': capture outputs from stderr and write into the `logfile`,
# useful for capture the exception message when the bot crash.
#logfile =
#redirect_strerr = False
#announce_current_music = True
#allow_other_channel_message = False

View File

@ -246,6 +246,11 @@ class MumbleBot:
def message_received(self, text):
raw_message = text.message.strip()
message = re.sub(r'<.*?>', '', raw_message)
if text.actor == 0:
# Some server will send a welcome message to the bot once connected.
# It doesn't have a valid "actor". Simply ignore it here.
return
user = self.mumble.users[text.actor]['name']
if var.config.getboolean('commands', 'split_username_at_space'):
@ -797,8 +802,9 @@ if __name__ == '__main__':
if logfile:
print(f"Redirecting stdout and stderr to log file: {logfile}")
handler = logging.handlers.RotatingFileHandler(logfile, mode='a', maxBytes=10240) # Rotate after 10KB
sys.stdout = util.LoggerIOWrapper(bot_logger, logging.INFO, fallback_io_buffer=sys.stdout.buffer)
sys.stderr = util.LoggerIOWrapper(bot_logger, logging.INFO, fallback_io_buffer=sys.stderr.buffer)
if var.config.getboolean("bot", "redirect_stderr", fallback=False):
sys.stderr = util.LoggerIOWrapper(bot_logger, logging.INFO,
fallback_io_buffer=sys.stderr.buffer)
else:
handler = logging.StreamHandler()