aboutsummaryrefslogtreecommitdiffstats
path: root/irc_send.c
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2016-03-21 13:46:32 +0100
committerMarius Halden <marius.h@lden.org>2017-03-17 11:38:24 +0100
commit4b3ef9273fe8136ae8fe8df2b7c2b6dc7a3144e4 (patch)
tree7ade0911fe80e7e4808b77cfd64b0f9a283d682a /irc_send.c
parent262a82b875f2a05cdcf2258260c5e8a9e538f405 (diff)
Add irc_send_tagged_msg* to send tagged messages
Add support for tagged messages by adding the functions irc_send_tagged_msg*, the old irc_send_msg* functions are now wrappers for these functions without any tags.
Diffstat (limited to 'irc_send.c')
-rw-r--r--irc_send.c56
1 files changed, 48 insertions, 8 deletions
diff --git a/irc_send.c b/irc_send.c
index 89f0100a..38d1221d 100644
--- a/irc_send.c
+++ b/irc_send.c
@@ -364,6 +364,11 @@ void irc_send_who(irc_t *irc, GSList *l, const char *channel)
void irc_send_msg(irc_user_t *iu, const char *type, const char *dst, const char *msg, const char *prefix)
{
+ irc_send_tagged_msg(iu, type, dst, msg, prefix, NULL);
+}
+
+void irc_send_tagged_msg(irc_user_t *iu, const char *type, const char *dst, const char *msg, const char *prefix, const char *tags)
+{
char last = 0;
const char *s = msg, *line = msg;
char raw_msg[strlen(msg) + 1024];
@@ -383,14 +388,14 @@ void irc_send_msg(irc_user_t *iu, const char *type, const char *dst, const char
strcpy(raw_msg, "\001ACTION ");
strncat(raw_msg, line + 4, s - line - 4);
strcat(raw_msg, "\001");
- irc_send_msg_raw(iu, type, dst, raw_msg);
+ irc_send_tagged_msg_raw(iu, type, dst, raw_msg, tags);
} else {
*raw_msg = '\0';
if (prefix && *prefix) {
strcpy(raw_msg, prefix);
}
strncat(raw_msg, line, s - line);
- irc_send_msg_raw(iu, type, dst, raw_msg);
+ irc_send_tagged_msg_raw(iu, type, dst, raw_msg, tags);
}
line = s + 1;
}
@@ -400,21 +405,56 @@ void irc_send_msg(irc_user_t *iu, const char *type, const char *dst, const char
void irc_send_msg_raw(irc_user_t *iu, const char *type, const char *dst, const char *msg)
{
- irc_write(iu->irc, ":%s!%s@%s %s %s :%s",
- iu->nick, iu->user, iu->host, type, dst, msg && *msg ? msg : " ");
+ irc_send_tagged_msg_raw(iu, type, dst, msg, NULL);
+}
+
+void irc_send_tagged_msg_raw(irc_user_t *iu, const char *type, const char *dst, const char *msg, const char *tags)
+{
+ if (!tags || !*tags) {
+ irc_write(iu->irc, ":%s!%s@%s %s %s :%s",
+ iu->nick, iu->user, iu->host,
+ type, dst, msg && *msg ? msg : " ");
+ } else {
+ irc_write(iu->irc, "@%s :%s!%s@%s %s %s :%s",
+ tags, iu->nick, iu->user, iu->host,
+ type, dst, msg && *msg ? msg : " ");
+ }
}
void irc_send_msg_f(irc_user_t *iu, const char *type, const char *dst, const char *format, ...)
{
- char text[IRC_MAX_LINE];
va_list params;
va_start(params, format);
- g_vsnprintf(text, IRC_MAX_LINE, format, params);
+ irc_send_tagged_msg_vf(iu, type, dst, NULL, format, params);
+ va_end(params);
+
+}
+
+void irc_send_tagged_msg_f(irc_user_t *iu, const char *type, const char *dst, const char *tags, const char *format, ...)
+{
+ va_list params;
+
+ va_start(params, format);
+ irc_send_tagged_msg_vf(iu, type, dst, tags, format, params);
va_end(params);
+}
- irc_write(iu->irc, ":%s!%s@%s %s %s :%s",
- iu->nick, iu->user, iu->host, type, dst, text);
+void irc_send_tagged_msg_vf(irc_user_t *iu, const char *type, const char *dst, const char *tags, const char *format, va_list params)
+{
+ char text[IRC_MAX_LINE];
+
+ g_vsnprintf(text, IRC_MAX_LINE, format, params);
+
+ if (!tags || !*tags) {
+ irc_write(iu->irc, ":%s!%s@%s %s %s :%s",
+ iu->nick, iu->user, iu->host,
+ type, dst, text);
+ } else {
+ irc_write(iu->irc, "@%s :%s!%s@%s %s %s :%s",
+ tags, iu->nick, iu->user, iu->host,
+ type, dst, text);
+ }
}
void irc_send_nick(irc_user_t *iu, const char *new)