Exemple #1
0
    def __init__(self, bot):
        super().__init__(bot)
        self.bets = {}

        redis = RedisManager.get()

        self.last_game_start = None
        self.last_game_id = None
        try:
            last_game_start_timestamp = int(
                redis.get("{streamer}:last_hsbet_game_start".format(streamer=StreamHelper.get_streamer()))
            )
            self.last_game_start = datetime.datetime.fromtimestamp(last_game_start_timestamp, tz=datetime.timezone.utc)
        except (TypeError, ValueError):
            # Issue with the int-cast
            pass
        except (OverflowError, OSError):
            # Issue with datetime.fromtimestamp
            pass

        try:
            self.last_game_id = int(
                redis.get("{streamer}:last_hsbet_game_id".format(streamer=StreamHelper.get_streamer()))
            )
        except (TypeError, ValueError):
            pass

        self.job = ScheduleManager.execute_every(15, self.poll_trackobot)
        self.job.pause()
        self.reminder_job = ScheduleManager.execute_every(1, self.reminder_bet)
        self.reminder_job.pause()
Exemple #2
0
    def enable(self, bot):
        # Web interface, nothing to do
        if not bot:
            return

        # every 10 minutes, add the subscribers update to the action queue
        ScheduleManager.execute_every(10 * 60, lambda: self.bot.action_queue.submit(self._update_subscribers))
Exemple #3
0
    def __init__(self, bot):
        super().__init__(bot)
        self.action_queue = ActionQueue()
        self.action_queue.start()
        self.bets = {}
        self.betting_open = False
        self.message_closed = True
        self.isRadiant = False
        self.matchID = 0
        self.oldID = 0
        self.winPoints = 0
        self.lossPoints = 0
        self.winBetters = 0
        self.lossBetters = 0
        self.gettingTeam = False
        self.secondAttempt = False
        self.calibrating = True
        self.calibratingSecond = True
        self.jobPaused = False
        self.spectating = False

        self.job = ScheduleManager.execute_every(25, self.poll_webapi)
        self.job.pause()

        self.reminder_job = ScheduleManager.execute_every(
            200, self.reminder_bet)
        self.reminder_job.pause()
Exemple #4
0
    def __init__(self):
        super().__init__()
        self.bets = {}

        redis = RedisManager.get()

        self.last_game_start = None
        self.last_game_id = None
        try:
            last_game_start_timestamp = int(redis.get('{streamer}:last_hsbet_game_start'.format(streamer=StreamHelper.get_streamer())))
            self.last_game_start = datetime.fromtimestamp(last_game_start_timestamp)
        except (TypeError, ValueError):
            # Issue with the int-cast
            pass
        except (OverflowError, OSError):
            # Issue with datetime.fromtimestamp
            pass

        try:
            self.last_game_id = int(redis.get('{streamer}:last_hsbet_game_id'.format(streamer=StreamHelper.get_streamer())))
        except (TypeError, ValueError):
            pass

        self.job = ScheduleManager.execute_every(15, self.poll_trackobot)
        self.job.pause()
        self.reminder_job = ScheduleManager.execute_every(1, self.reminder_bet)
        self.reminder_job.pause()
Exemple #5
0
 def __init__(self, bot, token):
     self.bot = bot
     self.token = token
     self.sent_ping = False
     self.websocket = None
     self.ping_schedule = ScheduleManager.execute_every(
         60, self.ping_server)
     self.check_connection_schedule = ScheduleManager.execute_every(
         30, self.check_connection)
     ScheduleManager.execute_now(self.check_connection)
Exemple #6
0
    def command_start(self, bot, source, message, **rest):
        if self.trivia_running:
            bot.safe_me(f"{source}, a trivia is already running")
            return

        self.trivia_running = True
        self.job = ScheduleManager.execute_every(1, self.poll_trivia)

        try:
            self.point_bounty = int(message)
            if self.point_bounty < 0:
                self.point_bounty = 0
            elif self.point_bounty > 50:
                self.point_bounty = 50
        except:
            self.point_bounty = self.settings["default_point_bounty"]

        if self.point_bounty > 0:
            bot.safe_me(
                f"The trivia has started! {self.point_bounty} points for each right answer!"
            )
        else:
            bot.safe_me("The trivia has started!")

        HandlerManager.add_handler("on_message", self.on_message)
Exemple #7
0
    def enable(self, bot):
        if not bot:
            return

        # We can't use bot.execute_every directly since we can't later cancel jobs created through bot.execute_every
        self.gc_job = ScheduleManager.execute_every(
            30, lambda: self.bot.execute_now(self._cancel_expired_duels))
Exemple #8
0
    def command_start(self, bot, source, message, **rest):
        if self.trivia_running:
            bot.me(f"{source}, a trivia is already running")
            return

        if bot.is_online:
            bot.whisper(source,
                        "You can't start a trivia when the stream is live.")
            return

        self.trivia_running = True
        self.job = ScheduleManager.execute_every(1, self.poll_trivia)

        try:
            self.point_bounty = int(message)
            if self.point_bounty < 0:
                self.point_bounty = 0
            if source.level < 500:
                self.point_bounty = 20
        except:
            self.point_bounty = self.settings["default_point_bounty"]

        if self.point_bounty > 0:
            self.bot.safe_me(
                f"The trivia has started! {self.point_bounty} points for each right answer!"
            )
        else:
            self.bot.safe_me("The trivia has started!")

        HandlerManager.add_handler("on_message", self.on_message)
Exemple #9
0
    def __init__(self, twitch_helix_api, action_queue) -> None:
        self.action_queue = action_queue
        self.streamer = StreamHelper.get_streamer()
        self.streamer_id = StreamHelper.get_streamer_id()
        self.twitch_emote_manager = TwitchEmoteManager(twitch_helix_api)
        self.ffz_emote_manager = FFZEmoteManager()
        self.bttv_emote_manager = BTTVEmoteManager()
        self.seventv_emote_manager = SevenTVEmoteManager()

        # every 1 hour
        # note: whenever emotes are refreshed (cache is saved to redis), the key is additionally set to expire
        # in one hour. This is to prevent emotes from never refreshing if the bot restarts in less than an hour.
        # (This also means that the bot will never have emotes older than 2 hours)
        ScheduleManager.execute_every(1 * 60 * 60, self.update_all_emotes)

        self.load_all_emotes()
Exemple #10
0
    def enable(self, bot):
        if not bot:
            return

        HandlerManager.add_handler("on_open_bets", self.start_game)
        HandlerManager.add_handler("on_lock_bets", self.automated_lock)
        HandlerManager.add_handler("on_end_bets", self.automated_end)

        self.reminder_job = ScheduleManager.execute_every(200, self.reminder_bet)
Exemple #11
0
    def enable(self, bot):
        # Web interface, nothing to do
        if not bot:
            return

        # every 10 minutes, add the chatters update to the action queue
        self.scheduled_job = ScheduleManager.execute_every(
            self.UPDATE_INTERVAL * 60,
            lambda: self.bot.action_queue.submit(self._update_chatters))
Exemple #12
0
    def __init__(self, twitch_v5_api, twitch_legacy_api, action_queue):
        self.action_queue = action_queue
        self.twitch_emote_manager = TwitchEmoteManager(twitch_v5_api, twitch_legacy_api)
        self.ffz_emote_manager = FFZEmoteManager()
        self.bttv_emote_manager = BTTVEmoteManager()

        self.epm = {}

        try:
            # every 1 hour
            # note: whenever emotes are refreshed (cache is saved to redis), the key is additionally set to expire
            # in one hour. This is to prevent emotes from never refreshing if the bot restarts in less than an hour.
            # (This also means that the bot will never have emotes older than 2 hours)
            ScheduleManager.execute_every(1 * 60 * 60, self.update_all_emotes)
        except:
            log.exception("Something went wrong trying to initialize automatic emote refresh")

        self.load_all_emotes()
Exemple #13
0
    def __init__(self):
        super().__init__()

        self.job = ScheduleManager.execute_every(1, self.poll_trivia)
        self.job.pause()
        self.checkjob = ScheduleManager.execute_every(10, self.check_run)
        self.checkjob.pause()
        self.checkPaused = True

        self.jservice = False
        self.trivia_running = False
        self.manualStart = False
        self.last_question = None
        self.question = None
        self.step = 0
        self.last_step = None
        self.correct_dict = {}

        self.point_bounty = 0
Exemple #14
0
    def enable(self, bot):
        # Web interface, nothing to do
        if not bot:
            return

        HandlerManager.add_handler("on_pubnotice", self._on_pubnotice)

        # every 10 minutes, send the /vips command (response is received via _on_pubnotice)
        self.scheduled_job = ScheduleManager.execute_every(
            self.UPDATE_INTERVAL * 60,
            lambda: self.bot.execute_now(self._update_vips))
Exemple #15
0
 def on_open(self, ws):
     log.info("Pubsub Started!")
     self.sendData({
         "type": "LISTEN",
         "data": {
             "topics":
             ["channel-bits-events-v2." + self.bot.streamer_user_id],
             "auth_token": self.token.token.access_token,
         },
     })
     self.schedule = ScheduleManager.execute_every(120,
                                                   self.check_connection)
Exemple #16
0
    def __init__(self, bot):
        super().__init__(bot)

        self.job = ScheduleManager.execute_every(1, self.poll_trivia)
        self.job.pause()
        self.checkjob = ScheduleManager.execute_every(10, self.check_run)
        self.checkjob.pause()
        self.checkPaused = True

        self.jservice = False
        self.trivia_running = False
        self.manualStart = False
        self.last_question = None
        self.question = None
        self.step = 0
        self.last_step = None
        self.streptocuckus = 0
        self.correct_dict = {}

        self.gazCategories = [
            "W_OMEGALUL_W", "Vietnam", "Video_Games", "Video Games", "Twitch",
            "Sports", "Spongebob", "Science", "Programming", "Music", "Memes",
            "Math", "Maths", "Movies", "Languages", "History", "Geography",
            "Gachimuchi", "Gachi", "Emotes", "Bees", "Country", "Books",
            "AdmiralBulldog", "D DansGame TA", "Country", "HTTP"
        ]

        self.bad_phrases = [
            "href=",  # bad phrases for questions
            "Which of these",
            "Which one of these",
            "Which of the following",
            "here is no such thing"
        ]
        self.recent_questions = list()  # List of most recent questions
        self.q_memory = 200  # No. of recent questions to remember
        # Stored winstreak [user name, winstreak]
        self.winstreak = [None, None]
        self.min_streak = 3  # minimum correct answers for a streak
        self.point_bounty = 0
Exemple #17
0
    def __init__(self, bot):
        # this should probably not even be a dictionary
        self.bot = bot
        self.streamer = bot.streamer
        self.bttv_emote_manager = BTTVEmoteManager()
        redis = RedisManager.get()
        self.subemotes = redis.hgetall('global:emotes:twitch_subemotes')

        # Emote current EPM
        self.epm = {}

        try:
            # Update BTTV Emotes every 2 hours
            ScheduleManager.execute_every(60 * 60 * 2, self.bttv_emote_manager.update_emotes)

            # Update Twitch emotes every 3 hours
            ScheduleManager.execute_every(60 * 60 * 3, self.update_emotes)
        except:
            pass

        # Used as caching to store emotes
        self.global_emotes = []
Exemple #18
0
    def __init__(self, bot):
        super().__init__(bot)

        self.job = ScheduleManager.execute_every(1, self.poll_trivia)
        self.job.pause()

        self.trivia_running = False
        self.last_question = None
        self.question = None
        self.step = 0
        self.last_step = None

        self.point_bounty = 0
Exemple #19
0
    def __init__(self):
        super().__init__()

        self.job = ScheduleManager.execute_every(1, self.poll_trivia)
        self.job.pause()

        self.trivia_running = False
        self.last_question = None
        self.question = None
        self.step = 0
        self.last_step = None

        self.point_bounty = 0
Exemple #20
0
    def __init__(self):
        super().__init__()

        self.job = ScheduleManager.execute_every(1, self.poll_trivia)
        self.job.pause()
        self.checkjob = ScheduleManager.execute_every(10, self.check_run)
        self.checkjob.pause()
        self.checkPaused = True

        self.jservice = False
        self.trivia_running = False
        self.manualStart = False
        self.last_question = None
        self.question = None
        self.step = 0
        self.last_step = None
        self.correct_dict = {}

        self.gazCategories = [
            'W_OMEGALUL_W', 'Vietnam', 'Video_Games', 'Video Games', 'Twitch',
            'Sports', 'Spongebob', 'Science', 'Programming', 'Music', 'Memes',
            'Math', 'Maths', 'Movies', 'Languages', 'History', 'Geography',
            'Gachimuchi', 'Gachi', 'Emotes', 'Bees', 'Country', 'Books',
            'AdmiralBulldog', 'D DansGame TA', 'Country', 'HTTP'
        ]

        self.bad_phrases = [
            'href=',  # bad phrases for questions
            'Which of these',
            'Which one of these',
            'Which of the following'
        ]
        self.recent_questions = list()  # List of most recent questions
        self.q_memory = 200  # No. of recent questions to remember
        # Stored winstreak [user name, winstreak]
        self.winstreak = [None, None]
        self.min_streak = 3  # minimum correct answers for a streak
        self.point_bounty = 0
Exemple #21
0
    def enable(self, bot):
        if not bot:
            return

        HandlerManager.add_handler("on_stream_start", self.on_stream_start)
        HandlerManager.add_handler("on_stream_stop", self.on_stream_stop)

        if self.settings["new_song_auto_enable"]:
            self.scheduled_job = ScheduleManager.execute_every(15, self.on_scheduled_new_song_check)

            if bot.is_online:
                self.on_stream_start()
            else:
                self.on_stream_stop()
Exemple #22
0
    def __init__(self, bot):
        # this should probably not even be a dictionary
        self.bot = bot
        self.streamer = bot.streamer
        self.bttv_emote_manager = BTTVEmoteManager()
        redis = RedisManager.get()
        self.subemotes = redis.hgetall('global:emotes:twitch_subemotes')

        # Emote current EPM
        self.epm = {}

        try:
            # Update BTTV Emotes every 2 hours
            ScheduleManager.execute_every(
                60 * 60 * 2, self.bttv_emote_manager.update_emotes)

            # Update Twitch emotes every 3 hours
            ScheduleManager.execute_every(60 * 60 * 3, self.update_emotes)
        except:
            pass

        # Used as caching to store emotes
        self.global_emotes = []
Exemple #23
0
    def _make_new_connection(self):
        self.conn = Connection(self.bot.reactor)
        with self.bot.reactor.mutex:
            self.bot.reactor.connections.append(self.conn)
        self.conn.connect(
            "irc.chat.twitch.tv",
            6697,
            self.bot.nickname,
            self.bot.password,
            self.bot.nickname,
            connect_factory=Factory(wrapper=ssl.wrap_socket),
        )
        self.conn.cap("REQ", "twitch.tv/commands", "twitch.tv/tags")

        self.ping_task = ScheduleManager.execute_every(30, lambda: self.bot.execute_now(self._send_ping))
Exemple #24
0
    def start_trivia(self, message=None):
        if self.checkPaused and not self.manualStart:
            return

        self.trivia_running = True
        self.job = ScheduleManager.execute_every(1, self.poll_trivia)

        try:
            self.point_bounty = int(message)
            if self.point_bounty < 0:
                self.point_bounty = 0
        except:
            self.point_bounty = self.settings["default_point_bounty"]

        if self.point_bounty > 0:
            self.bot.safe_me(f"The trivia has started! {self.point_bounty} points for each right answer!")
        else:
            self.bot.safe_me("The trivia has started!")

        HandlerManager.add_handler("on_message", self.on_message)
Exemple #25
0
    def __init__(self, twitch_client_id):
        self.twitch_emote_manager = TwitchEmoteManager(twitch_client_id)
        self.ffz_emote_manager = FFZEmoteManager()
        self.bttv_emote_manager = BTTVEmoteManager()

        self.epm = {}

        try:
            # every 1 hour
            # note: whenever emotes are refreshed (cache is saved to redis), the key is additionally set to expire
            # in one hour. This is to prevent emotes from never refreshing if the bot restarts in less than an hour.
            # (In practice, this means that the bot will never have emotes older than 2 hours at maximum)
            ScheduleManager.execute_every(1 * 60 * 60, self.bttv_emote_manager.update_all)
            ScheduleManager.execute_every(1 * 60 * 60, self.ffz_emote_manager.update_all)
            ScheduleManager.execute_every(1 * 60 * 60, self.twitch_emote_manager.update_all)
        except:
            log.exception("Something went wrong trying to initialize automatic emote refresh")
Exemple #26
0
    def enable(self, bot):
        if not bot:
            return

        self.reminder_job = ScheduleManager.execute_every(
            200, self.reminder_bet)
Exemple #27
0
 def init():
     ScheduleManager.execute_every(30 * 60, UserSQLCache._clear_cache)
Exemple #28
0
    def enable(self, bot):
        if not bot:
            return

        self.checkJob = ScheduleManager.execute_every(30, self.check_retimeout)
Exemple #29
0
 def __init__(self, bot):
     super().__init__(bot)
     self.checkJob = ScheduleManager.execute_every(30, self.check_retimeout)
     self.checkJob.pause()
     self.mysqlFormat = "%Y-%m-%d %H:%M:%S"
Exemple #30
0
 def enable(self, bot):
     if bot:
         self.poll_job = ScheduleManager.execute_every(
             15, self.poll_trackobot)
         self.reminder_job = ScheduleManager.execute_every(
             1, self.reminder_bet)
Exemple #31
0
 def init():
     ScheduleManager.execute_every(30 * 60, UserSQLCache._clear_cache)
Exemple #32
0
    def enable(self, bot):
        if bot:
            self.check_job = ScheduleManager.execute_every(10, self.check_run)
            self.checkPaused = False

        HandlerManager.add_handler("on_quit", self.stop_trivia)