Skip to content

Instantly share code, notes, and snippets.

@sash13
Last active May 18, 2018 21:26
Show Gist options
  • Save sash13/24a04cc8a270ceae7e60a355bb8b1367 to your computer and use it in GitHub Desktop.
Save sash13/24a04cc8a270ceae7e60a355bb8b1367 to your computer and use it in GitHub Desktop.
Matrix admin api shutdown_room realization
import urllib2
import json
from builtins import input
# Settings here
HOST = 'https://localhost'
USER = 'admin'
PASS = 'pass'
###############
LOGIN_URL = '{}/_matrix/client/r0/login'.format(HOST)
SHUTDOWN_URL = '{}/_matrix/client/r0/admin/shutdown_room/{}?access_token={}'
LOGIN_DATA = {
'type':'m.login.password',
'user':USER,
'password':PASS
}
SHUTDOWN_DATA = {
'new_room_user_id':''
}
def f(url, params):
req = urllib2.Request(url)
req.add_header('Content-Type', 'application/json')
res = urllib2.urlopen(req, json.dumps(params))
return json.loads(res.read())
# Get Room
room = input('Shutdown room: ')
# Login
login_res = f(LOGIN_URL, LOGIN_DATA)
print(login_res)
# Shutdown room
SHUTDOWN_DATA['new_room_user_id'] = login_res['user_id']
try:
shutdown_res = f(SHUTDOWN_URL.format(HOST, room, login_res['access_token']),
SHUTDOWN_DATA)
print(shutdown_res)
if 'new_room_id' in shutdown_res:
print('Room shutdowned')
else:
print('Something wrong. Read ^')
except urllib2.HTTPError as e:
print(e)
print('Probably you already shutdowned this room')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment