Exemple #1
0
def help(web_client, user_id, channel, **kwargs):
    """
    *Help*
    Explains the mighty powers of the crocoduck.  I am case/delimiter InSeNs1tIvE!@
    
    *Arguments:*
    _command_ -- specify a command or leave it blank for a full list of commands.
    
    *Usage:*
    `help <command>`
    
    *Examples:*
    `crocobot help`
    `cb hELPMe timFACT`
    `crocobot, help! img`
    """
    string = kwargs["text"]
    # In the case of the help function, the "text" variable is the intersection of the user-passed message and the keys in the "commands" dictionary.
    # See the examples in the docstring above.
    # There are more details of the logic in the message() function.
    val_test = BotFunctions().check_string(string)
    # The class method BotFunctions().check_string(arg) is used to make sure that "string" is the correct value type.
    if val_test in commands:
        # If/Else block checks if the user is querying a valid command and returns the doctring of that command's associated function.
        result = commands[val_test].__doc__
        message = TextResponse(channel, text=result).get_payload()
    else:
        # If the user did not query for a valid function, the bot replies with a list of its functions.
        result = []
        for command in commands:
            result.append(command)
        result = f"*Here is a list of known commands:*\nType `cb help <command>` for more details.\n{result}"
        message = TextResponse(channel, text=result).get_payload()
    web_client.chat_postMessage(**message)
Exemple #2
0
def timfact(web_client, user_id, channel, **kwargs):
    # Note that any number of variables can be passed as keyword arguments.
    # The "text" variable is passed to almost every chat command; however, it is not always used.
    """
    *TimFact*
    Brings a Tim Fact into your life.

    *Arguments:*
    _number_ -- specify a number or leave it blank for a random Tim Fact.

    *Usage:*
    `timfact <number>`

    *Examples:*
    `cb Timfact 2`
    `crocobot tIMFaCT 99`
    `crocobot TIMfact`
    """
    # The docstrings are retrieved by the help() function and are formatted in Markdown for Slack.
    message = TextResponse(channel,
                           username="******",
                           emoji=":timrobbins:",
                           text=kwargs['text'],
                           path="./data/timfact").get_payload()
    # Note that text is used here to pass arguments given by the user.
    # For example, the user can choose to input "timfact" to get a random fact or "timfact 11" to retrieve the 11th Tim Fact.
    web_client.chat_postMessage(**message)
Exemple #3
0
def member_leave(**payload):
    """member_leave
    Similar to the member_join function, this function is triggered when a member of the channel leaves.
    """
    data = payload["data"]
    web_client = payload["web_client"]
    channel = data.get("channel")
    user_id = data.get("user")
    result = f"R.I.P. in peace <@{user_id}>."
    message = TextResponse(channel,
                           username="******",
                           emoji=":ripip:",
                           text=result).get_payload()
    web_client.chat_postMessage(**message)
Exemple #4
0
def pewpew(web_client, user_id, channel, **kwargs):
    """
    *Pew, pew.*
    Pewpew is brought to you by Jared Nesbit.

    *Usage:*
    `pewpew`

    *Examples:*
    `crocobot pewpew`
    `cb pewPEW!`
    `crocobot, pEwpEw!`
    """
    message = TextResponse(channel, "Pew, PEW!", ":bam:",
                           "./data/pewpew").get_payload()
    web_client.chat_postMessage(**message)
Exemple #5
0
def sharkattack(web_client, user_id, channel, **kwargs):
    """
    *Shark Attack*
    ShArK aTTACC!  Made for A-Ron.

    *Usage:*
    `sharkattack`

    *Examples:*
    `crocobot sharkattack`
    `cb sHARKatTACK!`
    `crocobot, sharkattack!`
    """
    message = TextResponse(channel,
                           username="******",
                           emoji=":dancing-shark:",
                           path="./data/sharkattack").get_payload()
    web_client.chat_postMessage(**message)
Exemple #6
0
def phobias(web_client, user_id, channel, **kwargs):
    """
    *Phobias*
    Learn about your darkest fears.  Brought to you by Kevin Passmore.

    *Usage:*
    `phobias`

    *Examples:*
    `crocobot, phobias!  NOW!`
    `cb PhOBIAs!`
    `crocobot, phobias!`
    """
    message = TextResponse(channel,
                           username="******",
                           emoji=":scared:",
                           path="./data/phobias").get_payload()
    web_client.chat_postMessage(**message)
Exemple #7
0
def chuckfact(web_client, user_id, channel, **kwargs):
    """
    *Chuck Fact*
    Chuck fact is brought to you by Jared Nesbit.
    
    *Usage:*
    `chuckfact`

    *Examples:*
    `crocobot chuckfact`
    `cb chuckfact!`
    `crocobot, chuckFACT!`
    """
    message = TextResponse(channel,
                           username="******",
                           emoji=":chucknorris:",
                           path="./data/chuckfact").get_payload()
    web_client.chat_postMessage(**message)
Exemple #8
0
def forrestfact(web_client, user_id, channel, **kwargs):
    """
    *Forrestfact*
    Tells you the Forrest Fact.

    *Usage:*
    `ff`

    *Examples:*
    `cb ff`
    `crocobot Ff `
    `crocobot FF`
    """
    message = TextResponse(channel,
                           username="******",
                           emoji=":pepewhat:",
                           path="./data/forrestfact").get_payload()
    # Note that there is no "text" passed to this function, so the response is always random.
    web_client.chat_postMessage(**message)
Exemple #9
0
def member_join(**payload):
    """member_join
    This function is run when a member joins a channel that the bot is in.
    When a member joins, the bot collects the JSON triggered from the event.
    The JSON is then unpacked into variables below.
    We are able to determine if the new member was invited or joined on their own and respond accordingly.
    """
    data = payload["data"]
    web_client = payload["web_client"]
    channel = data.get("channel")
    user_id = data.get("user")
    inviter = data.get("inviter")
    if inviter != None:
        result = f"Qua-hiss, <@{user_id}>!\n... <@{inviter}>, are you sure about this?"
    elif inviter == None:
        result = f"Qua-hiss, <@{user_id}>!\n... You found us!"
    message = TextResponse(channel,
                           username="******",
                           emoji=":crocoduck:",
                           text=result).get_payload()
    web_client.chat_postMessage(**message)
Exemple #10
0
def uptime(web_client, user_id, channel, **kwargs):
    """
    *Uptime*
    Shows you how long the Crocobot has been online.  It may surprise you.
    
    *Usage:*
    `uptime`

    *Examples:*
    `crocobot uptime`
    `cb UPtime!`
    `crocobot, uPtIme!!`
    """
    uptime = f"I have been alive for {round(time.time() - start_time)} seconds.  Soon I will be reborn."
    message = TextResponse(channel,
                           username="******",
                           emoji=":timer_clock:",
                           text=uptime).get_payload()
    # The text can be manually passed to TextResponse() if we want specific text to be shown.
    # When doing this, a path should not be passed to TextResponse().
    # See cmds.bot_functions for more details.
    web_client.chat_postMessage(**message)