google / hypebot

#HypeBotHype

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HypeBot

HypeBot is the perfect way to add more #Hype to your chat application. Simply add this bot to get #Hype.

Development Guide

Want to increase #HypeQuality? Join https://discord.gg/QZmQd5m to get started.

Running the Bot

Use bazel for building all the things. Installation instructions.

bazel build hypebot:lolbot.par --python_path=python3
./bazel-bin/hypebot/lolbot.par \
    --params='{
        "interface": {"token": "[DISCORD_TOKEN]"},
        "riot": {"api_key": "[RIOT_KEY]"},
        "commands": {"WeatherCommand": {"apixu_key": [APIXU_KEY]}
    }'

Discord

Discord is our primary chat application interface. Create an application with Discord. Once the application is created, click "Create A Bot User" to get a Discord Token. You then need admin privileges on a server and select "Generate OAuth2 URL" to invite the bot to your server.

Weather Key

HypeBot gets its weather from www.apixu.com. Sign up to get your key.

Storage

By default, HypeBot looks for a Redis server running on localhost at the default port 6379. You can pass overrides in --params to use a different location.

Riot

To integrate with the Riot API, you need to create an application in order to get an API Key.

Type Annotations

HypeBot is joining the 21st century and attempting to use a new fancy type annotation or hinting library to reduce the number of bugs that careless humans introduce into the otherwise spotless codebase. As you modify existing code or add new functionality, please use typing. Since we only support python3, this can be done in two easy steps.

  1. Add the relevant imports from the typing module into your python file depending on the types used in your code.

    from typing import Any, Callable
    
  2. Add type annotations to your function definitions. As an example:

    def DisableSkynet(requesting_user, confirmation_id,
                      post_disable_fn, are_you_really_sure=False):
      ...
    
    # This turns into...
    
    def DisableSkynet(requesting_user: str, confirmation_id: int,
                      post_disable_fn: Callable[..., None]
                      are_you_really_sure: bool = False) -> None:
      ...
    

    Note: The ellipse inside Callable mean that post_disable_fn can take any number of arguments. If you want to annotate the function's arguments, use the Callable[[int, str], None] format.

A few "best" practices:

  • Annotating public methods is strongly encouraged
  • Annotating private methods is optional, but encouraged where it helps readability
  • Complex types (particularly ones from outside hypebot) can be omitted or replaced with Any
  • For any other questions, refer to PEP484.

What about HypeParams?

Because of how HypeParams operates (specifically, creating attributes dynamically from the initialization dict), typing can't provide useful type-checking to these objects. If you need to annotate a HypeParams instance, just use Any as per the best practices above.

Legal

Hypebot is not an official Google product.

About

#HypeBotHype

License:Apache License 2.0


Languages

Language:Python 97.3%Language:Starlark 2.7%