initial commit of corrected code
This commit is contained in:
parent
e77ae0c39f
commit
8680ae5712
1 changed files with 17 additions and 62 deletions
75
catto.py
75
catto.py
|
@ -1,15 +1,13 @@
|
||||||
#import re
|
import logging
|
||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
import logging
|
|
||||||
import requests
|
import requests
|
||||||
from errbot import BotPlugin, botcmd, re_botcmd
|
from errbot import BotPlugin, botcmd
|
||||||
|
|
||||||
class Catto(BotPlugin):
|
class Catto(BotPlugin):
|
||||||
"""Plugin for random cat images!"""
|
"""Fetch random cat images URLs"""
|
||||||
min_err_version = '3.0.0' # Optional, but recommended
|
min_err_version = '3.0.0' # Optional, but recommended
|
||||||
|
|
||||||
|
|
||||||
def get_catapi_pic(self, type):
|
def get_catapi_pic(self, type):
|
||||||
api_url = 'https://api.thecatapi.com/v1/images/search'
|
api_url = 'https://api.thecatapi.com/v1/images/search'
|
||||||
api_key = '9880edd3-3c4f-4758-aebe-c7182aeb3a70'
|
api_key = '9880edd3-3c4f-4758-aebe-c7182aeb3a70'
|
||||||
|
@ -38,64 +36,21 @@ class Catto(BotPlugin):
|
||||||
return json.loads(response.text)['file']
|
return json.loads(response.text)['file']
|
||||||
|
|
||||||
def get_catpic(self):
|
def get_catpic(self):
|
||||||
flip = random.randint(0, 1)
|
choice = random.randint(0, 2)
|
||||||
if flip == 0:
|
if choice < 2:
|
||||||
return self.get_catapi_pic("jpg,png,gif")
|
return self.get_catapi_pic("jpg,png,gif")
|
||||||
return self.get_randomcat_pic()
|
return self.get_randomcat_pic()
|
||||||
|
|
||||||
@botcmd()
|
@botcmd(split_args_with=' ')
|
||||||
def catto(self, msg, args):
|
def catto(self, msg, args):
|
||||||
"""Retrieve a random cat image, which may be animated (gif) or still (jpg/png)"""
|
"""Fetch a random cat image, which may be animated (gif) or still (jpg/png)"""
|
||||||
if "gif" in args:
|
if len(args) > 0 and args[0]:
|
||||||
return self.catto_gif(msg, args)
|
type = args[0]
|
||||||
elif "still" in args:
|
if type == 'gif':
|
||||||
return self.catto_still(msg, args)
|
|
||||||
return self.get_catpic()
|
|
||||||
|
|
||||||
@botcmd()
|
|
||||||
def catto_gif(self, msg, args):
|
|
||||||
"""Retrieve a random cat animated gif"""
|
|
||||||
return self.get_catapi_pic("gif")
|
return self.get_catapi_pic("gif")
|
||||||
|
elif type == 'still':
|
||||||
@botcmd()
|
|
||||||
def catto_still(self, msg, args):
|
|
||||||
"""Retrieve a random cat still picture (not animated)"""
|
|
||||||
return self.get_catapi_pic("jpg,png")
|
return self.get_catapi_pic("jpg,png")
|
||||||
|
else:
|
||||||
|
return 'Unrecognized image type. Please use "gif" or "still" or leave blank to get either type.'
|
||||||
# @botcmd
|
else:
|
||||||
# def catto_gif(self, msg, args):
|
return self.get_catpic()
|
||||||
# """Retrieve a random cat image"""
|
|
||||||
# return self.get_catpic("gif")
|
|
||||||
|
|
||||||
# """Example 'Hello, world!' plugin, modified by APiontek"""
|
|
||||||
|
|
||||||
# @botcmd
|
|
||||||
# def hello(self, msg, args):
|
|
||||||
# """Say hello to the world"""
|
|
||||||
# return "Fart on this, fucker!!"
|
|
||||||
|
|
||||||
# @re_botcmd(pattern=r"^(([Cc]an|[Mm]ay) I have a )?cookie please\?$")
|
|
||||||
# def hand_out_cookies(self, msg, match):
|
|
||||||
# """
|
|
||||||
# Gives cookies to people who ask me nicely.
|
|
||||||
|
|
||||||
# This command works especially nice if you have the following in
|
|
||||||
# your `config.py`:
|
|
||||||
|
|
||||||
# BOT_ALT_PREFIXES = ('Err',)
|
|
||||||
# BOT_ALT_PREFIX_SEPARATORS = (':', ',', ';')
|
|
||||||
|
|
||||||
# People are then able to say one of the following:
|
|
||||||
|
|
||||||
# Err, can I have a cookie please?
|
|
||||||
# Err: May I have a cookie please?
|
|
||||||
# Err; cookie please?
|
|
||||||
# """
|
|
||||||
# yield "Here's a cookie for you, {}".format(msg.frm)
|
|
||||||
# yield "/me hands out a cookie."
|
|
||||||
|
|
||||||
# @re_botcmd(pattern=r"(^| )cookies?( |$)", prefixed=False, flags=re.IGNORECASE)
|
|
||||||
# def listen_for_talk_of_cookies(self, msg, match):
|
|
||||||
# """Talk of cookies gives Errbot a craving..."""
|
|
||||||
# return "Somebody mentioned cookies? Om nom nom!"
|
|
||||||
|
|
Loading…
Reference in a new issue