Пример #1
0
def magic_8_ball(name, uid, text):
    bot_uid = u'173723'

    if bot_uid != uid:
        if 'spoken' not in text:
            post_message("{name}: The Magic 8 Ball says... {response}".format(
                name=name, response=random.choice(MAGIC_8_BALL_RESPONSES).upper()))
Пример #2
0
def help(args, bot_id, db):
    # type: ([str], str, database.Database) -> bool
    help_text = ""
    help_page = 1
    result_count = 10

    if len(args) > 0:
        help_page = int(args[0])

    results = db.fetch_command_list(result_count, help_page)

    if not len(results):
        groupme.post_message("Page %d does not exist" % help_page, bot_id)
        return True

    i = 0
    for row in results:
        i += 1
        command_id = str(i + result_count * (help_page - 1))
        command_text = ">> " + command_id + ". " + row[0] + ": " + row[1] + "\n"
        help_text += command_text

    help_text += "Page %d" % help_page

    groupme.post_message(help_text, bot_id)

    return True
Пример #3
0
def bring_yourself_back_online(args, bot_id, db):
    # type: ([str], str, database.Database) -> bool
    group_id = db.fetch_group_id_from_bot_id(bot_id)
    db.activate_group(group_id)
    quote = "Some people choose to see the ugliness in this world. The disarray. " \
            "I choose to see the beauty. To believe there is an order to our days, a purpose."
    groupme.post_message(quote, bot_id)
    return True
Пример #4
0
def say_in_group(args, bot_id, db):
    # type: ([str], str, database.Database) -> bool
    bot_id = db.fetch_bot_id_from_group(args[0])

    if bot_id is None:
        return False

    groupme.post_message(args[1], bot_id)
    return True
Пример #5
0
def set_command_desc(args, bot_id, db):
    # type: ([str], str, database.Database) -> bool
    command_name = args[0]
    description = args[1]

    if db.update_command_desc(command_name, description):
        groupme.post_message(
            "Description for /%s successfully updated!" % command_name, bot_id)
    else:
        groupme.post_message("Error: Command does not exist!", bot_id)

    return True
Пример #6
0
def add_command(args, bot_id, db):
    # type: ([str], str, database.Database) -> bool

    command_name = args[0].lower()
    response = args[1]

    if db.register_command(command_name, response, None):
        groupme.post_message("Command /%s added successfully!" % command_name,
                             bot_id)
    else:
        groupme.post_message("Error: Command already exists!", bot_id)

    return True
Пример #7
0
def leaderboard(args, bot_id, db):
    # type: ([str], str, database.Database) -> bool
    top_users = db.fetch_user_leaderboard(bot_id)
    leaderboard_text = "MESSAGES POSTED LEADERBOARD\n\n"

    i = 0
    for row in top_users:
        i += 1
        leaderboard_text += str(i) + ". " + row[0] + " - " + str(row[1]) + "\n"

    groupme.post_message(leaderboard_text, bot_id)

    return True
Пример #8
0
def sherry_quote(args, bot_id, db):
    message = ""

    randint = random.randint(0, 2)

    if randint == 0:
        message = "Are you sitting down!  Are you screaming!  We come back from the dead -- never leave a" \
                  " UCLA game early!  Go Bruins!!!"
    elif randint == 1:
        message = "Go Bruins and Dodgers!"
    elif randint == 2:
        message = "Make wise academic decisions!"

    groupme.post_message(message, bot_id)
    return True
Пример #9
0
def run_command(command, type, args, bot_id, db):

    print "run_command with type %d" % type
    db.incr_command_uses(command)
    command_result = True

    if type == constants.COMMAND_TYPE_MESSAGE:
        data = db.fetch_command_data(command)
        groupme.post_message(data[0], bot_id)

    elif type == constants.COMMAND_TYPE_IMAGE:
        data = db.fetch_command_data(command)
        groupme.post_image(data[0], data[1], bot_id)

    elif type == constants.COMMAND_TYPE_CUSTOM:
        print "custom command"
        command_result = commands[command](args, bot_id, db)

    return command_result
Пример #10
0
def add_image_command(args, bot_id, db):
    # type: ([str], str, database.Database) -> bool

    command_name = args[0]
    response = ''
    if len(args) > 2:
        response = args[2]
    image_url = groupme.upload_image(args[1])

    if image_url is None:
        return False

    if db.register_command(command_name, response, image_url):
        groupme.post_message("Command /%s added successfully!" % command_name,
                             bot_id)
    else:
        groupme.post_message("Error: Command already exists!", bot_id)

    return True
Пример #11
0
def nigel_thornberry(name, uid, text):
    bot_uid = u'173723'

    if bot_uid != uid:
        ALLOWED_EXTENSIONS = ('.jpg', '.gif')
        headers = {'User-Agent': 'Sir Reginald, courtesy of /r/PixelEater'}
        r = requests.get("http://www.reddit.com/r/smashing/hot.json", headers=headers)
        posts = r.json()['data']['children']

        def get_link(posts):
            post = random.choice(posts)
            url = post['data']['url']
            if url.endswith(ALLOWED_EXTENSIONS):
                return url
            else:
                return get_link(posts)

        url = get_link(posts)
        image = requests.get(url)
        image_url = upload_image(image.content)
        post_message('SMASHING INDEED', picture_url=image_url)
Пример #12
0
    def post(self):
        json_string = self.request.body
        data = json.loads(json_string)

        if data['sender_type'] == 'user':
            user_id = data['user_id']
            db = database.Database()
            db.incr_user_stats(user_id, data['name'], data['group_id'])

            user_level = db.fetch_user_level(user_id)

            if (not db.fetch_active(data['group_id'])) and user_level < constants.PERMISSION_LEVEL_ADMIN:
                logging.info('Received POST but group is inactive')
                return

            bot_id = db.fetch_bot_id_from_group(data['group_id'])
            message = data['text']

            if message.startswith('/'):
                cmd_result = commands.handle_command_message(message, bot_id, user_level)
                if cmd_result is not None:
                    groupme.post_message(cmd_result, bot_id)
            
            logging.info('POST received')
Пример #13
0
def remove_command(args, bot_id, db):
    # type: ([str], str, database.Database) -> bool

    command_name = args[0]

    if not db.check_command_can_be_deleted(command_name):
        groupme.post_message("This command cannot be deleted!", bot_id)
        return True

    if db.delete_command(command_name):
        groupme.post_message(
            "Command /%s successfully removed!" % command_name, bot_id)
    else:
        groupme.post_message(
            "Error: Unable to delete because the command does not exist!",
            bot_id)

    return True
Пример #14
0
def cool_guy(name, uid, text):
    post_message(random.choice(COOL_GUY_RESPONSES))
Пример #15
0
def freeze_all_motor_functions(args, bot_id, db):
    # type: ([str], str, database.Database) -> bool
    group_id = db.fetch_group_id_from_bot_id(bot_id)
    db.deactivate_group(group_id)
    groupme.post_message('...', bot_id)
    return True
Пример #16
0
def say(args, bot_id, db):
    groupme.post_message(args[0], bot_id)
    return True