Dummy messaging, channel utility useful vars, nagging
This commit is contained in:
parent
fcabaf420a
commit
bc25ffcb1e
|
|
@ -1,13 +1,15 @@
|
|||
|
||||
import shelve
|
||||
import slack_util
|
||||
|
||||
DB_NAME = "channel_priveleges"
|
||||
|
||||
# Useful channels
|
||||
GENERAL = "C0CFHPNEM"
|
||||
COMMAND_CENTER_ID = "GCR631LQ1"
|
||||
SLAVES_TO_THE_MACHINE_ID = "C9WUQBYNP"
|
||||
BOTZONE = "C3BF2MFKM"
|
||||
|
||||
# Define our patterns
|
||||
channel_check_pattern = r"channel id\s*(.*)"
|
||||
# channel_check_pattern = r"channel id <#(.*)>"
|
||||
# identify_other_pattern = r"<@(.*)>\s+has scroll\s+(.*)"
|
||||
|
||||
|
||||
def channel_check_callback(slack, msg, match):
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
import time
|
||||
import channel_util
|
||||
|
||||
msg = {
|
||||
"type": "message",
|
||||
"channel": channel_util.COMMAND_CENTER_ID,
|
||||
"user": "U0Q1PKL92",
|
||||
"text": "nagjobs tuesday",
|
||||
"ts": "1355517523.000005"
|
||||
}
|
||||
|
||||
|
||||
class FakeClient(object):
|
||||
def rtm_send_message(self, channel=None, message="", thread=None, to_channel=None):
|
||||
print("Sent \"{}\" to channel {}".format(message, channel))
|
||||
|
||||
def rtm_connect(self, with_team_state=None, auto_reconnect=None):
|
||||
return True
|
||||
|
||||
def rtm_read(self):
|
||||
time.sleep(4)
|
||||
return [msg]
|
||||
|
|
@ -1,27 +1,55 @@
|
|||
import identifier
|
||||
import scroll_util
|
||||
import slack_util
|
||||
import google_api
|
||||
import channel_util
|
||||
|
||||
nag_pattern = r"nag (.*)"
|
||||
nag_pattern = r"nagjobs (tuesday|thursday)"
|
||||
|
||||
|
||||
SHEET_ID = "1lPj9GjB00BuIq9GelOWh5GmiGsheLlowPnHLnWBvMOM"
|
||||
eight_jobs = "House Jobs!A2:C25" # Format: Job Day Bro
|
||||
fiftythree_jobs = "House Jobs!E2:G6"
|
||||
|
||||
# For matching purposes
|
||||
tuesday = "tuesday"
|
||||
thursday = "thursday"
|
||||
|
||||
|
||||
class Job(object):
|
||||
def __init__(self, row):
|
||||
self.job_name, self.day, self.brother_name = row
|
||||
self.day = self.day.lower().strip()
|
||||
|
||||
def lookup_brother_slack_id(self):
|
||||
brother_dict = scroll_util.find_by_name(self.brother_name)
|
||||
return identifier.lookup_brother_userids(brother_dict)
|
||||
|
||||
|
||||
def nag_callback(slack, msg, match):
|
||||
# Get who we want to nag
|
||||
name = match.group(1)
|
||||
# Only allow in
|
||||
|
||||
# Find them using scroll shit
|
||||
brother = scroll_util.find_by_name(name)
|
||||
# Get the day
|
||||
day = match.group(1).lower()
|
||||
|
||||
# Get the associated user ids
|
||||
ids = identifier.lookup_brother_userids(brother)
|
||||
# Get the spreadsheet section
|
||||
jobs = google_api.get_sheet_range(SHEET_ID, eight_jobs)
|
||||
jobs = jobs + google_api.get_sheet_range(SHEET_ID, fiftythree_jobs)
|
||||
jobs = [Job(r) for r in jobs]
|
||||
|
||||
# Nag them each
|
||||
# Filter to day
|
||||
jobs = [j for j in jobs if j.day == day]
|
||||
|
||||
# Nag each
|
||||
response = "Do your jobs! They are as follows:\n"
|
||||
for job in jobs:
|
||||
response += "{} -- ".format(job.job_name)
|
||||
ids = job.lookup_brother_slack_id()
|
||||
if ids:
|
||||
result = "Hey"
|
||||
for user_id in ids:
|
||||
result += " <@{}>".format(user_id)
|
||||
result += "!"
|
||||
for id in ids:
|
||||
response += "<@{}> ".format(id)
|
||||
else:
|
||||
result = "Nobody has identified themselves as {} ({})... Sad!".format(brother["name"], brother["scroll"])
|
||||
response += "{} (scroll not found. Please register for @ notifications!)".format(job.brother_name)
|
||||
response += "\n"
|
||||
|
||||
slack_util.reply(slack, msg, result, in_thread=False)
|
||||
slack_util.reply(slack, msg, response, in_thread=False, to_channel=channel_util.BOTZONE)
|
||||
|
|
|
|||
13
main.py
13
main.py
|
|
@ -9,6 +9,7 @@ import identifier
|
|||
import re
|
||||
import channel_util
|
||||
import job_nagger
|
||||
from dummy import FakeClient
|
||||
|
||||
# Read api token from file
|
||||
api_file = open("apitoken.txt", 'r')
|
||||
|
|
@ -39,7 +40,7 @@ def main():
|
|||
# Added channel utility
|
||||
wrapper.add_hook(channel_util.channel_check_pattern, channel_util.channel_check_callback)
|
||||
|
||||
# Add test nagging functionality
|
||||
# Add nagging functionality
|
||||
wrapper.add_hook(job_nagger.nag_pattern, job_nagger.nag_callback)
|
||||
|
||||
# Add kill switch
|
||||
|
|
@ -53,9 +54,15 @@ def die(*args):
|
|||
exit()
|
||||
|
||||
|
||||
DEBUG_MODE = False
|
||||
|
||||
|
||||
class ClientWrapper(object):
|
||||
def __init__(self):
|
||||
# Init slack
|
||||
if DEBUG_MODE:
|
||||
self._slack = FakeClient()
|
||||
else:
|
||||
self._slack = SlackClient(SLACK_API)
|
||||
|
||||
# Hooks go regex -> callback on (slack, msg, match)
|
||||
|
|
@ -73,6 +80,10 @@ class ClientWrapper(object):
|
|||
if msg.get("subtype") is not None:
|
||||
continue
|
||||
|
||||
# Never deal with general
|
||||
if msg.get("channel") == channel_util.GENERAL:
|
||||
continue
|
||||
|
||||
# Handle Message
|
||||
text = msg['text'].strip()
|
||||
success = False
|
||||
|
|
|
|||
|
|
@ -5,16 +5,19 @@ Slack helpers. Separated for compartmentalization
|
|||
"""
|
||||
|
||||
|
||||
def reply(slack, msg, text, in_thread=True):
|
||||
def reply(slack, msg, text, in_thread=True, to_channel=None):
|
||||
"""
|
||||
Sends message with "text" as its content to the channel that message came from
|
||||
"""
|
||||
channel = msg['channel']
|
||||
thread_id = msg['ts']
|
||||
# If no channel specified, just do same as msg
|
||||
if to_channel is None:
|
||||
to_channel = msg['channel']
|
||||
|
||||
# Send in a thread by default
|
||||
if in_thread:
|
||||
slack.rtm_send_message(channel=channel, message=text, thread=thread_id)
|
||||
slack.rtm_send_message(channel=to_channel, message=text, thread=msg['ts'])
|
||||
else:
|
||||
slack.rtm_send_message(channel=channel, message=text)
|
||||
slack.rtm_send_message(channel=to_channel, message=text)
|
||||
|
||||
|
||||
def message_stream(slack):
|
||||
|
|
|
|||
Loading…
Reference in New Issue