mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 13:45:10 +00:00
I honestly don't know what to call it.
It's not a 0.2 release, btw.
This commit is contained in:
parent
e7ba1fa48d
commit
3ceae7b053
13 changed files with 179 additions and 85 deletions
|
|
@ -9,43 +9,60 @@
|
|||
|
||||
#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;
|
||||
DbRef *ref;
|
||||
char *muc = NULL, *chat_id = NULL, *room = NULL;
|
||||
|
||||
BotInitialise();
|
||||
|
||||
muc = HashMapGet(cmd->arguments, "muc");
|
||||
if (!muc)
|
||||
if (!Grab(data, cmd, &muc, &chat_id, &room))
|
||||
{
|
||||
ReplyBasic("`muc` field REQUIRED.");
|
||||
ReplyBasic("`muc`|`room` REQUIRED");
|
||||
goto end;
|
||||
}
|
||||
|
||||
ref = DbLock(data->db, 1, "chats");
|
||||
json = DbJson(ref);
|
||||
chat_id = StrDuplicate(GrabString(json, 2, "mucs", muc));
|
||||
chat_id = ParseeGetFromMUCID(data, muc);
|
||||
room = ParseeGetRoomID(data, chat_id);
|
||||
if (!chat_id)
|
||||
{
|
||||
ReplySprintf("No internal mapping to '%s'.", muc);
|
||||
goto end;
|
||||
}
|
||||
mucs = GrabObject(json, 1, "mucs");
|
||||
JsonValueFree(HashMapDelete(mucs, muc));
|
||||
DbUnlock(data->db, ref);
|
||||
|
||||
room = ParseeGetRoomID(data, chat_id);
|
||||
ref = DbLock(data->db, 1, "chats");
|
||||
json = DbJson(ref);
|
||||
mucs = GrabObject(json, 1, "rooms");
|
||||
JsonValueFree(HashMapDelete(mucs, room));
|
||||
DbUnlock(data->db, ref);
|
||||
|
||||
DbDelete(data->db, 2, "chats", chat_id);
|
||||
ParseeUnlinkRoom(data, chat_id);
|
||||
|
||||
/* TODO: Do it automatically, if *not plumbed* */
|
||||
ReplySprintf("The MUC %s is now *unlinked*.", muc);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue