コード例 #1
0
        private static void StreamServiceProvider_OnMessageReceived(IChatService svc, IChatMessage msg)
        {
            try
            {
                Console.WriteLine($"{msg.Sender.DisplayName}: {msg.Message}");
                Console.WriteLine("NAME:");
                Console.WriteLine(msg.Sender.DisplayName);
                string[] redeemString = msg.Message.Split(new string[] { "redeemed " }, StringSplitOptions.None);
                if (msg is TwitchMessage twitchMsg)
                {
                    int bits = twitchMsg.Bits;
                    if (bits > 0)
                    {
                        StreamlabsEvent streamlabsEvent = new StreamlabsEvent();
                        streamlabsEvent.type              = "bits";
                        streamlabsEvent.message           = new Message[1];
                        streamlabsEvent.message[0]        = new Message();
                        streamlabsEvent.message[0].name   = msg.Sender.UserName;
                        streamlabsEvent.message[0].amount = twitchMsg.Bits.ToString();
                        unitySyncContext.Send(SafeInvokeNormalStreamEvent, streamlabsEvent);
                    }
                }
                if (redeemString.Length > 1)
                {
                    Console.WriteLine(redeemString[1]);
                    Console.WriteLine(redeemString[0]);
                    Console.WriteLine("REDEEMED ^");
                    StreamlabsEvent streamlabsEvent = new StreamlabsEvent();
                    streamlabsEvent.type            = "channelpoints";
                    streamlabsEvent.message         = new Message[1];
                    streamlabsEvent.message[0]      = new Message();
                    streamlabsEvent.message[0].name = redeemString[0].Split(new string[] { "] " }, StringSplitOptions.None)[1].Trim();
                    streamlabsEvent.message[0].channelPointsName = redeemString[1].Trim();
                    unitySyncContext.Send(SafeInvokeStreamEvent, streamlabsEvent);

                    /*foreach (CustomAlert alert in AlertObjectLoader.CustomAlerts)
                     * {
                     *  if(alert.Descriptor.ChannelPointsName.ToLower().Trim() == redeemString[1].ToLower().Trim())
                     *  {
                     *      //StreamlabsEvent labsEvent = new StreamlabsEvent();
                     *      //labsEvent.type = "channelpoints";
                     *      //labsEvent.message[0] = new Message();
                     *      //labsEvent.message[0].name = redeemString[0].Trim();
                     *      //alert.streamEvent = labsEvent;
                     *      //Debug.WriteLine(redeemString[0]);
                     *      //alert.ChannelPointsUser = redeemString[0].Split(new string[] { "] " }, StringSplitOptions.None)[1].Trim();
                     *      //alert.Spawn
                     *  }
                     * }*/
                    //.streamEvent = streamlabsEvent;
                }
                void SafeInvokeStreamEvent(object streamEvent) => OnEvent?.Invoke(streamEvent as StreamlabsEvent);
                void SafeInvokeNormalStreamEvent(object streamEvent) => OnNormalEvent?.Invoke(streamEvent as StreamlabsEvent);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            //Console.WriteLine(msg.ToJson().ToString());
        }
コード例 #2
0
 private void StreamServiceProvider_OnMessageReceived(IChatService svc, IChatMessage msg)
 {
     try
     {
         string[] redeemString = msg.Message.Split(new string[] { "redeemed " }, StringSplitOptions.None);
         if (msg is TwitchMessage twitchMsg)
         {
             int bits = twitchMsg.Bits;
             if (bits > 0)
             {
                 StreamlabsEvent streamlabsEvent = new StreamlabsEvent
                 {
                     Type    = "bits",
                     Message = new Message[1]
                 };
                 streamlabsEvent.Message[0] = new Message
                 {
                     Name   = msg.Sender.UserName,
                     Amount = twitchMsg.Bits.ToString()
                 };
                 _synchronizationContext.Send(SafeInvokeNormalStreamEvent, streamlabsEvent);
             }
         }
         if (redeemString.Length > 1)
         {
             StreamlabsEvent streamlabsEvent = new StreamlabsEvent
             {
                 Type    = "channelpoints",
                 Message = new Message[1]
             };
             streamlabsEvent.Message[0] = new Message
             {
                 Name = redeemString[0].Split(new string[] { "] " }, StringSplitOptions.None)[1].Trim(),
                 ChannelPointsName = redeemString[1].Trim()
             };
             _synchronizationContext.Send(SafeInvokeStreamEvent, streamlabsEvent);
         }
         void SafeInvokeStreamEvent(object streamEvent) => OnEvent?.Invoke(streamEvent as StreamlabsEvent);
         void SafeInvokeNormalStreamEvent(object streamEvent) => OnNormalEvent?.Invoke(streamEvent as StreamlabsEvent);
     }
     catch (Exception e)
     {
         Plugin.Log.Error($"Error when processing received chat message: {e.Message}");
     }
 }