1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-07-08 01:47:11 +02:00

Implement methods to send messages with style formatting in the IRC module. Should close #7

Also remove duplicate code in raw squirrel functions by merging it into one function.
This commit is contained in:
Sandu Liviu Catalin
2016-08-16 21:38:04 +03:00
parent 0f2ac5679a
commit e770ac3405
6 changed files with 193 additions and 142 deletions

View File

@ -89,14 +89,6 @@ protected:
*/
void IsNotConnected() const;
/* --------------------------------------------------------------------------------------------
* See whether this session is connected to a server or not.
*/
bool Connected() const
{
return (m_Session && irc_is_connected(m_Session));
}
/* --------------------------------------------------------------------------------------------
* Validate a session instance used by an event and log an error if it's invalid.
*/
@ -227,6 +219,14 @@ public:
*/
static SQInteger Typename(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Retrieve the actual session handle.
*/
irc_session_t * GetHandle() const
{
return m_Session;
}
/* --------------------------------------------------------------------------------------------
* See whether this session is valid.
*/
@ -569,11 +569,11 @@ public:
void Disconnect();
/* --------------------------------------------------------------------------------------------
* See whether the session is connected to a server.
* See whether this session is connected to a server or not.
*/
bool IsConnected()
{
return Connected();
return (m_Session && irc_is_connected(m_Session));
}
/* --------------------------------------------------------------------------------------------
@ -774,6 +774,72 @@ public:
return irc_cmd_notice(m_Session, nch, text);
}
/* --------------------------------------------------------------------------------------------
* Send a message to a specific channel or privately to another nick.
*/
Int32 CmdColoredMsg(CSStr nch, CSStr text)
{
// Validate the connection status
ValidateConnection();
// Attempt to scan the specified message for color formatting
char * cmsg = irc_color_convert_to_mirc(text, IrcAllocMem);
// Validate the message
if (!cmsg)
{
STHROWF("Failed to convert the message colors");
}
// Send the resulted message and grab the result code
const int ret = irc_cmd_msg(m_Session, nch, cmsg);
// Free the memory used to convert the message
IrcFreeMem(cmsg);
// Return the resulted code
return ret;
}
/* --------------------------------------------------------------------------------------------
* Send a /me message (CTCP ACTION) to a specific channel or privately to another nick.
*/
Int32 CmdColoredMe(CSStr nch, CSStr text)
{
// Validate the connection status
ValidateConnection();
// Attempt to scan the specified message for color formatting
char * cmsg = irc_color_convert_to_mirc(text, IrcAllocMem);
// Validate the message
if (!cmsg)
{
STHROWF("Failed to convert the message colors");
}
// Send the resulted message and grab the result code
const int ret = irc_cmd_me(m_Session, nch, cmsg);
// Free the memory used to convert the message
IrcFreeMem(cmsg);
// Return the resulted code
return ret;
}
/* --------------------------------------------------------------------------------------------
* Send a notice to a specific channel or privately to another nick.
*/
Int32 CmdColoredNotice(CSStr nch, CSStr text)
{
// Validate the connection status
ValidateConnection();
// Attempt to scan the specified message for color formatting
char * cmsg = irc_color_convert_to_mirc(text, IrcAllocMem);
// Validate the message
if (!cmsg)
{
STHROWF("Failed to convert the message colors");
}
// Send the resulted message and grab the result code
const int ret = irc_cmd_notice(m_Session, nch, cmsg);
// Free the memory used to convert the message
IrcFreeMem(cmsg);
// Return the resulted code
return ret;
}
/* --------------------------------------------------------------------------------------------
* Send a CTCP request to the specified user on the connected server.
*/
@ -927,6 +993,21 @@ public:
*/
static SQInteger CmdNoticeF(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Send a colored message to a specific channel or privately to another nick.
*/
static SQInteger CmdColoredMsgF(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Send a colored /me message (CTCP ACTION) to a specific channel or privately to another nick.
*/
static SQInteger CmdColoredMeF(HSQUIRRELVM vm);
/* --------------------------------------------------------------------------------------------
* Send a colored notice to a specific channel or privately to another nick.
*/
static SQInteger CmdColoredNoticeF(HSQUIRRELVM vm);
protected:
/* --------------------------------------------------------------------------------------------