Last active
May 18, 2018 21:26
-
-
Save sash13/24a04cc8a270ceae7e60a355bb8b1367 to your computer and use it in GitHub Desktop.
Matrix admin api shutdown_room realization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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