示例#1
0
static gboolean
autojoin_cb(gpointer data)
{
	PurpleAccount *account = data;
	gchar *cmd = g_strdup_printf("join %s", AUTOJOIN), *error = NULL,
		  *esc = g_markup_escape_text(cmd, -1);
	int result = 0;

	/* this hack courtesy irchelper -- don't use purple_conversation_set_account
	 * because it will fire a signal that other plugins can use.  Instead do
	 * this hack. This will break when struct hiding is complete and ABI breaks. */
	PurpleConversation *conv = purple_conversation_new(PURPLE_CONV_TYPE_IM,
	                                                   account, "None");

	purple_debug_info("irc-more", "Executng command: %s\n", cmd);
	result = purple_cmd_do_command(conv, cmd, esc, &error);
	purple_debug_info("irc-more", "Executed command.  Result: %d.  Error: %s\n",
			result, error ? error : "(null)");

	g_free(cmd);
	g_free(conv);
	g_free(esc);

	return FALSE;
}
示例#2
0
文件: irc.cpp 项目: hanzz/spectrum
bool IRCProtocol::changeNickname(const std::string &nick, PurpleConversation *conv) {
    char *error = NULL;
    purple_cmd_do_command(conv, std::string("nick " + nick).c_str(), std::string("nick " + nick).c_str(), &error);
    if (error)
        g_free(error);
    return true;
}
示例#3
0
/**
 * @brief This is the implementation of the actual command that is run from inside of an instant messenger
 * window. It will take the first argument and process it utilizing the process_url function.
 * @arg conv This is the conversation object passed in from the libpurple api.
 * @arg cmd This is the actual command being executed, in this case it should be "bitly"
 * @arg args This is a character array of arguments.
 * @arg data Most likely junk. We do not use this parameter.
 */
static PurpleCmdRet
purple_cmd_bitly (PurpleConversation* conv, const char* cmd, char** args, char* error, void* data) {
    PurpleCmdStatus ret;
    GString* str = g_string_new(args[0]);
    char* newcmd = NULL;

    if (args[0])
    {
        const char* login = purple_prefs_get_string("/plugins/core/bitly_urlshort/account");
        const char* apiKey = purple_prefs_get_string("/plugins/core/bitly_urlshort/apikey");

        str = process_url(login, apiKey, str);
        newcmd = g_strdup_printf("say %s", str->str);
        ret = purple_cmd_do_command(conv, newcmd, newcmd, &error);
        free(newcmd);
        g_string_free(str, TRUE);
    }
    return ret;
}
示例#4
0
static gboolean
show_them(gpointer data)
{
	/* So you think you can kick me? I'll show you! */
	PurpleConversation *conv = data;
	const char *conv_name = NULL;
	char *command = NULL, *markup = NULL, *error = NULL;

	if(conv)
		conv_name = purple_conversation_get_name(conv);

	if(conv_name) {
		command = g_strdup_printf("join %s", conv_name);
		markup = g_markup_escape_text(command, -1);
		error = NULL;
		purple_cmd_do_command(conv, command, markup, &error);  /* Do anything with the return value? */
		g_free(command);
		g_free(markup);
		g_free(error);
	}

	return FALSE;
}
示例#5
0
static void
entry_key_pressed(GntWidget *w, FinchConv *ggconv)
{
	const char *text = gnt_entry_get_text(GNT_ENTRY(ggconv->entry));
	if (*text == '/' && *(text + 1) != '/')
	{
		PurpleConversation *conv = ggconv->active_conv;
		PurpleCmdStatus status;
		const char *cmdline = text + 1;
		char *error = NULL, *escape;

		escape = g_markup_escape_text(cmdline, -1);
		status = purple_cmd_do_command(conv, cmdline, escape, &error);
		g_free(escape);

		switch (status)
		{
			case PURPLE_CMD_STATUS_OK:
				break;
			case PURPLE_CMD_STATUS_NOT_FOUND:
				purple_conversation_write(conv, "", _("No such command."),
						PURPLE_MESSAGE_NO_LOG, time(NULL));
				break;
			case PURPLE_CMD_STATUS_WRONG_ARGS:
				purple_conversation_write(conv, "", _("Syntax Error:  You typed the wrong number of arguments "
							"to that command."),
						PURPLE_MESSAGE_NO_LOG, time(NULL));
				break;
			case PURPLE_CMD_STATUS_FAILED:
				purple_conversation_write(conv, "", error ? error : _("Your command failed for an unknown reason."),
						PURPLE_MESSAGE_NO_LOG, time(NULL));
				break;
			case PURPLE_CMD_STATUS_WRONG_TYPE:
				if(purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM)
					purple_conversation_write(conv, "", _("That command only works in chats, not IMs."),
							PURPLE_MESSAGE_NO_LOG, time(NULL));
				else
					purple_conversation_write(conv, "", _("That command only works in IMs, not chats."),
							PURPLE_MESSAGE_NO_LOG, time(NULL));
				break;
			case PURPLE_CMD_STATUS_WRONG_PRPL:
				purple_conversation_write(conv, "", _("That command doesn't work on this protocol."),
						PURPLE_MESSAGE_NO_LOG, time(NULL));
				break;
		}
		g_free(error);
	}
	else if (!purple_account_is_connected(purple_conversation_get_account(ggconv->active_conv)))
	{
		purple_conversation_write(ggconv->active_conv, "", _("Message was not sent, because you are not signed on."),
				PURPLE_MESSAGE_ERROR | PURPLE_MESSAGE_NO_LOG, time(NULL));
	}
	else
	{
		char *escape = purple_markup_escape_text((*text == '/' ? text + 1 : text), -1);
		switch (purple_conversation_get_type(ggconv->active_conv))
		{
			case PURPLE_CONV_TYPE_IM:
				purple_conv_im_send_with_flags(PURPLE_CONV_IM(ggconv->active_conv), escape, PURPLE_MESSAGE_SEND);
				break;
			case PURPLE_CONV_TYPE_CHAT:
				purple_conv_chat_send(PURPLE_CONV_CHAT(ggconv->active_conv), escape);
				break;
			default:
				g_free(escape);
				g_return_if_reached();
		}
		g_free(escape);
		purple_idle_touch();
	}
	gnt_entry_add_to_history(GNT_ENTRY(ggconv->entry), text);
	gnt_entry_clear(GNT_ENTRY(ggconv->entry));
}
示例#6
0
xmlnode * _h_elim_command ( const char *name ,
                            const char *id   ,
                            SEXP_VALUE *args ,
                            gpointer data    )
{
    fprintf(stderr, "(elim-debug entered _h_elim_command)");
    ASSERT_ALISTP( args, id, name );
    
    elim_ping();

    const char *aname = ALIST_VAL_STR( args, "account-name" );
    const char *proto = ALIST_VAL_STR( args, "im-protocol"  );
    gpointer    auid  = ALIST_VAL_PTR( args, "account-uid"  );

    PurpleAccount *acct = 
      auid ? find_acct_by_uid( auid ) : purple_accounts_find( aname, proto );

    if( !acct )
    {
        sexp_val_free( args );
        return response_error( ENXIO, id, name, "unknown account" );
    }

    PurpleConversationType pt = PURPLE_CONV_TYPE_UNKNOWN;
    gpointer             cuid = ALIST_VAL_PTR( args, "conv-uid"  );
    const char         *cname = ALIST_VAL_STR( args, "conv-name" );
    PurpleConversation    *pc = find_conv_by_acct_uid( acct, cuid );

    if  ( pc ) pt = purple_conversation_get_type( pc );
    else
    {
        pt = PURPLE_CONV_TYPE_ANY;
        pc = purple_find_conversation_with_account( pt, cname, acct );
        if( !pc )
        {
            sexp_val_free( args );
            return response_error( ENOENT, id, name, "conversation not found" );
        }
        else { pt = purple_conversation_get_type( pc ); }
    }

    PurpleCmdStatus c_s = PURPLE_CMD_STATUS_FAILED;
    const char     *cmd = ALIST_VAL_STRING( args, "command" );
    char           *esc = g_markup_escape_text( cmd, -1 );
    char           *err = NULL;
    const char   *error = NULL;
    c_s = purple_cmd_do_command( pc, cmd, esc, &err );

    if( c_s != PURPLE_CMD_STATUS_OK && (!err || !*err) )
        switch( c_s )
        {
          case PURPLE_CMD_STATUS_FAILED    :
            error = "Command failed";
            break;
          case PURPLE_CMD_STATUS_NOT_FOUND :
            error = "Command not found";
            break;
          case PURPLE_CMD_STATUS_WRONG_ARGS:
            error = "Bad command arguments";
            break;
          case PURPLE_CMD_STATUS_WRONG_PRPL:
            error = "Command not valid for this IM protocol";
            break;
          case PURPLE_CMD_STATUS_WRONG_TYPE:
            error = "Command not valid in this conversation";
            break;
          default:
            error = "Unknown command error";
        }

    xmlnode *rval = xnode_new( "alist" );
    AL_PTR ( rval, "conv-uid"      , pc  );
    AL_STR ( rval, "conv-name"     , purple_conversation_get_name(pc) );

    AL_ENUM( rval, "command-status", c_s , ":cmd-status" );
    AL_STR ( rval, "command-error" , err ? err : error   );
    AL_STR ( rval, "command-line"  , cmd );

    g_free       ( err  );
    g_free       ( esc  );
    sexp_val_free( args );

    fprintf(stderr, "(elim-debug leaving _h_elim_command)");
    return response_value( 0, id, name, rval );
}
示例#7
0
文件: purple.c 项目: echoline/rs
char *alice(const char *source, const char *msgin, PurpleConversation *conv) {
	int s, t, len, chk = 0;
	char *ptr;
	struct sockaddr_un remote;
	char str[0x10000];
	static char msg[0x10000];
	gchar *error = NULL;

TOP:
	if (!chk)
		snprintf(str,sizeof(str)-1,"%s\007%s",source,msgin);
	else
		snprintf(str,sizeof(str)-1,"%s",source);

	if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
		return "error in socket()";
	}

	remote.sun_family = AF_UNIX;
	strcpy(remote.sun_path, "/tmp/alice");
	len = strlen(remote.sun_path) + sizeof(remote.sun_family);
	if (connect(s, (struct sockaddr *)&remote, len) == -1) {
		return "error in connect()";
	}	

	if (send(s, str, strlen(str), 0) == -1) {
		return "error in send()";
	}

	if ((t=recv(s, str, 1024, 0)) > 0) {
		str[t] = '\0';
	} else {
		return "error in recv()";
	}

	close(s);

	if (chk) {
		if (!strcasecmp(str, "abusive")) {
			snprintf(str,sizeof(str)-1,"kick %s",source);
			purple_cmd_do_command(conv, str, str, &error);

			if (error) {
				snprintf(msg,sizeof(msg)-1,"%s",error);
				free(error);
			} else
				snprintf(msg,sizeof(msg)-1,"!kick %s",source);
		}
	} else {
		strncpy(msg, str, 0xFFFF);
		if (conv == chat_g) {
			chk = 1;
			goto TOP;
		}
	}

	// pause for typing reality-ness
/*	len = strlen(msg);
	if (len > 20)
		len = 20;
	for (t = 0; t < len; t++)
		usleep(99000);*/

	return msg;
}