grim/purple-spasm

2a1c4ada8b4a
Parents ca9c17d5becc
Children aa6ea9564502
Add a /quote command to run twitch specific commands
--- a/src/meson.build Mon Feb 28 21:53:34 2022 -0600
+++ b/src/meson.build Mon Feb 28 22:41:06 2022 -0600
@@ -3,6 +3,8 @@
'spasm-account.h',
'spasm-chat.c',
'spasm-chat.h',
+ 'spasm-commands.c',
+ 'spasm-commands.h',
'spasm-const.h',
'spasm-plugin.c',
'spasm-rest.c',
--- a/src/spasm-account.c Mon Feb 28 21:53:34 2022 -0600
+++ b/src/spasm-account.c Mon Feb 28 22:41:06 2022 -0600
@@ -383,3 +383,16 @@
return sa->chat;
}
+SpasmAccount *
+spasm_account_from_conversation(PurpleConversation *conv) {
+ PurpleConnection *connection = NULL;
+
+ g_return_val_if_fail(conv != NULL, NULL);
+
+ connection = purple_conversation_get_gc(conv);
+ if(connection == NULL) {
+ return NULL;
+ }
+
+ return purple_connection_get_protocol_data(connection);
+}
--- a/src/spasm-account.h Mon Feb 28 21:53:34 2022 -0600
+++ b/src/spasm-account.h Mon Feb 28 22:41:06 2022 -0600
@@ -61,6 +61,8 @@
SpasmChatService *spasm_account_get_chat_service(SpasmAccount *sa);
+SpasmAccount *spasm_account_from_conversation(PurpleConversation *conv);
+
G_END_DECLS
#endif /* SPASM_ACCOUNT_H */
--- a/src/spasm-chat.c Mon Feb 28 21:53:34 2022 -0600
+++ b/src/spasm-chat.c Mon Feb 28 22:41:06 2022 -0600
@@ -549,7 +549,7 @@
chat->output_stream = g_io_stream_get_output_stream(G_IO_STREAM(chat->socket_connection));
/* first check that we have the right capabilities */
- spasm_chat_service_real_send(chat, "CAP REQ :twitch.tv/membership twitch.tv/tags");
+ spasm_chat_service_real_send(chat, "CAP REQ :twitch.tv/commands twitch.tv/membership twitch.tv/tags");
/* now do the login */
spasm_chat_service_real_send(
@@ -734,3 +734,10 @@
{
}
+
+void
+spasm_chat_service_send_raw(SpasmChatService *chat, const gchar *raw) {
+ g_return_if_fail(chat != NULL);
+
+ spasm_chat_service_real_send(chat, "%s", raw);
+}
--- a/src/spasm-chat.h Mon Feb 28 21:53:34 2022 -0600
+++ b/src/spasm-chat.h Mon Feb 28 22:41:06 2022 -0600
@@ -41,6 +41,8 @@
gint spasm_chat_service_send(PurpleConnection *connection, gint id, const gchar *message, PurpleMessageFlags flags);
void spasm_chat_service_set_topic(PurpleConnection *connection, gint id, const gchar *topic);
+void spasm_chat_service_send_raw(SpasmChatService *chat, const gchar *raw);
+
G_END_DECLS
#endif /* SPASM_CHAT */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/spasm-commands.c Mon Feb 28 22:41:06 2022 -0600
@@ -0,0 +1,69 @@
+/*
+ * Spasm - A Twitch Protocol Plugin
+ * Copyright (C) 2017-2022 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <purple.h>
+
+#include "spasm-account.h"
+#include "spasm-chat.h"
+#include "spasm-commands.h"
+
+/******************************************************************************
+ * Command Implementations
+ *****************************************************************************/
+static PurpleCmdRet
+spasm_command_quote(PurpleConversation *conv, const gchar *cmd, gchar **args,
+ gchar **error, gpointer data)
+{
+ SpasmAccount *sa = spasm_account_from_conversation(conv);
+ SpasmChatService *chat = NULL;
+ gchar *msg = NULL, *quoted = NULL;
+
+ if(sa == NULL) {
+ return PURPLE_CMD_RET_FAILED;
+ }
+
+ chat = spasm_account_get_chat_service(sa);
+
+ quoted = g_strjoinv(" ", args);
+ msg = g_strdup_printf("PRIVMSG #%s :%s",
+ purple_conversation_get_name(conv),
+ quoted);
+ g_free(quoted);
+
+ spasm_chat_service_send_raw(chat, msg);
+ g_free(msg);
+
+ return PURPLE_CMD_RET_OK;
+}
+
+/******************************************************************************
+ * Public API
+ *****************************************************************************/
+void
+spasm_commands_register() {
+ PurpleCmdFlag f;
+
+ f = PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_PRPL_ONLY |
+ PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS;
+
+ purple_cmd_register("quote", "s", PURPLE_CMD_P_PRPL, f,
+ "prpl-grim-spasm", spasm_command_quote,
+ "quote [...]: Send a raw command to the server.",
+ NULL);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/spasm-commands.h Mon Feb 28 22:41:06 2022 -0600
@@ -0,0 +1,31 @@
+/*
+ * Spasm - A Twitch Protocol Plugin
+ * Copyright (C) 2017-2022 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SPASM_COMMANDS_H
+#define SPASM_COMMANDS_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+void spasm_commands_register();
+
+G_END_DECLS
+
+#endif /* SPASM_COMMANDS_H */
--- a/src/spasm-plugin.c Mon Feb 28 21:53:34 2022 -0600
+++ b/src/spasm-plugin.c Mon Feb 28 22:41:06 2022 -0600
@@ -66,6 +66,7 @@
static void
spasm_plugin_init(PurplePlugin *plugin) {
+ spasm_commands_register();
}
static PurplePluginProtocolInfo spasm_protocol_info = {