mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 10:45:11 +00:00
76 lines
1.7 KiB
C
76 lines
1.7 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>
|
|
|
|
static bool
|
|
Grab(ParseeData *data, Command *cmd, char **muc, char **chat_id, char **room)
|
|
{
|
|
if (HashMapGet(cmd->arguments, "muc"))
|
|
{
|
|
*muc = HashMapGet(cmd->arguments, "muc");
|
|
|
|
*chat_id = ParseeGetFromMUCID(data, *muc);
|
|
*room = ParseeGetRoomID(data, *chat_id);
|
|
if (!chat_id || !room)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
else if (HashMapGet(cmd->arguments, "room"))
|
|
{
|
|
*room = HashMapGet(cmd->arguments, "room");
|
|
|
|
*chat_id = ParseeGetFromRoomID(data, *room);
|
|
*muc = ParseeGetMUCID(data, *chat_id);
|
|
if (!chat_id || !muc)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
CommandHead(CmdUnlinkMUC, cmd, argp)
|
|
{
|
|
ParseeCmdArg *args = argp;
|
|
ParseeData *data = args->data;
|
|
HashMap *json, *event = args->event, *mucs;
|
|
char *muc = NULL, *chat_id = NULL, *room = NULL;
|
|
|
|
BotInitialise();
|
|
|
|
if (!Grab(data, cmd, &muc, &chat_id, &room))
|
|
{
|
|
ReplyBasic("`muc`|`room` REQUIRED");
|
|
goto end;
|
|
}
|
|
|
|
chat_id = ParseeGetFromMUCID(data, muc);
|
|
room = ParseeGetRoomID(data, chat_id);
|
|
if (!chat_id)
|
|
{
|
|
ReplySprintf("No internal mapping to '%s'.", muc);
|
|
goto end;
|
|
}
|
|
|
|
ParseeUnlinkRoom(data, chat_id);
|
|
|
|
/* TODO: Do it automatically, if *not plumbed* */
|
|
ReplySprintf("The MUC %s is now *unlinked*.", muc);
|
|
ReplySprintf("Please now remove the room %s and its aliases.",
|
|
room
|
|
);
|
|
end:
|
|
Free(chat_id);
|
|
Free(room);
|
|
BotDestroy();
|
|
}
|