fix(nick): ne change de nom que toutes les 5 minutes

This commit is contained in:
François Poulain 2021-01-16 11:03:03 +01:00 committed by Cliss XXI - dev
parent 617234e41c
commit 4952036fc9

View File

@ -20,7 +20,6 @@ from itertools import groupby
import requests import requests
import irc.bot import irc.bot
import irc.strings
"""A simple IRC Bot statusing icinga2. """A simple IRC Bot statusing icinga2.
@ -192,19 +191,19 @@ class IcingaBot(Icinga2ServiceManager, irc.bot.SingleServerIRCBot):
self.nick = nickname self.nick = nickname
self.channel = channel self.channel = channel
self.connection.execute_every(30, self.refresh_ko_services) self.connection.execute_every(30, self.refresh_ko_services)
self.connection.execute_every(300, self.refresh_nick)
self.refresh_ko_services() self.refresh_ko_services()
def suffix_nick(self, suffix): def refresh_nick(self):
self.nick_suffix = suffix
if self.connection.is_connected(): if self.connection.is_connected():
self.connection.nick("{}{}".format(self.nick, suffix)) self.connection.nick("{}{}".format(self.nick, self.nick_suffix))
def unmute(self): def unmute(self):
self.muted = False self.muted = False
if self.ko_services: if self.ko_services:
self.suffix_nick("[{}]".format(len(self.ko_services))) self.nick_suffix = "[{}]".format(len(self.ko_services))
else: else:
self.suffix_nick("") self.nick_suffix = ""
def send(self, msg): def send(self, msg):
if not self.muted and self.connection.is_connected(): if not self.muted and self.connection.is_connected():
@ -216,9 +215,9 @@ class IcingaBot(Icinga2ServiceManager, irc.bot.SingleServerIRCBot):
if lost is False and news is False: if lost is False and news is False:
return return
if self.ko_services: if self.ko_services:
self.suffix_nick("[{}]".format(len(self.ko_services))) self.nick_suffix = "[{}]".format(len(self.ko_services))
else: else:
self.suffix_nick("") self.nick_suffix = ""
return return
def on_nicknameinuse(self, c, e): def on_nicknameinuse(self, c, e):
@ -336,7 +335,7 @@ class IcingaBot(Icinga2ServiceManager, irc.bot.SingleServerIRCBot):
def do_mute(self, c, e): def do_mute(self, c, e):
self.muted = True self.muted = True
self.suffix_nick("[zZz]") self.nick_suffix = "[zZz]"
self.connection.execute_delayed(3600, self.refresh_ko_services) self.connection.execute_delayed(3600, self.refresh_ko_services)
def do_command(self, e, cmd): def do_command(self, e, cmd):