Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix private channels issue #61

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions default.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"teamDomain": "yourDomainHere",
"channelName": "general",
"channelId": "channelIdHere",
"isPrivate": false,

"officeHours": {
"on": false,
Expand All @@ -26,34 +27,39 @@
{
"id": 0,
"name": "pushups",
"instruction": "",
"minReps": 15,
"maxReps": 20,
"units": "rep"
},
{
"id": 1,
"name": "planks",
"instruction": "",
"minReps": 40,
"maxReps": 60,
"units": "second"
},
{
"id": 2,
"name": "wall sit",
"instruction": "",
"minReps": 40,
"maxReps": 50,
"units": "second"
},
{
"id": 3,
"name": "chair dips",
"instruction": "",
"minReps": 15,
"maxReps": 30,
"units": "rep"
},
{
"id": 4,
"name": "calf raises",
"instruction": "",
"minReps": 20,
"maxReps": 30,
"units": "rep"
Expand Down
9 changes: 9 additions & 0 deletions fetchChannelId.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,12 @@
if channel["name"] == channelName:
print channel["id"]
break

#if it's private channel
response = requests.get("https://slack.com/api/groups.list", params=params)
channels = json.loads(response.text, encoding='utf-8')["groups"]

for channel in channels:
if channel["name"] == channelName:
print channel["id"]
break
16 changes: 13 additions & 3 deletions slackbotExercise.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def setConfiguration(self):

self.team_domain = settings["teamDomain"]
self.channel_name = settings["channelName"]
self.is_private = settings["isPrivate"]
self.min_countdown = settings["callouts"]["timeBetween"]["minTime"]
self.max_countdown = settings["callouts"]["timeBetween"]["maxTime"]
self.num_people_per_callout = settings["callouts"]["numPeople"]
Expand All @@ -78,6 +79,7 @@ def setConfiguration(self):
def selectUser(bot, exercise):
active_users = fetchActiveUsers(bot)

#print len(active_users)
# Add all active users not already in the user queue
# Shuffles to randomly add new active users
shuffle(active_users)
Expand Down Expand Up @@ -122,8 +124,12 @@ def selectUser(bot, exercise):
def fetchActiveUsers(bot):
# Check for new members
params = {"token": USER_TOKEN_STRING, "channel": bot.channel_id}
response = requests.get("https://slack.com/api/channels.info", params=params)
user_ids = json.loads(response.text, encoding='utf-8')["channel"]["members"]
if bot.is_private:
urlSegment = "group";
else:
urlSegment = "channel";
response = requests.get("https://slack.com/api/" + urlSegment + "s.info", params=params)
user_ids = json.loads(response.text, encoding='utf-8')[urlSegment]["members"]

active_users = []

Expand Down Expand Up @@ -192,7 +198,7 @@ def assignExercise(bot, exercise):
# Select number of reps
exercise_reps = random.randrange(exercise["minReps"], exercise["maxReps"]+1)

winner_announcement = str(exercise_reps) + " " + str(exercise["units"]) + " " + exercise["name"] + " RIGHT NOW "
winner_announcement = str(exercise_reps) + " " + str(exercise["units"]) + " " + exercise["name"] + " (" + exercise["instruction"] + ") RIGHT NOW "

# EVERYBODY
if random.random() < bot.group_callout_chance:
Expand All @@ -205,6 +211,10 @@ def assignExercise(bot, exercise):
logExercise(bot,"@channel",exercise["name"],exercise_reps,exercise["units"])

else:
amount_active_users = len(fetchActiveUsers(bot))
if bot.num_people_per_callout > amount_active_users:
bot.num_people_per_callout = amount_active_users

winners = [selectUser(bot, exercise) for i in range(bot.num_people_per_callout)]

for i in range(bot.num_people_per_callout):
Expand Down