more cake
This commit is contained in:
13
common.py
13
common.py
@@ -1,6 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
""" Common functions for urlbot """
|
""" Common functions for urlbot """
|
||||||
import html.parser
|
import html.parser
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
@@ -192,3 +193,15 @@ def extract_title(url):
|
|||||||
return expanded_html
|
return expanded_html
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def giphy(subject, api_key):
|
||||||
|
url = 'http://api.giphy.com/v1/gifs/random?tag={}&api_key={}&limit=1&offset=0'.format(subject, api_key)
|
||||||
|
response = urllib.request.urlopen(url)
|
||||||
|
giphy_url = None
|
||||||
|
try:
|
||||||
|
data = json.loads(response.read().decode('utf-8'))
|
||||||
|
giphy_url = data['data']['image_url']
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return giphy_url
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import urllib.parse
|
|||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
||||||
from common import RATE_GLOBAL, RATE_NO_SILENCE, VERSION, RATE_INTERACTIVE, BUFSIZ, \
|
from common import RATE_GLOBAL, RATE_NO_SILENCE, VERSION, RATE_INTERACTIVE, BUFSIZ, \
|
||||||
USER_AGENT, extract_title, RATE_FUN, RATE_NO_LIMIT, RATE_URL
|
USER_AGENT, extract_title, RATE_FUN, RATE_NO_LIMIT, RATE_URL, giphy
|
||||||
from config import runtimeconf_get
|
from config import runtimeconf_get
|
||||||
import config
|
import config
|
||||||
from string_constants import excuses, moin_strings_hi, moin_strings_bye, cakes
|
from string_constants import excuses, moin_strings_hi, moin_strings_bye, cakes
|
||||||
@@ -603,8 +603,10 @@ def command_usersetting(argv, **args):
|
|||||||
|
|
||||||
@pluginfunction('cake', 'displays a cake ASCII art', ptypes_COMMAND, ratelimit_class=RATE_FUN | RATE_GLOBAL)
|
@pluginfunction('cake', 'displays a cake ASCII art', ptypes_COMMAND, ratelimit_class=RATE_FUN | RATE_GLOBAL)
|
||||||
def command_cake(argv, **args):
|
def command_cake(argv, **args):
|
||||||
if 'cake' != argv[0]:
|
if 'please' in argv:
|
||||||
return
|
return {
|
||||||
|
'msg': 'cake for {}: {}'.format(args['reply_user'], giphy('cake', 'dc6zaTOxFJmzC'))
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'msg': args['reply_user'] + ': %s' % (random.sample(cakes, 1)[0])
|
'msg': args['reply_user'] + ': %s' % (random.sample(cakes, 1)[0])
|
||||||
|
|||||||
Reference in New Issue
Block a user