Channel Class

Note: Currently the information is pre-release, and could be changed at any time before the release. Please refer to the code for the most accurate use of this object.

The channel class has all the functionality to manage a channel and its users. It is recommended that you instantiate a new channel through the servers Join method, and retrieve it by using the GetChannel method. It is very important that you remember to suffix the channel name with the # symbol.

     server.Join("#YourChannel");
     Channel chan = server.GetChannel("#YourChannel");

Once you have joined a channel, you can send a message by using the Send method. When using this method, the PRIVMSG and channel name are already assumed and should not be given to the Send method.

     server.GetChannel("#YourChannel")->Send("This is your message");

When you join a channel, Modesto will automatically check to see who is in the channel, and then auto-populate the user list. You can check to see how many users there are by calling NumUsers, or find out is in the room by using the HasUser method. You can also retrieve the user by calling GetUser. If you'd like to know more about the User class, then please visit the User Class page.

     if (server.GetChannel("#YourChannel")->HasUser("NickName"))
     {
          User usr = server.GetChannel("#YourChannel")->GetUser("NickName");
          usr->Send("Hello");
     }

If you need to check if the user exists so that you can call a method on the user class, then we suggest you skip the HasUser method, and go directly to calling GetUser which will return a NULL value if the user does not exist.

     if (User usr = server.GetChannel("#YourChannel")->GetUser("NickName"))
     {
          usr->Send("Hello");
     }

Example

Below is an example of how to retrieve and use the Channel class. This will only work if you have already connected to the server by using the Server Class.

     serv.Join("#MyChannel");

     if (Channel chan = serv.GetChannel("#MyChannel"))
     {
          chan->Send("Hello channel, I am Modesto");

          if (chan->HasUser("MasterChief"))
          {
               chan->Send("I see you MasterChief, let's take this to PM");
          }
 
          if (User usr = chan->GetUser("MasterChief"))
          {
               usr->Send("It's good to see you again MasterChief!");
          }
     }

     serv.Part("#MyChannel");

API Reference

Method Name Description
void Channel(std::string name, Server &server) Instantiate a new channel instance. You must prefix the name with the # symbol.
std::string GetName() Returns the name of the channel, including the prefixed #.
void Send(std::string message) // Send a message directly to the channel. The method already assumes the PRIVMSG and channel name.
int NumUsers() Returns the number of users who are in this channel.
bool HasUser(std::string nick) Check to see if the user is currently in this channel.
User *GetUser(std::string name) Returns a specific user from the channel.
UserList GetUsers() Returns a list of all the users who are in the channel.
void OnJoin(User *usr, RawCmd cmd) Adds the user to the user list, and executes user join events.
void OnPart(RawCmd cmd) Removes the user from the user list, and executes user part events.
void OnMessage(RawCmd cmd) Executes the events that occur when a new message is received.
void OnModeChange(RawCmd cmd) Executes the events that occur when a channel mode is changed.
void OnTopicChange(RawCmd cmd) Executes the events that occur when a channel topic is changed.

Last edited Aug 30, 2013 at 11:47 PM by cbutcher, version 2

Comments

No comments yet.