Implement bot owners
This commit is contained in:
parent
30b5c6d3c6
commit
e20654668b
@ -38,6 +38,11 @@ try:
|
||||
MATRIX_HOST_EXT = CONFIG['hosts']['external']
|
||||
MATRIX_HOST_BARE = CONFIG['hosts']['bare']
|
||||
|
||||
try:
|
||||
MATRIX_BOT_OWNERS = CONFIG['bot-owners']
|
||||
except KeyError:
|
||||
MATRIX_BOT_OWNERS = {}
|
||||
|
||||
MATRIX_PREFIX = MATRIX_HOST + '_matrix/client/r0/'
|
||||
MATRIX_MEDIA_PREFIX = MATRIX_HOST + '_matrix/media/r0/'
|
||||
|
||||
@ -205,37 +210,43 @@ async def matrix_transaction(request):
|
||||
|
||||
if event['type'] == 'm.room.message':
|
||||
user_id = event['user_id']
|
||||
if matrix_is_telegram(user_id):
|
||||
continue
|
||||
|
||||
|
||||
sender = db.session.query(db.MatrixUser)\
|
||||
.filter_by(matrix_id=user_id).first()
|
||||
|
||||
if not sender:
|
||||
response = await matrix_get('client', 'profile/{}/displayname'
|
||||
.format(user_id), None)
|
||||
try:
|
||||
displayname = response['displayname']
|
||||
except KeyError:
|
||||
displayname = get_username(user_id)
|
||||
sender = db.MatrixUser(user_id, displayname)
|
||||
db.session.add(sender)
|
||||
if user_id in MATRIX_BOT_OWNERS:
|
||||
displayname = ''
|
||||
else:
|
||||
displayname = sender.name or get_username(user_id)
|
||||
if matrix_is_telegram(user_id):
|
||||
continue
|
||||
|
||||
|
||||
sender = db.session.query(db.MatrixUser)\
|
||||
.filter_by(matrix_id=user_id).first()
|
||||
|
||||
if not sender:
|
||||
response = await matrix_get('client', 'profile/{}/displayname'
|
||||
.format(user_id), None)
|
||||
try:
|
||||
displayname = response['displayname']
|
||||
except KeyError:
|
||||
displayname = get_username(user_id)
|
||||
sender = db.MatrixUser(user_id, displayname)
|
||||
db.session.add(sender)
|
||||
else:
|
||||
displayname = sender.name or get_username(user_id)
|
||||
content = event['content']
|
||||
|
||||
if 'msgtype' not in content:
|
||||
continue
|
||||
|
||||
if content['msgtype'] == 'm.text':
|
||||
msg, mode = format_matrix_msg('<{}> {}', displayname, content)
|
||||
prefix = '<' + displayname + '> ' if displayname != ''
|
||||
msg, mode = format_matrix_msg('{}{}', prefix, content)
|
||||
response = await group.send_text(msg, parse_mode=mode)
|
||||
elif content['msgtype'] == 'm.notice':
|
||||
msg, mode = format_matrix_msg('[{}] {}', displayname, content)
|
||||
prefix = '[' + displayname + '] ' if displayname != ''
|
||||
msg, mode = format_matrix_msg('{}{}', prefix, content)
|
||||
response = await group.send_text(msg, parse_mode=mode)
|
||||
elif content['msgtype'] == 'm.emote':
|
||||
msg, mode = format_matrix_msg('* {} {}', displayname, content)
|
||||
prefix = '* ' + displayname + ' ' if displayname != ''
|
||||
msg, mode = format_matrix_msg('{}{}', prefix, content)
|
||||
response = await group.send_text(msg, parse_mode=mode)
|
||||
elif content['msgtype'] == 'm.image':
|
||||
try:
|
||||
@ -255,7 +266,8 @@ async def matrix_transaction(request):
|
||||
.format(url.netloc, quote(url.path))
|
||||
url_str = await shorten_url(url_str)
|
||||
|
||||
caption = '<{}> {} ({})'.format(displayname,
|
||||
prefix = '<' + displayname + '> ' if displayname != ''
|
||||
caption = '{}{} ({})'.format(prefix,
|
||||
content['body'], url_str)
|
||||
response = await group.send_photo(img_file, caption=caption)
|
||||
except:
|
||||
|
Loading…
Reference in New Issue
Block a user