def do_unpin_filecomment(channel, filecomment, token=bottoken): url = ('https://slack.com/api/pins.remove?token=' + token + '&channel=' + channel + '&file_comment=' + filecomment) posted, retries = False, 0 while posted == False and retries < 1: result = create_request(url) posted, retries = result['ok'], retries + 1 if result['ok'] == False: do_send_botmessage( 'WARN:do_pin_filecomment, ' + str(result['error']), botroomid)
def do_kick_user(channel, user, token=admintoken): '''empties the channel fromt the user''' url = ('https://slack.com/api/channels.kick?token=' + token + '&channel=' + channel + '&user='******'ok'], retries + 1 if result['ok'] == False: do_send_botmessage( 'WARN:do_kick_user error, ' + str(result['error']), botroomid)
def do_set_purpose(channel, purpose, token=admintoken): purpose = urllib.parse.quote_plus(purpose) url = ('https://slack.com/api/channels.setPurpose?token=' + token + '&channel=' + channel + '&purpose=' + purpose) posted, retries = False, 0 while posted == False and retries < 2: result = create_request(url) posted, retries = result['ok'], retries + 1 if result['ok'] == False: do_send_botmessage( 'WARN:set_purpose error, ' + str(result['error']), botroomid)
def do_set_topic(channel, topic, token=admintoken, botroomid=botroomid): topic = urllib.parse.quote_plus(topic) url = ('https://slack.com/api/channels.setTopic?token=' + token + '&channel=' + channel + '&topic=' + topic) posted, retries = False, 0 while posted == False and retries < 2: result = create_request(url) posted, retries = result['ok'], retries + 1 if result['ok'] == False: do_send_botmessage('WARN:set_topic error, ' + str(result['error']), botroomid)
def delete_file(fileid, token=admintoken): 'deletes a specified file posted' url = ('https://slack.com/api/files.delete?token=' + token + '&file=' + fileid) posted, retries = False, 0 while posted == False and retries < 1: result = create_request(url) posted, retries = result['ok'], retries + 1 if result['ok'] == False: do_send_botmessage( 'WARN:do_delete_file error, ' + str(result['error']), botroomid)
def delete_text(channel, ts, token=admintoken): url = ('https://slack.com/api/chat.delete?token=' + token + '&channel=' + channel + '&ts=' + ts) '''deletes a message posted taking as input the channel and the timestamp''' posted, retries = False, 0 while posted == False and retries < 1: result = create_request(url) posted, retries = result['ok'], retries + 1 if result['ok'] == False: do_send_botmessage( 'WARN:do_delete_chat error, ' + str(result['error']), botroomid)
def do_send_botephemeral(message, room, user, token=bottoken): '''sends an ephemeral message as the bot user to the user in the room''' text = urllib.parse.quote_plus(message) url = ('https://slack.com/api/chat.postEphemeral?token=' + token + '&channel=' + room + '&text=' + text + '&user='******'ok'], retries + 1 if result['ok'] == False: do_send_botmessage( 'WARN:do_send_botmessage error, ' + str(result['error']), botroomid)
def do_unpin_message(channel, timestamp, token=bottoken): 'pins a file' url = ('https://slack.com/api/pins.remove?token=' + token + '&channel=' + channel + '×tamp=' + timestamp) posted, retries = False, 0 while posted == False and retries < 1: result = create_request(url) posted, retries = result['ok'], retries + 1 if posted == True: break if result['ok'] == False: do_send_botmessage('WARN:do_pin_message, ' + str(result['error']), botroomid)
def get_channels(token): '''gets the rooms list''' url = ('https://slack.com/api/channels.list?token=' + token + '&exclude_members=true') posted, retries = False, 0 x = 0 while x < 2: try: while posted == False and retries < 2: result = create_request(url) posted, retries = result['ok'], retries + 1 if result['ok'] == False: do_send_botmessage( 'WARN:get_channels error, ' + str(result['error']), botroomid) return result except: x = x + 1
def get_socket_url(token): url = (' https://slack.com/api/rtm.connect?token=' + token + '&batch_presence_aware=true&presence_sub=true') wssurl = create_request(url) return wssurl
def get_user_info(userid, token=bottoken): '''returns the username of the user. not very efficient, it makes a call''' url = ('https://slack.com/api/users.info?token=' + token + '&user='******'user']['name']