mirror of
https://github.com/CHN-beta/nixos.git
synced 2026-01-11 16:49:22 +08:00
packages.misskey-forwarder: fix
This commit is contained in:
1
packages/misskey-forwarder/.gitignore
vendored
Normal file
1
packages/misskey-forwarder/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
config.yaml
|
||||
@@ -15,7 +15,9 @@ find_package(httplib REQUIRED)
|
||||
add_executable(misskey-forwarder src/main.cpp)
|
||||
target_link_libraries(misskey-forwarder PRIVATE biu::biu httplib::httplib)
|
||||
target_compile_features(misskey-forwarder PRIVATE cxx_std_23)
|
||||
target_compile_definitions(misskey-forwarder PRIVATE FORWARDER_CONFIG_FILE="${FORWARDER_CONFIG_FILE}")
|
||||
if(DEFINED FORWARDER_CONFIG_FILE)
|
||||
target_compile_definitions(misskey-forwarder PRIVATE FORWARDER_CONFIG_FILE="${FORWARDER_CONFIG_FILE}")
|
||||
endif()
|
||||
install(TARGETS misskey-forwarder RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
||||
get_property(ImportedTargets DIRECTORY "${CMAKE_SOURCE_DIR}" PROPERTY IMPORTED_TARGETS)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# include <httplib.h>
|
||||
# include <tgbot/tgbot.h>
|
||||
# ifndef FORWARDER_CONFIG_FILE
|
||||
# define FORWARDER_CONFIG_FILE "./config.yml"
|
||||
# define FORWARDER_CONFIG_FILE "./config.yaml"
|
||||
# endif
|
||||
|
||||
int main()
|
||||
@@ -16,8 +16,7 @@ int main()
|
||||
std::string TelegramBotToken;
|
||||
std::string TelegramChatId;
|
||||
int ServerPort;
|
||||
};
|
||||
auto config = YAML::LoadFile(FORWARDER_CONFIG_FILE).as<Config>();
|
||||
} config = YAML::LoadFile(FORWARDER_CONFIG_FILE).as<Config>();
|
||||
|
||||
biu::Logger::try_exec([&]
|
||||
{
|
||||
@@ -33,25 +32,38 @@ int main()
|
||||
struct Content
|
||||
{
|
||||
std::string type, server;
|
||||
struct { struct
|
||||
struct
|
||||
{
|
||||
std::string text, visibility;
|
||||
struct Renote { std::string id; };
|
||||
std::optional<Renote> renote;
|
||||
} note; } body;
|
||||
struct Note
|
||||
{
|
||||
std::string text, visibility;
|
||||
std::optional<std::string> replyId;
|
||||
struct Renote { std::string id; };
|
||||
std::optional<Renote> renote;
|
||||
};
|
||||
std::optional<Note> note;
|
||||
} body;
|
||||
};
|
||||
auto content = YAML::Load(req.body).as<Content>();
|
||||
|
||||
if (content.type != "note" || content.body.note.visibility != "public") return;
|
||||
std::string text = content.body.note.text;
|
||||
if (content.body.note.renote)
|
||||
text += "\n🔁 Renote: {}/notes/{}"_f(content.server, content.body.note.renote->id);
|
||||
if
|
||||
(
|
||||
content.type != "note" // 只转发 note 的情况
|
||||
|| !content.body.note // 大概不会发生,但还是判断一下
|
||||
|| content.body.note->visibility != "public" // 只转发公开的 note
|
||||
|| content.body.note->replyId // 不转发回复
|
||||
) return;
|
||||
std::string text = content.body.note->text;
|
||||
if (content.body.note->renote)
|
||||
text += "\n🔁 Renote: {}/notes/{}"_f(content.server, content.body.note->renote->id);
|
||||
|
||||
TgBot::Bot bot(config.TelegramBotToken);
|
||||
bot.getApi().sendMessage(config.TelegramChatId, text);
|
||||
// bot.getApi().sendMessage(config.TelegramChatId, text);
|
||||
|
||||
res.status = 200;
|
||||
res.body = "OK";
|
||||
|
||||
log.debug(req.body);
|
||||
});
|
||||
});
|
||||
svr.listen("0.0.0.0", config.ServerPort);
|
||||
|
||||
Reference in New Issue
Block a user