Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Merge pull request #5 from UnitedIncome/slackbot_01
Browse files Browse the repository at this point in the history
Attacks
  • Loading branch information
JamesIves committed Oct 30, 2018
2 parents eb0dd1c + 76fb844 commit 0f5802a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Procfile
@@ -1,2 +1,2 @@
worker: python app.py start
web: gunicorn destroyer-server:app
web: gunicorn server:app
22 changes: 16 additions & 6 deletions app.py
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import time
from slackclient import SlackClient
import requests
from constants import *
from util import *

Expand All @@ -17,17 +18,22 @@ def handle_command(command, channel):
send_basic_message('no', channel)

if command.startswith(TOGGLE_ATTACK_COMMAND):
global_settings['attack'] = not global_settings['attack']
global_settings['destroy'] = not global_settings['destroy']

if global_settings['attack'] == True:
if global_settings['destroy'] == True:
send_basic_message('DESTROY', channel)

if global_settings['attack'] == False:
if global_settings['destroy'] == False:
send_basic_message('DEACTIVATE', channel)

def delete_message(timestamp, channel):
slack_client.api_call("chat.delete", channel=channel,
ts=timestamp, as_user=True)
options = {
'token': SLACK_BOT_ACCESS_TOKEN,
'channel': channel,
'ts': timestamp,
'as_user': True
}
requests.post('https://slack.com/api/chat.delete', params=options)

def send_basic_message(message, channel):
""" Sends a basic message with the Slack API """
Expand All @@ -42,6 +48,11 @@ def parse_slack_output(slack_rtm_output):
output_list = slack_rtm_output
if output_list and len(output_list) > 0:
for output in output_list:

if global_settings['destroy'] == True and output and 'subtype' in output.keys():
if output['subtype'] == 'slackbot_response':
delete_message(output['ts'], output['channel'])

if output and 'text' in output and AT_BOT in output['text']:
# return text after the @ mention, whitespace removed
return output['text'].split(AT_BOT)[1].strip(), \
Expand All @@ -50,7 +61,6 @@ def parse_slack_output(slack_rtm_output):

if __name__ == "__main__":
READ_WEBSOCKET_DELAY = 1

if slack_client.rtm_connect():
print('Launch successful, waiting for input...')

Expand Down
3 changes: 2 additions & 1 deletion constants.py
Expand Up @@ -2,8 +2,9 @@

BOT_ID = str(os.environ.get('BOT_ID'))
SLACK_BOT_TOKEN = str(os.environ.get('SLACK_BOT_TOKEN'))
SLACK_BOT_ACCESS_TOKEN = str(os.environ.get('SLACK_BOT_ACCESS_TOKEN'))
AT_BOT = "<@" + BOT_ID + ">"

# Commands
SLACKBOT_SILENCE_COMMAND = 'shh'
TOGGLE_ATTACK_COMMAND = 'attack'
TOGGLE_ATTACK_COMMAND = 'destroy'
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion util.py
@@ -1,4 +1,4 @@
# Stores the global settings for the bot
global_settings = {
'attack': False
'destroy': False,
}

0 comments on commit 0f5802a

Please sign in to comment.