Command /topic modifications:
* new line symbol "\n" is available * remove required channel name from arguments: /topic [message] https://github.com/HarpyWar/pvpgn/issues/6
This commit is contained in:
parent
8657c029c9
commit
0e72ec967b
5 changed files with 86 additions and 75 deletions
|
@ -299,9 +299,9 @@ Example: /voice user
|
|||
Removes <username> from the VOP list and removes temporary voice privileges.
|
||||
Example: /devoice user
|
||||
%topic
|
||||
/topic [[channel] "[message]"]
|
||||
Sets or displays [channel]'s topic.
|
||||
Example: /topic Moderated Support "Supported is given in this channel..."
|
||||
/topic [message]
|
||||
Sets or displays current channel's topic.
|
||||
Example: /topic Supported is given in this channel...\n(some text on a new line)
|
||||
%moderate
|
||||
/moderate
|
||||
Toggles the current channel's moderated status.
|
||||
|
|
|
@ -5014,86 +5014,48 @@ namespace pvpgn
|
|||
static int _handle_topic_command(t_connection * c, char const * text)
|
||||
{
|
||||
char const * channel_name;
|
||||
char const * topic;
|
||||
char * tmp;
|
||||
const char * topic;
|
||||
t_channel * channel;
|
||||
int do_save = NO_SAVE_TOPIC;
|
||||
|
||||
channel_name = skip_command(text);
|
||||
topic = skip_command(text);
|
||||
|
||||
if ((topic = std::strchr(channel_name, '"')))
|
||||
{
|
||||
tmp = (char *)topic;
|
||||
for (tmp--; tmp[0] == ' '; tmp--);
|
||||
tmp[1] = '\0';
|
||||
topic++;
|
||||
tmp = std::strchr((char *)topic, '"');
|
||||
if (tmp) tmp[0] = '\0';
|
||||
}
|
||||
|
||||
if (!(conn_get_channel(c))) {
|
||||
if (!(channel = conn_get_channel(c))) {
|
||||
message_send_text(c, message_type_error, c, "This command can only be used inside a channel.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (channel_name[0] == '\0')
|
||||
{
|
||||
if (channel_get_topic(channel_get_name(conn_get_channel(c))))
|
||||
{
|
||||
snprintf(msgtemp, sizeof(msgtemp), "%.64s topic: %.128s", channel_get_name(conn_get_channel(c)), channel_get_topic(channel_get_name(conn_get_channel(c))));
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(msgtemp, sizeof(msgtemp), "%.64s topic: no topic", channel_get_name(conn_get_channel(c)));
|
||||
}
|
||||
message_send_text(c, message_type_info, c, msgtemp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(topic))
|
||||
{
|
||||
if (channel_get_topic(channel_name))
|
||||
{
|
||||
snprintf(msgtemp, sizeof(msgtemp), "%.64s topic: %.128s", channel_name, channel_get_topic(channel_name));
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(msgtemp, sizeof(msgtemp), "%.64s topic: no topic", channel_name);
|
||||
}
|
||||
message_send_text(c, message_type_info, c, msgtemp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(channel = channellist_find_channel_by_name(channel_name, conn_get_country(c), realm_get_name(conn_get_realm(c)))))
|
||||
{
|
||||
snprintf(msgtemp, sizeof(msgtemp), "There is no such channel.");
|
||||
message_send_text(c, message_type_error, c, msgtemp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (std::strlen(topic) >= MAX_TOPIC_LEN)
|
||||
{
|
||||
snprintf(msgtemp, sizeof(msgtemp), "Max topic length exceeded (max %d symbols)", MAX_TOPIC_LEN);
|
||||
message_send_text(c, message_type_error, c, msgtemp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
channel_name = channel_get_name(channel);
|
||||
|
||||
if (!(account_is_operator_or_admin(conn_get_account(c), channel_name))) {
|
||||
snprintf(msgtemp, sizeof(msgtemp), "You must be at least a Channel Operator of %.64s to set the topic", channel_name);
|
||||
message_send_text(c, message_type_error, c, msgtemp);
|
||||
return -1;
|
||||
// set channel topic
|
||||
if (topic[0] != '\0')
|
||||
{
|
||||
if (std::strlen(topic) >= MAX_TOPIC_LEN)
|
||||
{
|
||||
snprintf(msgtemp, sizeof(msgtemp), "Max topic length exceeded (max %d symbols)", MAX_TOPIC_LEN);
|
||||
message_send_text(c, message_type_error, c, msgtemp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(account_is_operator_or_admin(conn_get_account(c), channel_name))) {
|
||||
snprintf(msgtemp, sizeof(msgtemp), "You must be at least a Channel Operator of %.64s to set the topic", channel_name);
|
||||
message_send_text(c, message_type_error, c, msgtemp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (channel_get_permanent(channel))
|
||||
do_save = DO_SAVE_TOPIC;
|
||||
|
||||
channel_set_topic(channel_name, topic, do_save);
|
||||
}
|
||||
|
||||
if (channel_get_permanent(channel))
|
||||
do_save = DO_SAVE_TOPIC;
|
||||
|
||||
channel_set_topic(channel_name, topic, do_save);
|
||||
|
||||
snprintf(msgtemp, sizeof(msgtemp), "%.64s topic: %.128s", channel_name, topic);
|
||||
message_send_text(c, message_type_info, c, msgtemp);
|
||||
// display channel topic
|
||||
if (channel_display_topic(c, channel_name) < 0)
|
||||
{
|
||||
snprintf(msgtemp, sizeof(msgtemp), "%.64s topic: no topic", channel_name);
|
||||
message_send_text(c, message_type_info, c, msgtemp);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -2071,12 +2071,10 @@ namespace pvpgn
|
|||
message_send_text(c, message_type_info, c, msgtemp);
|
||||
}
|
||||
|
||||
if (channel_get_topic(channel_get_name(c->protocol.chat.channel)) && ((conn_is_irc_variant(c)) == 0))
|
||||
|
||||
if (conn_is_irc_variant(c) == 0)
|
||||
{
|
||||
char msgtemp[MAX_MESSAGE_LEN];
|
||||
|
||||
std::sprintf(msgtemp, "%s topic: %s", channel_get_name(c->protocol.chat.channel), channel_get_topic(channel_get_name(c->protocol.chat.channel)));
|
||||
message_send_text(c, message_type_info, c, msgtemp);
|
||||
channel_display_topic(c, channel_get_name(c->protocol.chat.channel));
|
||||
}
|
||||
|
||||
if (c->protocol.chat.channel && (channel_get_flags(c->protocol.chat.channel) & channel_flags_moderated))
|
||||
|
|
|
@ -20,11 +20,15 @@
|
|||
#include <cstdio>
|
||||
|
||||
#include "compat/strcasecmp.h"
|
||||
#include "compat/snprintf.h"
|
||||
|
||||
#include "common/list.h"
|
||||
#include "common/eventlog.h"
|
||||
#include "common/xalloc.h"
|
||||
#include "common/field_sizes.h"
|
||||
|
||||
#include "message.h"
|
||||
|
||||
#include "prefs.h"
|
||||
#include "common/setup_after.h"
|
||||
|
||||
|
@ -207,6 +211,50 @@ namespace pvpgn
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Display topic with new lines formatting (\n) */
|
||||
int channel_display_topic(t_connection * c, const char * channel_name)
|
||||
{
|
||||
char msgtemp[MAX_MESSAGE_LEN];
|
||||
char *topic, *tmp, *token;
|
||||
char * delim = "\\";
|
||||
if (!(topic = channel_get_topic(channel_name)))
|
||||
return -1;
|
||||
|
||||
tmp = xstrdup(topic);
|
||||
|
||||
token = strtok(tmp, delim);
|
||||
bool first = true;
|
||||
bool start_with_bs = (topic[0] == '\\');
|
||||
|
||||
while (token)
|
||||
{
|
||||
if (token[0] == 'n')
|
||||
{
|
||||
*token++;
|
||||
if (first && start_with_bs)
|
||||
{
|
||||
snprintf(msgtemp, sizeof(msgtemp), "%.64s topic:", channel_name);
|
||||
message_send_text(c, message_type_info, c, msgtemp);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (first)
|
||||
snprintf(msgtemp, sizeof(msgtemp), "%.64s topic: %.128s", channel_name, token);
|
||||
else
|
||||
snprintf(msgtemp, sizeof(msgtemp), token);
|
||||
|
||||
message_send_text(c, message_type_info, c, msgtemp);
|
||||
|
||||
token = strtok(NULL, delim);
|
||||
first = false;
|
||||
}
|
||||
xfree((void *)tmp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
#ifndef INCLUDED_TOPIC_TYPES
|
||||
#define INCLUDED_TOPIC_TYPES
|
||||
|
||||
#include "connection.h"
|
||||
|
||||
namespace pvpgn
|
||||
{
|
||||
|
||||
|
@ -56,6 +58,7 @@ namespace pvpgn
|
|||
int topiclist_unload(void);
|
||||
int channel_set_topic(char const * channel_name, char const * topic_text, int do_save);
|
||||
char * channel_get_topic(char const * channel_name);
|
||||
int channel_display_topic(t_connection * c, const char * channel_name);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue