Skip to content

Instantly share code, notes, and snippets.

@revmischa
Created September 22, 2016 17:24
Show Gist options
  • Save revmischa/cf94a5de06631e3d7b9144a571192e59 to your computer and use it in GitHub Desktop.
Save revmischa/cf94a5de06631e3d7b9144a571192e59 to your computer and use it in GitHub Desktop.
"""Mass invite users from one channel to another."""
from slacker import Slacker
from pprint import pprint
slack = Slacker('xxxxx')
me = slack.auth.test().body
me_id = me['user_id']
print("Authed as {}".format(me['user']))
channels = slack.channels.list().body['channels']
def mass_invite(group_src, chan_dst):
response = slack.groups.info(group_src['id'])
users = response.body['group']['members']
for u in users:
print("Inviting {} from {} to {}".format(u, group_src['name'], chan_dst['name']))
# slack.channels.invite(channel=chan_dst['id'], user=u['id'])
def mass_kick_group(group):
response = slack.groups.info(group['id'])
users = response.body['group']['members']
for u in users:
if u == me_id:
print("Skipping me")
continue
print("Booting {} from {}".format(u, group['name']))
# slack.groups.kick(channel=group['id'], user=u['id'])
def select_group():
response = slack.groups.list(exclude_archived=True)
groups = response.body['groups']
for i in range(len(groups)):
g = groups[i]
print("{}\t{}".format(i, g['name']))
i = int(raw_input('Select destination group:'))
return groups[i]
def select_channel():
response = slack.channels.list(exclude_archived=True)
channels = response.body['channels']
for i in range(len(channels)):
c = channels[i]
print("{}\t{}".format(i, c['name']))
i = int(raw_input('Select destination channel:'))
return channels[i]
group = select_group()
channel = select_channel()
mass_invite(group, channel)
mass_kick_group(group)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment