Skip to content
This repository was archived by the owner on Aug 15, 2022. It is now read-only.

Commit 25ce082

Browse files
author
Jeff Ammons
committed
Fix PEP8 compliance in example plugins and rtmbot
1 parent 6052333 commit 25ce082

File tree

6 files changed

+33
-22
lines changed

6 files changed

+33
-22
lines changed

doc/example-plugins/canary.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import time
22
outputs = []
33

4+
45
def canary():
5-
#NOTE: you must add a real channel ID for this to work
6+
# NOTE: you must add a real channel ID for this to work
67
outputs.append(["D12345678", "bot started: " + str(time.time())])
78

89
canary()

doc/example-plugins/counter.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
crontable = []
33
outputs = []
44

5-
crontable.append([5,"say_time"])
5+
crontable.append([5, "say_time"])
6+
67

78
def say_time():
8-
#NOTE: you must add a real channel ID for this to work
9+
# NOTE: you must add a real channel ID for this to work
910
outputs.append(["D12345678", time.time()])

doc/example-plugins/repeat.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import time
21
crontable = []
32
outputs = []
43

4+
55
def process_message(data):
66
if data['channel'].startswith("D"):
7-
outputs.append([data['channel'], "from repeat1 \"{}\" in channel {}".format(data['text'], data['channel']) ])
8-
7+
outputs.append([data['channel'], "from repeat1 \"{}\" in channel {}".format(
8+
data['text'], data['channel'])]
9+
)

doc/example-plugins/todo.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@
66

77
tasks = {}
88

9-
FILE="plugins/todo.data"
9+
10+
FILE = "plugins/todo.data"
1011
if os.path.isfile(FILE):
1112
tasks = pickle.load(open(FILE, 'rb'))
1213

14+
1315
def process_message(data):
1416
global tasks
1517
channel = data["channel"]
1618
text = data["text"]
17-
#only accept tasks on DM channels
19+
# only accept tasks on DM channels
1820
if channel.startswith("D"):
1921
if channel not in tasks.keys():
2022
tasks[channel] = []
21-
#do command stuff
23+
# do command stuff
2224
if text.startswith("todo"):
2325
tasks[channel].append(text[5:])
2426
outputs.append([channel, "added"])
@@ -36,4 +38,4 @@ def process_message(data):
3638
tasks[channel].pop(num)
3739
if text == "show":
3840
print tasks
39-
pickle.dump(tasks, open(FILE,"wb"))
41+
pickle.dump(tasks, open(FILE, "wb"))

rtmbot.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
#!/usr/bin/env python
2-
32
import sys
4-
5-
sys.dont_write_bytecode = True
6-
73
import glob
84
import yaml
95
import os
106
import time
117
import logging
8+
129
from argparse import ArgumentParser
1310

1411
from slackclient import SlackClient
1512

13+
sys.dont_write_bytecode = True
14+
1615

1716
def dbg(debug_string):
1817
if debug:
@@ -66,14 +65,14 @@ def output(self):
6665
if limiter:
6766
time.sleep(.1)
6867
limiter = False
69-
message = output[1].encode('ascii','ignore')
68+
message = output[1].encode('ascii', 'ignore')
7069
channel.send_message("{}".format(message))
71-
limiter = True # TODO: check goal: no sleep for 1st channel, sleep of all after ?
70+
limiter = True
71+
# TODO: check goal: no sleep for 1st channel, sleep of all after ?
7272
# TODO: find out how to safely encode stuff if needed :(
7373
# message = output[1].encode('utf-8','ignore')
7474
channel.send_message(output[1]) # message
7575

76-
7776
def crons(self):
7877
for plugin in self.bot_plugins:
7978
plugin.do_jobs()
@@ -82,18 +81,21 @@ def load_plugins(self):
8281
for plugin in glob.glob(directory + '/plugins/*'):
8382
sys.path.insert(0, plugin)
8483
sys.path.insert(0, directory + '/plugins/')
85-
for plugin in glob.glob(directory + '/plugins/*.py') + glob.glob(directory + '/plugins/*/*.py'):
84+
for plugin in glob.glob(directory + '/plugins/*.py') + \
85+
glob.glob(directory + '/plugins/*/*.py'):
8686
logging.info(plugin)
8787
name = plugin.split('/')[-1][:-3]
8888
# try:
8989
self.bot_plugins.append(Plugin(name))
9090
# except:
9191
# print "error loading plugin %s" % name
9292

93+
9394
class Plugin(object):
95+
9496
def __init__(self, name, plugin_config=None):
9597
if plugin_config is None:
96-
plugin_config = {} #TODO: is this necessary?
98+
plugin_config = {} # TODO: is this necessary?
9799
self.name = name
98100
self.jobs = []
99101
self.module = __import__(name)
@@ -179,7 +181,11 @@ class UnknownChannel(Exception):
179181

180182
def main_loop():
181183
if "LOGFILE" in config:
182-
logging.basicConfig(filename=config["LOGFILE"], level=logging.INFO, format='%(asctime)s %(message)s')
184+
logging.basicConfig(
185+
filename=config["LOGFILE"],
186+
level=logging.INFO,
187+
format='%(asctime)s %(message)s'
188+
)
183189
logging.info(directory)
184190
try:
185191
bot.start()
@@ -215,7 +221,7 @@ def parse_args():
215221
files_currently_downloading = []
216222
job_hash = {}
217223

218-
if config.has_key("DAEMON"):
224+
if 'DAEMON' in config:
219225
if config["DAEMON"]:
220226
import daemon
221227

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ basepython =
2020
[testenv:flake8]
2121
basepython=python
2222
deps=flake8
23-
commands=flake8 {toxinidir}/rtmbot.py {toxinidir}/example-plugins
23+
commands=flake8 {toxinidir}/rtmbot.py {toxinidir}/doc/example-plugins

0 commit comments

Comments
 (0)