mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 16:45:10 +00:00
77 lines
1.8 KiB
C
77 lines
1.8 KiB
C
#include <Routes.h>
|
|
|
|
#include <Cytoplasm/Memory.h>
|
|
#include <Cytoplasm/Str.h>
|
|
|
|
#include <Matrix.h>
|
|
#include <Bot.h>
|
|
#include <AS.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
CommandHead(CmdPlumb, cmd, argp)
|
|
{
|
|
ParseeCmdArg *args = argp;
|
|
ParseeData *data = args->data;
|
|
HashMap *event = args->event;
|
|
char *muc = NULL, *room = NULL, *chat_id = NULL;
|
|
char *room_id = NULL;
|
|
MUCInfo info = { .exists = false };
|
|
|
|
BotInitialise();
|
|
|
|
BotRequired(muc);
|
|
BotRequired(room);
|
|
|
|
/* Check MUC viability */
|
|
if (ParseeManageBan(args->data, muc, NULL) ||
|
|
ParseeIsMUCWhitelisted(args->data, muc))
|
|
{
|
|
ReplySprintf("MUC '%s' is not allowed on this bridge.", muc);
|
|
goto end;
|
|
}
|
|
if (!XMPPQueryMUC(args->data->jabber, muc, &info))
|
|
{
|
|
ReplySprintf("MUC '%s' does not exist.", muc);
|
|
goto end;
|
|
}
|
|
if ((chat_id = ParseeGetFromMUCID(args->data, muc)))
|
|
{
|
|
ReplySprintf("MUC '%s' is already mapped to %s.", muc, chat_id);
|
|
Free(chat_id);
|
|
chat_id = NULL;
|
|
goto end;
|
|
}
|
|
|
|
|
|
/* Check room viability */
|
|
room_id = ASJoin(args->data->config, room, NULL);
|
|
if (!room_id)
|
|
{
|
|
ReplySprintf("Room '%s' does not exist.", room);
|
|
goto end;
|
|
}
|
|
if ((chat_id = ParseeGetFromRoomID(args->data, room_id)))
|
|
{
|
|
Free(chat_id);
|
|
chat_id = NULL;
|
|
ReplySprintf("Room '%s' is already mapped.", room);
|
|
goto end;
|
|
}
|
|
|
|
chat_id = ParseePushMUC(args->data, room_id, muc);
|
|
if (chat_id)
|
|
{
|
|
char *rev = StrConcat(2, muc, "/parsee");
|
|
XMPPJoinMUC(args->data->jabber, "parsee", rev, false);
|
|
|
|
Free(rev);
|
|
}
|
|
|
|
ReplySprintf("Plumbed '%s'", muc);
|
|
end:
|
|
BotDestroy();
|
|
Free(chat_id);
|
|
Free(room_id);
|
|
XMPPFreeMUCInfo(info);
|
|
}
|