Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def wait_for_tables(cls, timeout=30):
watch = tempora.timing.Stopwatch()
while watch.split() < datetime.timedelta(seconds=timeout):
try:
cls.check_logs('#check')
return
except Exception:
# short-circuit if the bot has stopped
if cls.bot.poll() is not None:
return
time.sleep(0.2)
def __eq__(self, other):
return isinstance(other, DelayedCommand)
def handler(self):
return AtHandler(
name='some name',
channel='#some-channel',
when=now(),
func=lambda x: x,
doc='some doc',
)
def _expired(self, last, now):
return now - last > self.warn_every
def warn(self, nick, connection):
if pmxbot.config.get('privacy warning') == 'suppress':
return
if not self.needs_warning(nick):
return
logged_channels_string = ', '.join(pmxbot.config.log_channels)
msg = self.warn_message.format(**locals())
for line in msg.splitlines():
connection.notice(nick, line)
class Scheduler(tempora.schedule.CallbackScheduler, irc.schedule.DefaultScheduler):
pass
class LoggingCommandBot(core.Bot, irc.bot.SingleServerIRCBot):
def __init__(self, server, port, nickname, channels, password=None):
ErrorReportingBuffer.install()
server_list = [(server, port, password)]
super().__init__(server_list, nickname, nickname)
self.reactor.scheduler = Scheduler(dispatch=self.handle_scheduled)
self.nickname = nickname
self._channels = channels
self._nickname = nickname
self.warn_history = WarnHistory()
def connect(self, *args, **kwargs):
factory = irc.connection.Factory(wrapper=self._get_wrapper())
def execute_every(self, period, func):
self.add(schedule.PeriodicCommand.after(period, func))
def execute_after(self, delay, func):
self.add(schedule.DelayedCommand.after(delay, func))
def as_cmd(self):
cls = schedule.PeriodicCommand if self.repeat else schedule.DelayedCommand
return cls.after(self.duration, self)
def as_cmd(self):
factory = (
schedule.PeriodicCommandFixedDelay.daily_at
if isinstance(self.when, datetime.time)
else schedule.DelayedCommand.at_time
)
return factory(self.when, self)
def __init__(self, server, port, nickname, channels, password=None):
token = pmxbot.config['slack token']
sc = importlib.import_module('slackclient')
self.slack = sc.SlackClient(token)
sr = importlib.import_module('slacker')
self.slacker = sr.Slacker(token)
self.scheduler = schedule.CallbackScheduler(self.handle_scheduled)
"execute func every period"
@abc.abstractmethod
def execute_at(self, when, func):
"execute func at when"
@abc.abstractmethod
def execute_after(self, delay, func):
"execute func after delay"
@abc.abstractmethod
def run_pending(self):
"invoke the functions that are due"
class DefaultScheduler(schedule.InvokeScheduler, IScheduler):
def execute_every(self, period, func):
self.add(schedule.PeriodicCommand.after(period, func))
def execute_at(self, when, func):
self.add(schedule.DelayedCommand.at_time(when, func))
def execute_after(self, delay, func):
self.add(schedule.DelayedCommand.after(delay, func))