def count(message): """Report on the current connections count. Slack has a limit on the number of concurrent Bot connections. Max: 17 Reference: https://github.com/slackapi/node-slack-sdk/issues/166 """ if (os.environ['TARGET_DEVICE'] != 'all' and os.environ['TARGET_DEVICE'] != device_name): return post = slackmq(os.environ['API_TOKEN'], message.body['channel'], message.body['ts']) if post.ack(): check = chatops.Chatops('https://slack.com/api/users.getPresence') result = json.loads(check.getpresence()) connection_count = result['connection_count'] message.send('{}I have {} connections to Slack.'.format( debug, connection_count)) post.unack()
import re import requests from slackbot.bot import listen_to from slacker import Slacker from . import settings import sys import os from slackmq import slackmq import local_settings import chatops sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) device_name = os.environ['DEVICE_NAME'] chat = chatops.Chatops(settings.servers.homeops.bot_webhook) if (settings.plugins.solariot.enabled): slack = Slacker(local_settings.API_TOKEN) def download_image(url, fpath): if (os.environ['TARGET_DEVICE'] != 'all' and os.environ['TARGET_DEVICE'] != device_name): return r = requests.get(url, stream=True) with open(fpath, 'wb') as f: for chunk in r.iter_content(chunk_size=1024 * 64): if chunk: # filter out keep-alive new chunks f.write(chunk) f.flush() return fpath
import os import sys import chatops from slackbot.bot import listen_to from . import settings from slackmq import slackmq sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) device_name = os.environ['DEVICE_NAME'] chat = chatops.Chatops(settings.servers.devops.bot_webhook) @listen_to('^screenplay (.*)') def screenplay(message, filename): """Parse a screenplay to act out """ post = slackmq(os.environ['API_TOKEN'], message.body['channel'], message.body['ts']) if post.ack(): chat.screenplay(filename + '.txt') post.unack()
import re from slackbot.bot import listen_to from . import settings from arlo import Arlo from time import sleep import os import sys import chatops from slackmq import slackmq sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) device_name = os.environ['DEVICE_NAME'] chat = chatops.Chatops(settings.servers.arlo.bot_webhook) def login(USERNAME, PASSWORD): global arlo arlo = Arlo(USERNAME, PASSWORD) global basestations basestations = arlo.GetDevices('basestation') def callback(arlo, event): for camera in arlo.GetDevices('camera'): if camera['deviceId'] in event['resource']: cameraName = camera['deviceName'] if eval(os.environ['DEBUG']): debug = "[{}] ".format(device_name) else:
import tarfile from time import sleep, localtime, time import zipfile from . import settings import pip from pip.req import parse_requirements import pkg_resources from pkg_resources import DistributionNotFound, VersionConflict import yaml sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) base_dir = os.environ['BASE_DIR'] onlaunch = os.environ['ONLAUNCH'] nextlaunch = os.environ['NEXTLAUNCH'] device_name = os.environ['DEVICE_NAME'] chat = chatops.Chatops(settings.servers.devops.bot_webhook) topic = chatops.Chatops('https://slack.com/api/channels.history') if eval(os.environ['DEBUG']): debug = "[{}] ".format(device_name) else: debug = "" # Seconds to wait for avoiding the Slack rate_limit rate_limit = 3 def touch(fname, mode=0o666, dir_fd=None, **kwargs): flags = os.O_CREAT | os.O_APPEND with os.fdopen(os.open(fname, flags=flags, mode=mode, dir_fd=dir_fd)) as f: os.utime(f.fileno() if os.utime in os.supports_fd else fname, dir_fd=None if os.supports_fd