An unofficial Dlive.tv API written in C#
Example usage of the D# API
(There are more events than shown, but I picked out the events I think are most commonly used)
usingSystem;usingDSharp.Dlive;usingDSharp.Dlive.Subscription;usingDSharp.Dlive.Subscription.Chat;namespaceDSharpExamples{classProgram{staticvoidMain(string[]args){SubscriptionmyChatSubscription=Subscription.SubscriptionByDisplayName(myAccountDisplayName);// orSubscriptionmyAlternativChatSubscription=newSubscription(myAccountUsername);myChatSubscription.OnChatEvent+=OnChatMessage;myChatSubscription.Connect();}staticvoidOnChatMessage(ChatMessagemessage){switch(message.EventType){caseChatEventType.MESSAGE:ChatTextMessagetextMessage=messageasChatTextMessage;Console.WriteLine($"[{DateTime.Now}] {textMessage.User.Displayname}: {textMessage.Content}");break;caseChatEventType.GIFT:ChatGiftMessagegiftMessage=messageasChatGiftMessage;Console.WriteLine($"[{DateTime.Now}] {giftMessage.User.Displayname} just gifted a {giftMessage.GiftType}");break;caseChatEventType.FOLLOW:UserChatMessagefollowMessage=messageasUserChatMessage;Console.WriteLine($"[{DateTime.Now}] {followMessage.User.Displayname} just followed");break;caseChatEventType.SUBSCRIPTION:ChatSubscriptionMessagesubMessage=messageasChatSubscriptionMessage;Console.WriteLine($"[{DateTime.Now}] {subMessage.User.Displayname} just subscribed for {subMessage.Months} months");break;caseChatEventType.GIFTSUB:ChatGiftSubscriptionMessagegSubMessage=messageasChatGiftSubscriptionMessage;Console.WriteLine($"[{DateTime.Now}] {gSubMessage.GiftingUser.Displayname} just gifted {gSubMessage.Months} months of subscription to {gSubMessage.ReceivingUser.Displayname}");break;caseChatEventType.HOST:ChatHostMessagehostMessage=messageasChatHostMessage;Console.WriteLine($"[{DateTime.Now}] {hostMessage.User.Displayname} just hosted with {hostMessage.Viewers} viewers");break;}}}}(Again, there are many more mutations than just sending messages, but I believe this is the most common use case)
usingDSharp.Dlive;namespaceDSharpExamples{classProgram{staticvoidMain(string[]args){DliveAccountmyAccount=newDliveAccount("Your Dlive user token");myAccount.Mutation.SendChatMessage("channelToSendMessageTo","Message to send");}}}All mutations require usernames to be supplied where identifiers are needed. In order to easily convert a display name into a username, the following utility method can be used.
usingDSharp.Utility;namespaceDSharpExamples{classProgram{staticvoidMain(string[]args){stringdisplayName=Util.DliveUsernameToDisplayName("blockchain username");// or the other waystringusername=Util.DliveDisplayNameToUsername("Dlive display name");}}}usingDSharp.Dlive;usingDSharp.Dlive.Query;namespaceDSharpExamples{classProgram{staticvoidMain(string[]args){DliveAccountmyAccount=newDliveAccount("Your Dlive user token");UserDatamyAccountInfo=myAccount.Query.GetMyInfo();// Get your follower countConsole.WriteLine(myAccountInfo.Public.NumFollowers);// Get your subscriber countConsole.WriteLine(myAccountInfo.Private.SubscriberCount);// GetMyInfo returns both your public and private info// and can be accessed as shown above// It is also possible to use public queries without using an accountPublicUserDatapublicUser=PublicQuery.GetPublicInfoByDisplayname("Dlive display name");// orPublicUserDataalternativePublicUser=PublicQuery.GetPublicInfo("blockchain username");// Both methods return the same (public) data, the examples are just to show that you can access the// information in multiple ways}}}