108 lines
3.4 KiB
C++
108 lines
3.4 KiB
C++
/**
|
|
This file is a part of rexy's matrix bot
|
|
Copyright (C) 2019 rexy712
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "fat_strings.hpp"
|
|
#include "matrix.hpp"
|
|
#include "raii/static_string.hpp"
|
|
#include "raii/util.hpp"
|
|
|
|
namespace matrix::detail{
|
|
|
|
raii::string _image_body(const image_info& image){
|
|
raii::string url = raii::json_escape(image.fileurl);
|
|
const raii::string_base* thumburl;
|
|
if(image.thumburl)
|
|
thumburl = &image.thumburl;
|
|
else
|
|
thumburl = &url;
|
|
|
|
//compiler intensive
|
|
return raii::string(
|
|
"{"
|
|
"\"body\":\"" + raii::json_escape(image.filename) + "\","
|
|
"\"info\":{"
|
|
"\"h\":" + raii::itostr(image.height) + ","
|
|
"\"mimetype\":\"" + image.mimetype + "\","
|
|
"\"size\":" + raii::itostr(image.filesize) + ","
|
|
"\"thumnail_info\":{"
|
|
"\"h\":" + raii::itostr(image.thumb_height) + ","
|
|
"\"mimetype\":\"" + image.mimetype + "\","
|
|
"\"size\":" + raii::itostr(image.thumbsize) + ","
|
|
"\"w\":" + raii::itostr(image.thumb_width) +
|
|
"},"
|
|
"\"thumbnail_url\":\"" + (*thumburl) + "\","
|
|
"\"w\":" + raii::itostr(image.width) +
|
|
"},"
|
|
"\"msgtype\":\"m.image\","
|
|
"\"url\":\"" + url + "\""
|
|
"}");
|
|
}
|
|
|
|
raii::string _video_body(const video_info& video){
|
|
return raii::string(
|
|
"{"
|
|
"\"body\":\"" + raii::json_escape(video.filename) + "\","
|
|
"\"info\":{"
|
|
"\"h\":" + raii::itostr(video.height) + ","
|
|
"\"mimetype\":\"" + video.mimetype + "\","
|
|
"\"size\":" + raii::itostr(video.filesize) + ","
|
|
"\"thumnail_info\":{"
|
|
"\"h\":" + raii::itostr(video.thumb_height) + ","
|
|
"\"mimetype\":\"image/jpeg\","
|
|
"\"size\":" + raii::itostr(video.thumbsize) + ","
|
|
"\"w\":" + raii::itostr(video.thumb_width) +
|
|
"},"
|
|
"\"thumbnail_url\":\"" + video.thumburl + "\","
|
|
"\"w\":" + raii::itostr(video.width) +
|
|
"},"
|
|
"\"msgtype\":\"m.video\","
|
|
"\"url\":\"" + raii::json_escape(video.fileurl) + "\""
|
|
"}");
|
|
}
|
|
raii::string _file_body(const file_info& file){
|
|
return raii::string(
|
|
"{"
|
|
"\"body\":\"" + raii::json_escape(file.filename) + "\","
|
|
"\"info\":{"
|
|
"\"size\":" + raii::itostr(file.filesize) +
|
|
"},"
|
|
"\"msgtype\":\"m.file\","
|
|
"\"body\":\"" + file.filename + "\","
|
|
"\"url\":\"" + raii::json_escape(file.fileurl) + "\""
|
|
"}");
|
|
}
|
|
|
|
raii::string _audio_body(const audio_info& audio){
|
|
return raii::string(
|
|
"{"
|
|
"\"body\":\"" + raii::json_escape(audio.filename) + "\","
|
|
"\"info\":{"
|
|
"\"mimetype\":\"" + raii::json_escape(audio.mimetype) + "\","
|
|
"\"size\":" + raii::itostr(audio.filesize) +
|
|
"},"
|
|
"\"msgtype\":\"m.audio\","
|
|
"\"body\":\"" + audio.filename + "\","
|
|
"\"url\":\"" + raii::json_escape(audio.fileurl) + "\""
|
|
"}");
|
|
}
|
|
|
|
raii::string _message_body(const raii::string_base& msg){
|
|
return raii::string("{\"body\":\""_ss + raii::json_escape(msg) + "\",\"msgtype\":\"m.text\"}"_ss);
|
|
}
|
|
}
|