Await do stuff in irc bot (#486)
This commit is contained in:
parent
5f55abc6bb
commit
d750105a77
|
@ -1,6 +1,7 @@
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
import asyncio
|
||||||
|
|
||||||
import irc3
|
import irc3
|
||||||
from asgiref.sync import sync_to_async
|
from asgiref.sync import sync_to_async
|
||||||
|
@ -44,9 +45,8 @@ class Plugin(object):
|
||||||
"Calling self.bot.do_stuff() in %s seconds.."
|
"Calling self.bot.do_stuff() in %s seconds.."
|
||||||
% settings.IRCBOT_CHECK_MESSAGE_INTERVAL_SECONDS
|
% settings.IRCBOT_CHECK_MESSAGE_INTERVAL_SECONDS
|
||||||
)
|
)
|
||||||
self.bot.loop.call_later(
|
await asyncio.sleep(settings.IRCBOT_CHECK_MESSAGE_INTERVAL_SECONDS)
|
||||||
settings.IRCBOT_CHECK_MESSAGE_INTERVAL_SECONDS, self.bot.do_stuff
|
await self.bot.do_stuff()
|
||||||
)
|
|
||||||
|
|
||||||
def connection_lost(self, **kwargs):
|
def connection_lost(self, **kwargs):
|
||||||
"""triggered when connection is lost"""
|
"""triggered when connection is lost"""
|
||||||
|
@ -123,9 +123,8 @@ class Plugin(object):
|
||||||
await sync_to_async(self.bot.get_outgoing_messages)()
|
await sync_to_async(self.bot.get_outgoing_messages)()
|
||||||
|
|
||||||
# schedule a call of this function again in N seconds
|
# schedule a call of this function again in N seconds
|
||||||
self.bot.loop.call_later(
|
await asyncio.sleep(settings.IRCBOT_CHECK_MESSAGE_INTERVAL_SECONDS)
|
||||||
settings.IRCBOT_CHECK_MESSAGE_INTERVAL_SECONDS, self.bot.do_stuff
|
await self.bot.do_stuff()
|
||||||
)
|
|
||||||
|
|
||||||
@irc3.extend
|
@irc3.extend
|
||||||
def get_outgoing_messages(self):
|
def get_outgoing_messages(self):
|
||||||
|
|
Loading…
Reference in a new issue