Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
nficano committed Oct 19, 2018
1 parent d3db50f commit d03b3ed
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 26 deletions.
2 changes: 1 addition & 1 deletion artwork/tangerine.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 10 additions & 3 deletions samples/image_me.py
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""
google image me
~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -28,9 +29,15 @@ def image_me(user, message):


def google_image_search(query):
resp = requests.get(URL, params={
'v': '1.0', 'searchType': 'image', 'q': query.strip(),
'cx': CSE_ID, 'key': CSE_KEY})
resp = requests.get(
URL, params={
'v': '1.0',
'searchType':
'image', 'q': query.strip(),
'cx': CSE_ID,
'key': CSE_KEY,
},
)
if not resp.ok:
yield
for i in resp.json().get('items', []):
Expand Down
9 changes: 6 additions & 3 deletions samples/reddit_rando.py
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""
reddit rando (comment)
~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -62,9 +63,11 @@ def get_random_comment_in_subreddit(subreddit):


def reddit_request(url):
resp = requests.get(url, headers={
'User-agent': 'darwin:slackbot:v1.2.3 (by /u/nficano)'
})
resp = requests.get(
url, headers={
'User-agent': 'darwin:slackbot:v1.2.3 (by /u/nficano)',
},
)
if not resp.ok:
return False, resp
return True, resp.json()
Expand Down
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -44,6 +44,7 @@ def run(self):
os.system('twine upload dist/*')
sys.exit()


setup(
name='slack-tangerine',
version='4.1.4',
Expand Down
45 changes: 26 additions & 19 deletions tangerine/bot.py
Expand Up @@ -20,13 +20,14 @@

log = logging.getLogger(__name__)

Listener = namedtuple('Listener', (
'rule',
'view_func',
'trigger',
'doc',
'options'
)
Listener = namedtuple(
'Listener', (
'rule',
'view_func',
'trigger',
'doc',
'options',
),
)


Expand All @@ -44,7 +45,7 @@ def __init__(self, slack_token=None, settings=None):
self.scheduled_tasks = []

self.client = SlackClient(
slack_token or self.settings.tangerine.auth_token
slack_token or self.settings.tangerine.auth_token,
)
self.sleep = self.settings.tangerine.sleep

Expand Down Expand Up @@ -141,7 +142,7 @@ def respond(self, user, message, channel):
sendable = {
'user': user,
'message': message,
'channel': channel
'channel': channel,
}
if not message:
return
Expand All @@ -156,12 +157,14 @@ def respond(self, user, message, channel):
time.sleep(.2)
self.client.server.send_to_websocket({
'type': 'typing',
'channel': channel
'channel': channel,
})
time.sleep(.5)
if '{user.username}' in response:
response = response.replace('{user.username}',
self.get_user_name(user))
response = response.replace(
'{user.username}',
self.get_user_name(user),
)
self.speak(response, channel)

def add_listener(self, rule, view_func, trigger, docs, **options):
Expand All @@ -173,15 +176,17 @@ def add_listener(self, rule, view_func, trigger, docs, **options):
if not six.callable(view_func):
raise TypeError('view_func should be callable')
self.listeners.append(
Listener(rule, view_func, trigger, docs, options)
Listener(rule, view_func, trigger, docs, options),
)

def add_cron(self, schedule, f, **options):
self.scheduled_tasks.append(Task(schedule, f, **options))

def speak(self, message, channel, **kwargs):
self.client.api_call('chat.postMessage', as_user=True,
channel=channel, text=message, **kwargs)
self.client.api_call(
'chat.postMessage', as_user=True,
channel=channel, text=message, **kwargs,
)

def get_user_info(self, user_id):
return self.client.api_call('users.info', user=user_id)
Expand All @@ -200,7 +205,8 @@ def get_channel_id_from_name(self, channel):
types = ','.join(['public_channel', 'private_channel'])

response = self.client.api_call(
'conversations.list', types=types, limit=1000)
'conversations.list', types=types, limit=1000,
)
for c in response['channels']:
if channel == c['name'].lower():
return c['id']
Expand All @@ -214,7 +220,8 @@ def get_channel_name_from_channel_id(self, channel_id):
types = ','.join(['public_channel', 'private_channel'])

response = self.client.api_call(
'conversations.list', types=types, limit=1000)
'conversations.list', types=types, limit=1000,
)
for c in response['channels']:
if channel_id == c['id']:
return c['name']
Expand All @@ -230,13 +237,13 @@ def get_template_path(self):
else:
return os.path.join(
os.getcwd(),
self.settings.tangerine.template_folder
self.settings.tangerine.template_folder,
)

def get_jinja_environment(self):
return self.jinja_environment(
loader=FileSystemLoader(self.get_template_path()),
autoescape=select_autoescape(['txt'])
autoescape=select_autoescape(['txt']),
)

def render_template(self, template_name, **context):
Expand Down

0 comments on commit d03b3ed

Please sign in to comment.