Home DevelopersExamples & updates Added “IsHosting” to HostTarget and other changes

Added “IsHosting” to HostTarget and other changes

by BlushyFace
64 views

Added “IsHosting” to the HostTarget event
The IsHosting (bool) returns whether the host channel is hosting or unhosting the target channel.

Example
The first HOSTTARGET event shows that a client named justinfan12345 in channel #blushyface is hosting blushyfacebot with 0 viewers. A JOIN event occurs and shows that the client is joining #blushyfacebot , the client can now receive the target channel events the client is subscribed to such as PRIVMSG events to read chat messages etc.

The second HOSTTARGET event unhosts the target channel with 0 viewers but we cannot leave the target channel automatically because unhosting does not return a channel name. To do this manually you need to call the Part method (client.Part(…); but since we don’t know the target channel name it is recommended to keep track of what channel the client is hosting to leave when the host unhosts the target channel, or leave it as is and let the client stay in the channel.

        internal static async void Client_OnHostTargetEventHandler(Client client, HostTarget e)
        {
            if (e.IsHosting)
                await client.Join(e.Target);

            var message = string.Empty;
            message += !string.IsNullOrEmpty(client.LoginName) ? $"[{client.LoginName}] " : "";
            message += !string.IsNullOrEmpty(e.Host) ? $"[{e.Host}] " : "";
            message += $"Is hosting: {e.IsHosting.BoolToYesNo()} ";
            message += !string.IsNullOrEmpty(e.Target) ? $"[{e.Target}] " : "";
            message += !string.IsNullOrEmpty(e.Viewers) ? $"[{e.Viewers}] " : "";
            Console.WriteLine($"> [HOSTTARGET]{message}");
        }

 

Moved RegisterCaps() in Client before sending NICK & PASS
RegisterCaps() was originally added below NICK & PASS but it wouldn’t trigger the GlobalUserState event so it’s moved up to properly handle that.

await RegisterCaps();
await SendRaw($"PASS {_loginToken}");
await SendRaw($"NICK {LoginName}");

 

Added support for various event handlers
Most IRC commands should now be handled properly in events. They are found in Client.cs. The few missing commands are PING which will not be made into an event (if you have a good argument why it should be added let me know) and WHISPER which will be added another time.

public event EventHandler<GlobalUserState> GlobalUserStateEventHandler;
public event EventHandler<UserNotice> UserNoticeEventHandler;
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments

Related Articles

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

LIVE NOW! CLICK TO VIEW.
CURRENTLY OFFLINE