2019-07-09 19:48:02 +00:00
|
|
|
#--depends-on config
|
|
|
|
|
2019-07-09 10:43:02 +00:00
|
|
|
from src import ModuleManager, utils
|
|
|
|
|
|
|
|
DELAY = 30 # 30 seconds
|
|
|
|
|
|
|
|
@utils.export("channelset", utils.BoolSetting("slowvoice",
|
|
|
|
"Enable/disable giving +v to new users after a delay"))
|
|
|
|
@utils.export("channelset", utils.IntSetting("slowvoice-delay",
|
|
|
|
"Set delay for slowvoice in seconds"))
|
|
|
|
class Module(ModuleManager.BaseModule):
|
|
|
|
@utils.hook("timer.slowvoice")
|
|
|
|
def timer(self, event):
|
|
|
|
event["channel"].send_mode("+v", [event["user"].nickname])
|
|
|
|
|
|
|
|
@utils.hook("new.channel")
|
|
|
|
def new_channel(self, event):
|
|
|
|
event["channel"]._slowvoice_timers = {}
|
|
|
|
|
|
|
|
@utils.hook("received.join")
|
|
|
|
def on_join(self, event):
|
|
|
|
if event["channel"].get_setting("slowvoice", False):
|
|
|
|
delay = event["channel"].get_setting("slowvoice-delay", DELAY)
|
|
|
|
timer = self.timers.add("slowvoice", delay,
|
|
|
|
channel=event["channel"], user=event["user"])
|
|
|
|
event["channel"]._slowvoice_timers[event["user"]] = timer
|
|
|
|
|
|
|
|
def _cancel_timer(self, user, channel):
|
|
|
|
if user in channel._slowvoice_timers:
|
|
|
|
timer = channel._slowvoice_timers.pop(user)
|
|
|
|
timer.cancel()
|
|
|
|
|
|
|
|
@utils.hook("received.part")
|
|
|
|
def on_part(self, event):
|
|
|
|
self._cancel_timer(event["user"], event["channel"])
|
|
|
|
|
|
|
|
@utils.hook("received.quit")
|
|
|
|
def on_quit(self, event):
|
2019-07-09 19:58:02 +00:00
|
|
|
for channel in event["user"].channels:
|
2019-07-09 10:43:02 +00:00
|
|
|
self._cancel_timer(event["user"], channel)
|
|
|
|
|
|
|
|
@utils.hook("self.part")
|
|
|
|
def self_part(self, event):
|
|
|
|
event["channel"]._slowvoice_timers.clear()
|