예제 #1
0
        public static void Run([QueueTrigger("%TwitterNotifications%", Connection = "TwitchStreamStorage")] TwitchLib.Webhook.Models.Stream StreamEvent, ILogger log)
        {
            log.LogInformation($"TwitterEventHandler processing: {StreamEvent.UserName} type {StreamEvent.Type} started at {StreamEvent.StartedAt}");

            if (StreamEvent.Type != "live")
            {
                log.LogInformation($"TwitterEventHandler Processing event skipped. type: {StreamEvent.Type}");
                return;
            }


            string username;

            if (string.IsNullOrWhiteSpace(StreamEvent.Subscription.TwitterName))
            {
                username = StreamEvent.UserName;
                log.LogInformation($"TwitterEventHandler Stream username {username} will be used");
            }
            else
            {
                username = $"@{StreamEvent.Subscription.TwitterName}";
                log.LogInformation($"TwitterEventHandler Twitter username {username} will be used");
            }

            string streamUri = $"https://twitch.tv/{StreamEvent.UserName}";

            log.LogInformation($"TwitterEventHandler Stream Uri: {streamUri}");

            string myTweet = string.Format(TwitterTweetTemplate, streamUri, username, DateTime.UtcNow.ToString("u"));

            TwitterClient.PublishTweet(myTweet, log);
        }
        public static async Task Run(
            [QueueTrigger("%TwitterEventNotificationsQueue%", Connection = "TwitchStreamStorage")] TwitchScheduledChannelEvent ScheduledEvent,
            ILogger log)
        {
            log.LogInformation($"TwitterScheduledEventNotifier function processed: TwitchName {ScheduledEvent.EventItem.Subscription.TwitchName} TwitterName {ScheduledEvent.EventItem.Subscription.TwitterName} EventID {ScheduledEvent.EventItem.Event.Id} NotificationType {ScheduledEvent.Type}");

            var subscription = ScheduledEvent.EventItem.Subscription;
            var channelEvent = ScheduledEvent.EventItem.Event;
            var eventType    = ScheduledEvent.Type;

            if (eventType == TwitchScheduledChannelEventType.Unknown)
            {
                log.LogInformation($"TwitterScheduledEventNotifier Processing event skipped. TwitchName {ScheduledEvent.EventItem.Subscription.TwitchName} TwitterName {ScheduledEvent.EventItem.Subscription.TwitterName} EventID {ScheduledEvent.EventItem.Event.Id} NotificationType {ScheduledEvent.Type}");
                return;
            }

            string username;

            if (string.IsNullOrWhiteSpace(subscription.TwitterName) || subscription.TwitterName == Utility.NameNullString)
            {
                username = subscription.TwitchName;
                log.LogInformation($"TwitterScheduledEventNotifier Stream username {username} will be used");
            }
            else
            {
                username = $"@{subscription.TwitterName}";
                log.LogInformation($"TwitterScheduledEventNotifier Twitter username {username} will be used");
            }

            string eventUri = $"https://www.twitch.tv/events/{channelEvent.Id}";

            log.LogInformation($"TwitterScheduledEventNotifier Event Uri: {eventUri}");

            string myTweet = string.Format(
                TwitterTweetTemplate,
                eventUri,
                username,
                Utility.TypeStringLookup[eventType],
                channelEvent.StartTime.ToString("u"),
                channelEvent.Title);

            await TwitterClient.PublishTweet(myTweet, log);
        }