Fix PEP8 compliance in example plugins and rtmbot
This commit is contained in:
parent
6052333c64
commit
25ce082eac
6 changed files with 33 additions and 22 deletions
|
@ -1,8 +1,9 @@
|
||||||
import time
|
import time
|
||||||
outputs = []
|
outputs = []
|
||||||
|
|
||||||
|
|
||||||
def canary():
|
def canary():
|
||||||
#NOTE: you must add a real channel ID for this to work
|
# NOTE: you must add a real channel ID for this to work
|
||||||
outputs.append(["D12345678", "bot started: " + str(time.time())])
|
outputs.append(["D12345678", "bot started: " + str(time.time())])
|
||||||
|
|
||||||
canary()
|
canary()
|
||||||
|
|
|
@ -2,8 +2,9 @@ import time
|
||||||
crontable = []
|
crontable = []
|
||||||
outputs = []
|
outputs = []
|
||||||
|
|
||||||
crontable.append([5,"say_time"])
|
crontable.append([5, "say_time"])
|
||||||
|
|
||||||
|
|
||||||
def say_time():
|
def say_time():
|
||||||
#NOTE: you must add a real channel ID for this to work
|
# NOTE: you must add a real channel ID for this to work
|
||||||
outputs.append(["D12345678", time.time()])
|
outputs.append(["D12345678", time.time()])
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import time
|
|
||||||
crontable = []
|
crontable = []
|
||||||
outputs = []
|
outputs = []
|
||||||
|
|
||||||
|
|
||||||
def process_message(data):
|
def process_message(data):
|
||||||
if data['channel'].startswith("D"):
|
if data['channel'].startswith("D"):
|
||||||
outputs.append([data['channel'], "from repeat1 \"{}\" in channel {}".format(data['text'], data['channel']) ])
|
outputs.append([data['channel'], "from repeat1 \"{}\" in channel {}".format(
|
||||||
|
data['text'], data['channel'])]
|
||||||
|
)
|
||||||
|
|
|
@ -6,19 +6,21 @@ crontabs = []
|
||||||
|
|
||||||
tasks = {}
|
tasks = {}
|
||||||
|
|
||||||
FILE="plugins/todo.data"
|
|
||||||
|
FILE = "plugins/todo.data"
|
||||||
if os.path.isfile(FILE):
|
if os.path.isfile(FILE):
|
||||||
tasks = pickle.load(open(FILE, 'rb'))
|
tasks = pickle.load(open(FILE, 'rb'))
|
||||||
|
|
||||||
|
|
||||||
def process_message(data):
|
def process_message(data):
|
||||||
global tasks
|
global tasks
|
||||||
channel = data["channel"]
|
channel = data["channel"]
|
||||||
text = data["text"]
|
text = data["text"]
|
||||||
#only accept tasks on DM channels
|
# only accept tasks on DM channels
|
||||||
if channel.startswith("D"):
|
if channel.startswith("D"):
|
||||||
if channel not in tasks.keys():
|
if channel not in tasks.keys():
|
||||||
tasks[channel] = []
|
tasks[channel] = []
|
||||||
#do command stuff
|
# do command stuff
|
||||||
if text.startswith("todo"):
|
if text.startswith("todo"):
|
||||||
tasks[channel].append(text[5:])
|
tasks[channel].append(text[5:])
|
||||||
outputs.append([channel, "added"])
|
outputs.append([channel, "added"])
|
||||||
|
@ -36,4 +38,4 @@ def process_message(data):
|
||||||
tasks[channel].pop(num)
|
tasks[channel].pop(num)
|
||||||
if text == "show":
|
if text == "show":
|
||||||
print tasks
|
print tasks
|
||||||
pickle.dump(tasks, open(FILE,"wb"))
|
pickle.dump(tasks, open(FILE, "wb"))
|
||||||
|
|
28
rtmbot.py
28
rtmbot.py
|
@ -1,18 +1,17 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
sys.dont_write_bytecode = True
|
|
||||||
|
|
||||||
import glob
|
import glob
|
||||||
import yaml
|
import yaml
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
from slackclient import SlackClient
|
from slackclient import SlackClient
|
||||||
|
|
||||||
|
sys.dont_write_bytecode = True
|
||||||
|
|
||||||
|
|
||||||
def dbg(debug_string):
|
def dbg(debug_string):
|
||||||
if debug:
|
if debug:
|
||||||
|
@ -66,14 +65,14 @@ class RtmBot(object):
|
||||||
if limiter:
|
if limiter:
|
||||||
time.sleep(.1)
|
time.sleep(.1)
|
||||||
limiter = False
|
limiter = False
|
||||||
message = output[1].encode('ascii','ignore')
|
message = output[1].encode('ascii', 'ignore')
|
||||||
channel.send_message("{}".format(message))
|
channel.send_message("{}".format(message))
|
||||||
limiter = True # TODO: check goal: no sleep for 1st channel, sleep of all after ?
|
limiter = True
|
||||||
|
# TODO: check goal: no sleep for 1st channel, sleep of all after ?
|
||||||
# TODO: find out how to safely encode stuff if needed :(
|
# TODO: find out how to safely encode stuff if needed :(
|
||||||
# message = output[1].encode('utf-8','ignore')
|
# message = output[1].encode('utf-8','ignore')
|
||||||
channel.send_message(output[1]) # message
|
channel.send_message(output[1]) # message
|
||||||
|
|
||||||
|
|
||||||
def crons(self):
|
def crons(self):
|
||||||
for plugin in self.bot_plugins:
|
for plugin in self.bot_plugins:
|
||||||
plugin.do_jobs()
|
plugin.do_jobs()
|
||||||
|
@ -82,7 +81,8 @@ class RtmBot(object):
|
||||||
for plugin in glob.glob(directory + '/plugins/*'):
|
for plugin in glob.glob(directory + '/plugins/*'):
|
||||||
sys.path.insert(0, plugin)
|
sys.path.insert(0, plugin)
|
||||||
sys.path.insert(0, directory + '/plugins/')
|
sys.path.insert(0, directory + '/plugins/')
|
||||||
for plugin in glob.glob(directory + '/plugins/*.py') + glob.glob(directory + '/plugins/*/*.py'):
|
for plugin in glob.glob(directory + '/plugins/*.py') + \
|
||||||
|
glob.glob(directory + '/plugins/*/*.py'):
|
||||||
logging.info(plugin)
|
logging.info(plugin)
|
||||||
name = plugin.split('/')[-1][:-3]
|
name = plugin.split('/')[-1][:-3]
|
||||||
# try:
|
# try:
|
||||||
|
@ -90,10 +90,12 @@ class RtmBot(object):
|
||||||
# except:
|
# except:
|
||||||
# print "error loading plugin %s" % name
|
# print "error loading plugin %s" % name
|
||||||
|
|
||||||
|
|
||||||
class Plugin(object):
|
class Plugin(object):
|
||||||
|
|
||||||
def __init__(self, name, plugin_config=None):
|
def __init__(self, name, plugin_config=None):
|
||||||
if plugin_config is None:
|
if plugin_config is None:
|
||||||
plugin_config = {} #TODO: is this necessary?
|
plugin_config = {} # TODO: is this necessary?
|
||||||
self.name = name
|
self.name = name
|
||||||
self.jobs = []
|
self.jobs = []
|
||||||
self.module = __import__(name)
|
self.module = __import__(name)
|
||||||
|
@ -179,7 +181,11 @@ class UnknownChannel(Exception):
|
||||||
|
|
||||||
def main_loop():
|
def main_loop():
|
||||||
if "LOGFILE" in config:
|
if "LOGFILE" in config:
|
||||||
logging.basicConfig(filename=config["LOGFILE"], level=logging.INFO, format='%(asctime)s %(message)s')
|
logging.basicConfig(
|
||||||
|
filename=config["LOGFILE"],
|
||||||
|
level=logging.INFO,
|
||||||
|
format='%(asctime)s %(message)s'
|
||||||
|
)
|
||||||
logging.info(directory)
|
logging.info(directory)
|
||||||
try:
|
try:
|
||||||
bot.start()
|
bot.start()
|
||||||
|
@ -215,7 +221,7 @@ if __name__ == "__main__":
|
||||||
files_currently_downloading = []
|
files_currently_downloading = []
|
||||||
job_hash = {}
|
job_hash = {}
|
||||||
|
|
||||||
if config.has_key("DAEMON"):
|
if 'DAEMON' in config:
|
||||||
if config["DAEMON"]:
|
if config["DAEMON"]:
|
||||||
import daemon
|
import daemon
|
||||||
|
|
||||||
|
|
2
tox.ini
2
tox.ini
|
@ -20,4 +20,4 @@ basepython =
|
||||||
[testenv:flake8]
|
[testenv:flake8]
|
||||||
basepython=python
|
basepython=python
|
||||||
deps=flake8
|
deps=flake8
|
||||||
commands=flake8 {toxinidir}/rtmbot.py {toxinidir}/example-plugins
|
commands=flake8 {toxinidir}/rtmbot.py {toxinidir}/doc/example-plugins
|
Loading…
Add table
Add a link
Reference in a new issue