@@ -0,0 +1,2114 @@
+%22%22%22Search Giphy.%22%22%22%0A%0Aimport random%0A%0Afrom plumeria import config%0Afrom plumeria.command import commands, CommandError%0Afrom plumeria.command.parse import Text%0Afrom plumeria.plugin import PluginSetupError%0Afrom plumeria.util import http%0Afrom plumeria.util.ratelimit import rate_limit%0A%0Aapi_key = config.create(%22giphy%22, %22key%22,%0A                        fallback=%22%22,%0A                        comment=%22A Giphy API key. API keys can be registered at %22%0A                                %22https://developers.giphy.com/dashboard/%22)%0A%0A%0Adef collect_photos(posts):%0A    options = %5B%5D%0A    for entry in posts:%0A        if 'photos' in entry:%0A            for photo in entry%5B'photos'%5D:%0A                options.append(photo%5B'original_size'%5D%5B'url'%5D)%0A    return options%0A%0A%0A@commands.create('giphy', cost=2, category='Search', params=%5BText('query')%5D)%0A@rate_limit()%0Aasync def search(message, query):%0A    %22%22%22%0A    Search Giphy for images and pick a random one.%0A%0A    Example::%0A%0A        /giphy all time low%0A%0A    %22%22%22%0A    r = await http.get(%22https://api.giphy.com/v1/gifs/search%22, params=%7B%0A        %22q%22: query,%0A        %22api_key%22: api_key()%0A    %7D)%0A    data = r.json()%0A%0A    if not len(data%5B'data'%5D):%0A        raise CommandError(%22No results matching '%7B%7D'.%22.format(query))%0A%0A    return random.choice(data%5B'data'%5D)%5B'url'%5D%0A%0A%0A@commands.create('sticker', cost=2, category='Search', params=%5BText('query')%5D)%0A@rate_limit()%0Aasync def sticker(message, query):%0A    %22%22%22%0A    Search Giphy for stickers and pick a random one.%0A%0A    Example::%0A%0A        /sticker happy%0A%0A    %22%22%22%0A    r = await http.get(%22https://api.giphy.com/v1/stickers/search%22, params=%7B%0A        %22q%22: query,%0A        %22api_key%22: api_key()%0A    %7D)%0A    data = r.json()%0A%0A    if not len(data%5B'data'%5D):%0A        raise CommandError(%22No results matching '%7B%7D'.%22.format(query))%0A%0A    return random.choice(data%5B'data'%5D)%5B'url'%5D%0A%0A%0Adef setup():%0A    config.add(api_key)%0A%0A    if not api_key():%0A        raise PluginSetupError(%22This plugin requires an API key from Giphy. Registration is free. Get keys from %22%0A                               %22https://developers.giphy.com/dashboard/.%22)%0A%0A    commands.add(search)%0A    commands.add(sticker)%0A

Add Giphy plugin.