Exemplo n.º 1
0
 def testSimple(self):
     cd = cooldown.Cooldown(datetime.timedelta(minutes=1))
     self.assertTrue(cd.peek())
     self.assertTrue(cd.fire())
     self.assertFalse(cd.peek())
     self.time.tick(59)
     self.assertFalse(cd.peek())
     self.assertFalse(cd.fire())
     self.assertFalse(cd.peek())
     self.time.tick(1)
     self.assertTrue(cd.peek())
     self.assertTrue(cd.fire())
     self.assertFalse(cd.peek())
Exemplo n.º 2
0
 def __init__(self, oauth: TwitchOAuth):
     self.oauth = oauth
     self.streamer_username = oauth.streamer_username
     self._cached_sub_count: Optional[int] = None
     self._sub_count_ttl = cooldown.Cooldown(datetime.timedelta(minutes=5))
     self._channel_id_cache: Dict[str, int] = {}
Exemplo n.º 3
0
 def __init__(self) -> None:
     super().__init__()
     self.error_cooldown = cooldown.Cooldown(timedelta(seconds=30))
Exemplo n.º 4
0
from pprint import pprint
from typing import Optional, Set, Tuple, Union
from urllib import parse

import flask
import requests

import secret
from impbot.connections import twitch_event, twitch_eventsub
from impbot.core import base, web
from impbot.core import data
from impbot.handlers import command
from impbot.util import cooldown, twitch_util

logger = logging.getLogger(__name__)
cache_cd = cooldown.Cooldown(duration=timedelta(minutes=5))

# Keys associated with scenes don't contain underscores, so using this key guarantees there isn't a
# conflict.
CONFIG_KEY = '_config'


class HueClient:
    def __init__(self):
        self.data = data.Namespace('impbot.handlers.hue.HueClient')

    def startup(self) -> None:
        if not all(
                self.data.exists(CONFIG_KEY, subkey)
                for subkey in ('access_token', 'refresh_token', 'username')):
            logger.critical(