コード例 #1
0
ファイル: status.py プロジェクト: jdost/lazbot_plugins
def show(channel, user, status="open"):
    ''' lists the polls in this context
    Will list the polls in the channel based on their status.  If no status is
    provided, it will assume `open`.  The list will give the question and a
    URL to the original question post.

    usage: `@me show [<status>] polls`
        <status> can be either 'open' or 'closed'
    '''
    filter = {}
    filter["state"] = Poll.OPEN if status == "open" else Poll.CLOSED
    if channel.type == Channel.IM:
        filter["user"] = user
    else:
        filter["channel"] = channel

    open_polls = Poll.find(**filter)

    if not len(open_polls):
        bot.post(
            channel=channel,
            text="No open polls"
        )

    for poll in open_polls:
        bot.post(
            channel=channel,
            text="{}".format(poll.msg.__url__(poll.question))
        )
コード例 #2
0
ファイル: commands.py プロジェクト: jdost/challonger
def list_matches(channel, **kwargs):
    matches = []
    for match in state.matches.values():
        if match.is_open():
            matches.append(str(match))
    bot.post(
        channel=channel,
        text=', '.join(matches)
    )
コード例 #3
0
ファイル: admin.py プロジェクト: jdost/lazbot
def unload(name, channel):
    ''' attempts to completely unload a plugin

    Note: this may not always work, it depends on if the internals are properly
    tracking everything.

    usage: `!unload <plugin>`
    '''
    plugin = Plugin.find(name)
    if not plugin:
        bot.post(channel, text="{!s} is not a loaded plugin".format(name))
        return

    plugin.unload()
コード例 #4
0
ファイル: scheduler.py プロジェクト: jdost/challonger
def schedule(time, ability, user, channel, **kwargs):
    time = aliases.get(time, time)
    if time not in [LUNCH, AFTER_WORK]:
        bot.post(channel=channel, text="Sorry {!s}, I don't know that time.".format(user))

    available_users = available[time]
    if user in available_users[ability]:
        return

    available_users[ability].add(user)
    for match in check(user):
        unavailable_users = match & available_users["can't"]
        if len(unavailable_users) > 0:
            if len(unavailable_users) > 1:
                bot.post(
                    channel=channel,
                    text="Sorry, {} cannot play at that time".format(", ".join(map(str, unavailable_users))),
                )
            return

        required_users = match - available_users["can"]
        if len(required_users):
            bot.post(channel=channel, text="Still waiting to hear from: {}".format(", ".join(map(str, required_users))))
        else:
            bot.post(channel=channel, text="{!s} is happening!".format(match))
コード例 #5
0
ファイル: commands.py プロジェクト: jdost/challonger
def link_users(user, channel, users, participant, **kwargs):
    participant = None
    for player in state.players.values():
        if player.name == participant:
            participant = player
            break

    if not participant:
        bot.post(
            channel=channel,
            text=u"sorry {!s}, {} does not exist".format(user, participant)
        )
        return

    participant.register(*users)
コード例 #6
0
def show(channel, user, status="open"):
    ''' lists the polls in this context
    Will list the polls in the channel based on their status.  If no status is
    provided, it will assume `open`.  The list will give the question and a
    URL to the original question post.

    usage: `@me show [<status>] polls`
        <status> can be either 'open' or 'closed'
    '''
    filter = {}
    filter["state"] = Poll.OPEN if status == "open" else Poll.CLOSED
    if channel.type == Channel.IM:
        filter["user"] = user
    else:
        filter["channel"] = channel

    open_polls = Poll.find(**filter)

    if not len(open_polls):
        bot.post(channel=channel, text="No open polls")

    for poll in open_polls:
        bot.post(channel=channel,
                 text="{}".format(poll.msg.__url__(poll.question)))
コード例 #7
0
ファイル: state.py プロジェクト: jdost/challonger
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)