forked from SpiderOak/flow-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_join.py
More file actions
executable file
·48 lines (37 loc) · 1.39 KB
/
auto_join.py
File metadata and controls
executable file
·48 lines (37 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#! /usr/bin/env python
"""
auto_join.py
Bot to accept all Team join requests from a certain team.
It will also add the requestor to all channels within the Team.
usage:
./auto_join.py <teamId>
"""
import os
import sys
from flow import Flow
if len(sys.argv) < 2:
print("usage: %s <teamId>" % sys.argv[0])
sys.exit(os.EX_USAGE)
team_id = sys.argv[1]
flow = Flow()
# Log in with the first local device found in the system
flow.start_up()
# Callback to automatically add users to the team and all its channels
def accept(notif_type, notif_data):
for ojr in notif_data:
if ojr["orgId"] == team_id:
user_id = ojr["accountId"]
username = flow.get_peer_from_id(user_id)["username"]
# Add user to Team
flow.org_add_member(team_id, user_id, "m")
print("* user '%s' added to team." % username)
# Add user to all Channels within Team
for channel in flow.enumerate_channels(team_id):
flow.channel_add_member(team_id, channel["id"], user_id, "m")
print(" - also added to channel '%s'." % channel["name"])
# You can use 'register_callback' or just add the '@flow.org_join_request'
# decorator to 'accept'
flow.register_callback(Flow.ORG_JOIN_REQUEST_NOTIFICATION, accept)
# Main loop
print("Listening for incoming team join requests... (press Ctrl-C to stop)")
flow.process_notifications()