Ejemplo n.º 1
0
def kill(channel):
    ''' kill/stop the bot from running

    usage: `!kill`
    '''
    logger.info("Being killed via %s", channel)
    bot.stop()
Ejemplo n.º 2
0
Archivo: ext.py Proyecto: jdost/lazbot
def fix_users(client, users):
    ''' Take all provided users from login and create the rich `User` objects
    for them and add to the bot's lookup dictionary.
    '''
    for user in map(User, users):
        bot.users[user.id] = user

    logger.info("Loaded %d users", len(users))
Ejemplo n.º 3
0
    def close(self):
        self.state = Poll.CLOSED
        self.tally()

        logger.info("Poll closed")
        logger.info(str(self))

        self.msg = self.channel.post(self._results_str())
        self.msg = self.msg[0] if isinstance(self.msg, list) else self.msg
Ejemplo n.º 4
0
def check_day():
    logger.debug("Checking date...")
    now = datetime.now(tz())

    global open_dev
    open_dev_offset = now - OPEN_DEV_EPOCH
    open_dev = open_dev_offset.days % config["opendev"]["offset"] == 0
    if open_dev:
        logger.info("Open Dev has started")
Ejemplo n.º 5
0
Archivo: db.py Proyecto: jdost/lazbot
    def close(self):
        from lazbot import logger
        for name, db in self.dbs.items():
            if not db:
                continue

            logger.info("Closing db: %s", name)
            db.close()
            self.dbs[name] = None
Ejemplo n.º 6
0
Archivo: db.py Proyecto: jdost/lazbot
    def setup(self, config=None):
        import os
        from lazbot.utils import merge
        from lazbot import logger

        if config:
            self.config = merge(self.config, **config)

        if not os.path.exists(self.config["dir"]):
            os.mkdir(self.config["dir"])
            logger.info("Creating data directory: %s", self.config["dir"])
Ejemplo n.º 7
0
Archivo: ext.py Proyecto: jdost/lazbot
def user_updated(user):
    ''' Listen for user update events and update the user model on the bot.
    '''
    if user.id in bot.users:
        diff = compare(bot.users[user.id], user, User.KEYS)
        log_diff(diff)
        logger.debug("User updated: %s", user)
    else:
        logger.info("User created: %s (%s)", user, user.id)

    bot.users[user.id] = user
Ejemplo n.º 8
0
def cleanup():
    deleted_polls = []
    now = datetime.now()

    for poll in polls:
        if poll.state == Poll.OPEN and now - poll.created_at > EXPIRATION:
            deleted_polls.append(poll)

    for poll in deleted_polls:
        logger.info("Deleting poll %s", poll)
        poll.delete()
Ejemplo n.º 9
0
def cleanup():
    deleted_polls = []
    now = datetime.now()

    for poll in polls:
        if poll.state == Poll.OPEN and now - poll.created_at > EXPIRATION:
            deleted_polls.append(poll)

    for poll in deleted_polls:
        logger.info("Deleting poll %s", poll)
        poll.delete()
Ejemplo n.º 10
0
Archivo: db.py Proyecto: jdost/lazbot
    def _db(self):
        from lazbot.plugin import current_plugin
        import os.path as path
        from lazbot import logger

        plugin = str(current_plugin())
        location = path.join(self.config["dir"], plugin)
        if plugin not in self.dbs or self.dbs[plugin] is None:
            logger.info("Loading db for %s at %s", plugin, location)
            if self.config["backend"] == "anydbm":
                import anydbm
                self.dbs[plugin] = anydbm.open(location, "c")
            elif self.config["backend"] == "shelve":
                import shelve
                self.dbs[plugin] = shelve.open(location)

        return self.dbs[plugin]
Ejemplo n.º 11
0
def react(user, msg):
    from condor import is_opendev
    if not is_opendev():
        return

    if not user:
        return

    if user.name in reactions.keys():
        logger.info("Reacting with %s for %s.",
                    ", ".join(reactions[user.name]), user)

        for emoji in reactions[user.name]:
            try:
                msg.react(emoji)
            except Exception as e:
                logger.error("Reaction %s for %s failed: %s", emoji, user.name,
                             e)
Ejemplo n.º 12
0
def react(user, msg):
    from condor import is_opendev
    if not is_opendev():
        return

    if not user:
        return

    if user.name in reactions.keys():
        logger.info("Reacting with %s for %s.",
                    ", ".join(reactions[user.name]), user)

        for emoji in reactions[user.name]:
            try:
                msg.react(emoji)
            except Exception as e:
                logger.error("Reaction %s for %s failed: %s",
                             emoji, user.name, e)
Ejemplo n.º 13
0
Archivo: ext.py Proyecto: jdost/lazbot
def fix_channels(client, channels=[], groups=[], ims=[]):
    ''' Take all provided channels, groups, and ims from login  and create the
    rich `Channel` objects for them and add to the bot's lookup dictionary.
    '''
    total = 0
    for channel in channels:
        bot.channels[channel["id"]] = Channel(channel)
        total += 1

    for group in groups:
        bot.channels[group["id"]] = Channel(group)
        total += 1

    for im in ims:
        bot.channels[im["id"]] = Channel(im)
        total += 1

    logger.info("Loaded %d channels", total)
Ejemplo n.º 14
0
def start(channel, question, user, target=None):
    ''' asks a channel a question as a poll
    Will post a poll to a channel, which entails the question asked and
    reaction based options to "vote" on your responses to the question.  If
    a channel is specified, the question will target that channel, if none is
    provided, it will be in the current channel.

    usage: `@me ask [<channel>] <question>`
    '''
    if Poll.find(user=user, channel=channel):
        user.im("You already have a poll open in {!s}".format(channel))
        return

    if not target:
        target = channel

    poll = Poll(question, user, target)

    logger.info(str(poll))
    poll.ask()
Ejemplo n.º 15
0
def start(channel, question, user, target=None):
    ''' asks a channel a question as a poll
    Will post a poll to a channel, which entails the question asked and
    reaction based options to "vote" on your responses to the question.  If
    a channel is specified, the question will target that channel, if none is
    provided, it will be in the current channel.

    usage: `@me ask [<channel>] <question>`
    '''
    if Poll.find(user=user, channel=channel):
        user.im("You already have a poll open in {!s}".format(channel))
        return

    if not target:
        target = channel

    poll = Poll(question, user, target)

    logger.info(str(poll))
    poll.ask()
Ejemplo n.º 16
0
def load_info(*args, **kwargs):
    global tournaments
    global default_tournament
    global players
    global last_update

    tournaments = challonge.tournaments.index()
    logger.info("Loaded %d tournaments", len(tournaments))

    default_tournament = [tournament for tournament in tournaments
                          if not tournament["completed-at"]][0]

    for participant in challonge.participants.index(default_tournament["id"]):
        players[participant["id"]] = Participant(
            default_tournament["id"], participant)

    for match in challonge.matches.index(default_tournament["id"]):
        matches[match["id"]] = Match(match)

    logger.info("Loaded %d players", len(players))
    last_update = datetime.now()
Ejemplo n.º 17
0
def check_for_updates():
    global last_update
    changes = 0
    matches = []

    try:
        matches = challonge.matches.index(default_tournament["id"])
    except Exception as error:
        logger.error("Error connecting: %s", error)
        return

    for match_data in matches:
        match = get_match(match_data["id"])
        update = match.update(match_data)
        if update:
            changes += 1
            for channel in config["challonger"]["channels"]:
                bot.post(
                    channel=lookup_channel(channel),
                    text=str(match),
                )

    last_update = datetime.now()
    logger.info("Updated %s matches", changes)
Ejemplo n.º 18
0
def load():
    global polls
    polls = [Poll.from_json(json) for json in db.get("polls", [])]
    logger.info("Loaded %s polls", len(polls))
    logger.info("Loaded %s active polls",
                len([True for p in polls if p.state != Poll.CLOSED]))
Ejemplo n.º 19
0
Archivo: ext.py Proyecto: jdost/lazbot
def channel_created(channel):
    ''' Listen for channel creation events and add them to the lookup.
    '''
    bot.channels[channel.id] = channel
    logger.info("Added channel %s", channel)