Esempio n. 1
0
        /// <summary>
        /// Throws an item at a viewer and rates its effectiveness against the victim
        /// </summary>
        /// <param name="chatter">User that sent the message</param>
        private async Task <DateTime> ThrowAsync(TwitchChatter chatter)
        {
            try
            {
                int indexAction = chatter.Message.IndexOf(" ");

                if (chatter.Message.StartsWith("!throw @"))
                {
                    _irc.SendPublicChatMessage($"Please throw an item to a user @{chatter.DisplayName}");
                }
                else
                {
                    string recipient = chatter.Message.Substring(chatter.Message.IndexOf("@") + 1);
                    string item      = chatter.Message.Substring(indexAction, chatter.Message.IndexOf("@") - indexAction - 1);

                    ReactionCommand(_irc, chatter.DisplayName, recipient, $"Stop throwing {item} at yourself", $"throws {item} at", $". {Effectiveness()}");
                    return(DateTime.Now.AddSeconds(20));
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "Gen", "Throw(TwitchChatter)", false, "!throw", chatter.Message);
            }

            return(DateTime.Now);
        }
Esempio n. 2
0
        public override async Task <(bool, DateTime)> ExecCommandAsync(TwitchChatter chatter, string requestedCommand)
        {
            try
            {
                switch (requestedCommand)
                {
                case "!refreshreminders":
                    return(true, await RefreshRemindersAsync());

                case "!refreshbossfight":
                    return(true, await RefreshBossFightAsync());

                case "!refreshcommands":
                    return(true, await RefreshCommandsAsync());

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "ReminderFeature", "ExecCommand(TwitchChatter, string)", false, requestedCommand, chatter.Message);
            }

            return(false, DateTime.Now);
        }
        /// <summary>
        /// Put a cooldown for a user on a command
        /// </summary>
        /// <param name="chatter"></param>
        /// <param name="cooldown"></param>
        public void AddCooldown(TwitchChatter chatter, DateTime cooldown, string command)
        {
            if (cooldown > DateTime.Now)
            {
                _cooldownUsers.Add(new CooldownUser
                {
                    Username = chatter.Username,
                    Cooldown = cooldown,
                    Command  = command,
                    Warned   = false
                });
            }

            if (command == "!wrongsong")
            {
                // Allow the user to request another song in case if cooldown exists
                CooldownUser songRequestCooldown =
                    _cooldownUsers.FirstOrDefault(u => u.Username == chatter.Username && u.Command == "!ytsr");

                if (songRequestCooldown != null)
                {
                    _cooldownUsers.Remove(songRequestCooldown);
                }
            }
        }
Esempio n. 4
0
        public override async Task <(bool, DateTime)> ExecCommandAsync(TwitchChatter chatter, string requestedCommand)
        {
            try
            {
                switch (requestedCommand)
                {
                case "!partyup":
                    return(true, await PartyUpAsync(chatter));

                case "!partyuprequestlist":
                    return(true, await PartyUpRequestListAsync());

                case "!partyuplist":
                    return(true, await PartyUpListAsync());

                case "!poppartyup":
                case "!poppartyuprequest":
                    return(true, await PopPartyUpRequestAsync());

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "PartyUpFeature", "ExecCommand(TwitchChatter, string)", false, requestedCommand, chatter.Message);
            }

            return(false, DateTime.Now);
        }
Esempio n. 5
0
        public override async Task <(bool, DateTime)> ExecCommandAsync(TwitchChatter chatter, string requestedCommand)
        {
            try
            {
                switch (requestedCommand)
                {
                case "!roulette":
                    return(true, await RussianRoulette(chatter));

                case "!bankheist":
                case "!heist":
                    return(true, await BankHeist(chatter));

                case "!raid":
                case "!bossfight":
                    return(true, await BossFight(chatter));

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "MinigameFeature", "ExecCommand(TwitchChatter, string)", false, requestedCommand, chatter.Message);
            }

            return(false, DateTime.Now);
        }
Esempio n. 6
0
        public override async Task <(bool, DateTime)> ExecCommandAsync(TwitchChatter chatter, string requestedCommand)
        {
            try
            {
                switch (requestedCommand)
                {
                case "!srstart":
                    return(true, await StartAsync());

                case "!srstop":
                    return(true, await StopAsync());

                case "!srpause":
                    return(true, await PauseAsync());

                case "!sraod":
                    return(true, await SetAudioOutputDeviceAsync(chatter));

                case "!srshuffle":
                    return(true, await PersonalPlaylistShuffleAsync(chatter));

                case "!srplay":
                    return(true, await PlayAsync());

                case "!srvolume":
                    if ((chatter.Message.StartsWith("!srvolume ")) && HasPermission("!srvolume", DetermineChatterPermissions(chatter), _rolePermissions, true))
                    {
                        return(true, await SetVolumeAsync(chatter));
                    }
                    else if (chatter.Message == "!srvolume")
                    {
                        return(true, await ShowVolumeAsync(chatter));
                    }
                    break;

                case "!srskip":
                    return(true, await Skip(chatter));

                case "!srtime":
                    if ((chatter.Message.StartsWith("!srtime ")) && HasPermission("!srtime", DetermineChatterPermissions(chatter), _rolePermissions, true))
                    {
                        return(true, await SetTimeAsync(chatter));
                    }
                    else if (chatter.Message == "!srtime")
                    {
                        return(true, await ShowTimeAsync(chatter));
                    }
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "LibVLCSharpPlayerFeature", "ExecCommand(TwitchChatter, string)", false, requestedCommand, chatter.Message);
            }

            return(false, DateTime.Now);
        }
Esempio n. 7
0
        private async Task <DateTime> SetGenericIgnAsync(TwitchChatter chatter)
        {
            try
            {
                string message = chatter.Message;
                string gameIgn = message.Substring(message.IndexOf(" ") + 1);

                // Get current game name
                ChannelJSON json = await _twitchInfo.GetBroadcasterChannelByIdAsync();

                string gameTitle = json.Game;

                InGameUsername ign = await _ign.GetInGameUsernameAsync(_broadcasterInstance.DatabaseId);

                if (ign == null)
                {
                    await _ign.CreateInGameUsernameAsync(null, _broadcasterInstance.DatabaseId, gameIgn);

                    _irc.SendPublicChatMessage($"Yay! You've set your generic IGN to \"{gameIgn}\" @{chatter.DisplayName}");
                }
                else
                {
                    ign.Message = gameIgn;
                    await _ign.UpdateInGameUsernameAsync(ign.Id, _broadcasterInstance.DatabaseId, ign);

                    _irc.SendPublicChatMessage($"Yay! You've updated your generic IGN to \"{gameIgn}\" @{chatter.DisplayName}");
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "InGameNameFeature", "SetGenericIgn(TwitchChatter)", false, "!setgenericign", chatter.Message);
            }

            return(DateTime.Now);
        }
Esempio n. 8
0
        /// <summary>
        /// Displays the current song being played from Spotify
        /// </summary>
        /// <param name="chatter">User that sent the message</param>
        public static async Task <string> SpotifyCurrentSongAsync(TwitchChatter chatter, SpotifyWebClient spotify)
        {
            PlaybackContext playbackContext = await spotify.GetPlaybackAsync();

            if (playbackContext != null && playbackContext.IsPlaying)
            {
                string artistName = "";

                foreach (SimpleArtist simpleArtist in playbackContext.Item.Artists)
                {
                    artistName += $"{simpleArtist.Name}, ";
                }

                artistName = artistName.ReplaceLastOccurrence(", ", "");

                TimeSpan progressTimeSpan = TimeSpan.FromMilliseconds(playbackContext.ProgressMs);
                TimeSpan durationTimeSpan = TimeSpan.FromMilliseconds(playbackContext.Item.DurationMs);

                return($"@{chatter.DisplayName} <-- Now playing from Spotify: \"{playbackContext.Item.Name}\" by {artistName} "
                       + "https://open.spotify.com/track/" + playbackContext.Item.Id + " "
                       + $"Currently playing at {progressTimeSpan.ReformatTimeSpan()} of {durationTimeSpan.ReformatTimeSpan()}");
            }
            else
            {
                return($"Nothing is playing at the moment @{chatter.DisplayName}");
            }
        }
Esempio n. 9
0
        public override async Task <(bool, DateTime)> ExecCommandAsync(TwitchChatter chatter, string requestedCommand)
        {
            try
            {
                switch (requestedCommand)
                {
                case "!autotweet":
                    return(true, await SetAutoTweetAsync(chatter));

                case "!tweet":
                    return(true, await TweetAsync(chatter));

                case "!live":
                    return(true, await LiveAsync());

                case "!twitter":
                    return(true, await TwitterLinkAsync());

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "TwitterFeature", "ExecCommand(TwitchChatter, string)", false, requestedCommand, chatter.Message);
            }

            return(false, DateTime.Now);
        }
Esempio n. 10
0
        public async Task CmdLibVLCSharpPlayerVolume(TwitchChatter chatter)
        {
            try
            {
                bool validMessage = int.TryParse(chatter.Message.Substring(chatter.Message.IndexOf(" ") + 1), out int volumePercentage);

                if (validMessage)
                {
                    if (await _libVLCSharpPlayer.SetVolume(volumePercentage))
                    {
                        _irc.SendPublicChatMessage($"Song request volume set to {volumePercentage}% @{chatter.DisplayName}");
                    }
                    else if (volumePercentage < 1 || volumePercentage > 100)
                    {
                        _irc.SendPublicChatMessage($"Please use a value for the song request volume from 1-100 @{chatter.DisplayName}");
                    }
                }
                else
                {
                    _irc.SendPublicChatMessage($"Requested volume not valid. Please set the song request volume from 1-100 @{chatter.DisplayName}");
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "CmdMod", "CmdLibVLCSharpPlayerVolume(TwitchChatter)", false, "!srvolume", chatter.Message);
            }
        }
Esempio n. 11
0
        public async Task CmdLibVLCSharpPlayerSkip(TwitchChatter chatter)
        {
            try
            {
                bool validMessage = int.TryParse(chatter.Message.Substring(chatter.Message.IndexOf(" ") + 1), out int songSkipCount);

                if (!validMessage)
                {
                    await _libVLCSharpPlayer.Skip();
                }
                else
                {
                    await _libVLCSharpPlayer.Skip(songSkipCount);
                }

                string songRequest = _youTubeClientInstance.ShowPlayingSongRequest(_libVLCSharpPlayer.CurrentSongRequestPlaylistItem);

                if (!string.IsNullOrEmpty(songRequest))
                {
                    _irc.SendPublicChatMessage($"@{chatter.DisplayName} <-- Now playing: {songRequest}");
                }
                else
                {
                    _irc.SendPublicChatMessage($"Unable to display the current song @{chatter.DisplayName}");
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "CmdMod", "CmdLibVLCSharpPlayerSkip(TwitchChatter)", false, "!srskip");
            }
        }
        public override async Task <(bool, DateTime)> ExecCommandAsync(TwitchChatter chatter, string requestedCommand)
        {
            try
            {
                switch (requestedCommand)
                {
                case "!msl":
                case "!addmsl":
                    if ((chatter.Message.StartsWith("!msl ") || chatter.Message.StartsWith("!addmsl ")) &&
                        HasPermission("!addmsl", DetermineChatterPermissions(chatter), _rolePermissions))
                    {
                        return(true, await AddUsersAsync(chatter));
                    }
                    else if (chatter.Message == "!msl")
                    {
                        return(true, await ShowLinkAsync(chatter));
                    }
                    break;

                case "!resetmsl":
                    return(true, await ResetLinkAsync(chatter));

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "MultiLinkUserFeature", "ExecCommand(TwitchChatter, string)", false, requestedCommand, chatter.Message);
            }

            return(false, DateTime.Now);
        }
Esempio n. 13
0
        /// <summary>
        /// Reset the MultiStream link to allow the link to be reconfigured
        /// </summary>
        /// <param name="chatter"></param>
        /// <param name="multiStreamUsers">List of users that have already been added to the link</param>
        public async Task <List <string> > CmdResetMultiStreamLink(TwitchChatter chatter, List <string> multiStreamUsers)
        {
            try
            {
                multiStreamUsers = new List <string>();

                string resultMsg = "MultiStream link has been reset. " +
                                   $"Please reconfigure the link if you are planning on using it in the near future @{chatter.Username}";

                if (chatter.Username == _botConfig.Broadcaster.ToLower())
                {
                    _irc.SendPublicChatMessage(resultMsg);
                }
                else
                {
                    _irc.SendPublicChatMessage($"{resultMsg} @{_botConfig.Broadcaster.ToLower()}");
                }

                return(multiStreamUsers);
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "CmdMod", "CmdResetMultiStream(string, ref List<string>)", false, "!resetmsl");
            }

            return(new List <string>());
        }
Esempio n. 14
0
        public override async Task <(bool, DateTime)> ExecCommandAsync(TwitchChatter chatter, string requestedCommand)
        {
            try
            {
                switch (requestedCommand)
                {
                case "!resetjoin":
                    return(true, await ResetJoinAsync(chatter));

                case "!listjoin":
                    return(true, await ListJoinAsync(chatter));

                case "!invite":
                    return(true, await InviteAsync(chatter));

                case "!popjoin":
                    return(true, await PopJoinAsync(chatter));

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "JoinStreamerFeature", "ExecCommand(TwitchChatter, string)", false, requestedCommand, chatter.Message);
            }

            return(true, DateTime.Now);
        }
Esempio n. 15
0
        /// <summary>
        /// Set delay for messages based on the latency of the stream
        /// </summary>
        /// <param name="chatter"></param>
        private async Task <DateTime> SetLatencyAsync(TwitchChatter chatter)
        {
            try
            {
                int  latency      = -1;
                bool isValidInput = int.TryParse(ParseChatterCommandParameter(chatter), out latency);

                if (!isValidInput || latency < 0)
                {
                    _irc.SendPublicChatMessage("Please insert a valid positive alloted amount of time (in seconds)");
                }
                else
                {
                    _botConfig.StreamLatency = latency;
                    SaveAppConfigSettings(latency.ToString(), "streamLatency", _appConfig);

                    _irc.SendPublicChatMessage($"Bot settings for stream latency set to {_botConfig.StreamLatency} second(s) @{chatter.DisplayName}");
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "GeneralFeature", "SetLatency(TwitchChatter)", false, "!setlatency");
            }

            return(DateTime.Now);
        }
Esempio n. 16
0
        public override async Task <(bool, DateTime)> ExecCommandAsync(TwitchChatter chatter, string requestedCommand)
        {
            try
            {
                switch (requestedCommand)
                {
                case "!followsince":
                    return(true, await FollowSinceAsync(chatter));

                case "!rank":
                    return(true, await ViewRankAsync(chatter));

                case "!setregularhours":
                    return(true, await SetRegularFollowerHoursAsync(chatter));

                case "!ranktop3":
                    return(true, await LeaderboardRankAsync(chatter));

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "FollowerFeature", "ExecCommand(TwitchChatter, string)", false, requestedCommand, chatter.Message);
            }

            return(false, DateTime.Now);
        }
Esempio n. 17
0
        /// <summary>
        /// Enables tweets to be sent out from this bot (both auto publish tweets and manual tweets)
        /// </summary>
        private async Task <DateTime> SetAutoTweetAsync(TwitchChatter chatter)
        {
            try
            {
                if (!_twitterInstance.HasCredentials)
                {
                    _irc.SendPublicChatMessage($"You are missing twitter info @{_botConfig.Broadcaster}");
                }
                else
                {
                    string message      = ParseChatterCommandParameter(chatter);
                    bool   enableTweets = SetBooleanFromMessage(message);
                    string boolValue    = enableTweets ? "true" : "false";

                    _botConfig.EnableTweets = true;
                    SaveAppConfigSettings(boolValue, "enableTweets", _appConfig);

                    _irc.SendPublicChatMessage($"@{_botConfig.Broadcaster} : Automatic tweets is set to \"{_botConfig.EnableTweets}\"");
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "TwitterFeature", "EnableTweet()", false, "!sendtweet on");
            }

            return(DateTime.Now);
        }
Esempio n. 18
0
        /// <summary>
        /// Set delay for messages based on the latency of the stream
        /// </summary>
        /// <param name="chatter"></param>
        public async void CmdSetLatency(TwitchChatter chatter)
        {
            try
            {
                int  latency      = -1;
                bool isValidInput = int.TryParse(chatter.Message.Substring(chatter.Message.IndexOf(" ")), out latency);

                if (!isValidInput || latency < 0)
                {
                    _irc.SendPublicChatMessage("Please insert a valid positive alloted amount of time (in seconds)");
                }
                else
                {
                    _botConfig.StreamLatency = latency;
                    _appConfig.AppSettings.Settings.Remove("streamLatency");
                    _appConfig.AppSettings.Settings.Add("streamLatency", latency.ToString());
                    _appConfig.Save(ConfigurationSaveMode.Modified);
                    ConfigurationManager.RefreshSection("TwitchBotConfiguration");

                    _irc.SendPublicChatMessage($"Bot settings for stream latency set to {_botConfig.StreamLatency} second(s) @{chatter.DisplayName}");
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "CmdMod", "CmdSetLatency(TwitchChatter)", false, "!setlatency");
            }
        }
Esempio n. 19
0
        private async Task <DateTime> SetRegularFollowerHoursAsync(TwitchChatter chatter)
        {
            try
            {
                bool validInput = int.TryParse(ParseChatterCommandParameter(chatter), out int regularHours);
                if (!validInput)
                {
                    _irc.SendPublicChatMessage($"I can't process the time you've entered. " +
                                               $"Please insert positive hours @{_botConfig.Broadcaster}");
                    return(DateTime.Now);
                }
                else if (regularHours < 1)
                {
                    _irc.SendPublicChatMessage($"Please insert positive hours @{_botConfig.Broadcaster}");
                    return(DateTime.Now);
                }

                _botConfig.RegularFollowerHours = regularHours;
                _appConfig.AppSettings.Settings.Remove("regularFollowerHours");
                _appConfig.AppSettings.Settings.Add("regularFollowerHours", regularHours.ToString());
                _appConfig.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("TwitchBotConfiguration");

                Console.WriteLine($"Regular followers are set to {_botConfig.RegularFollowerHours}");
                _irc.SendPublicChatMessage($"{_botConfig.Broadcaster} : Regular followers now need {_botConfig.RegularFollowerHours} hours");
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "FollowerFeature", "SetRegularFollowerHours(TwitchChatter)", false, "!setregularhours");
            }

            return(DateTime.Now);
        }
        /// <summary>
        /// Checks if a user/command is on a cooldown from a particular command
        /// </summary>
        /// <param name="command"></param>
        /// <param name="chatter"></param>
        /// <returns></returns>
        public bool IsCommandOnCooldown(string command, TwitchChatter chatter, IrcClient irc, bool hasGlobalCooldown = false)
        {
            CooldownUser cooldown = null;

            if (!hasGlobalCooldown)
            {
                cooldown = _cooldownUsers.FirstOrDefault(u => u.Username == chatter.Username && u.Command == command);
            }
            else
            {
                cooldown = _cooldownUsers.FirstOrDefault(u => u.Command == command);
            }

            if (cooldown == null)
            {
                return(false);
            }
            else if (cooldown.Cooldown < DateTime.Now)
            {
                _cooldownUsers.Remove(cooldown);
                return(false);
            }

            if (!cooldown.Warned)
            {
                string specialCooldownMessage = "";

                // ToDo: Find more graceful way to prevent spam of commands with a global cooldown
                if (!hasGlobalCooldown)
                {
                    cooldown.Warned        = true; // prevent spamming cooldown message per personal cooldown
                    specialCooldownMessage = "a PERSONAL";
                }
                else
                {
                    specialCooldownMessage = "a GLOBAL";
                }

                string   timespanMessage = "";
                TimeSpan timespan        = cooldown.Cooldown - DateTime.Now;

                if (timespan.Minutes > 0)
                {
                    timespanMessage = $"{timespan.Minutes} minute(s) and {timespan.Seconds} second(s)";
                }
                else if (timespan.Seconds == 0)
                {
                    timespanMessage = $"{timespan.Milliseconds} millisecond(s)";
                }
                else
                {
                    timespanMessage = $"{timespan.Seconds} second(s)";
                }

                irc.SendPublicChatMessage($"The {command} command is currently on {specialCooldownMessage} cooldown @{chatter.DisplayName} for {timespanMessage}");
            }

            return(true);
        }
Esempio n. 21
0
        /// <summary>
        /// Parse out the command from the chatter's message
        /// </summary>
        /// <param name="chatter"></param>
        /// <returns></returns>
        protected string ParseChatterCommandName(TwitchChatter chatter)
        {
            int spaceIndex = chatter.Message.IndexOf(" ") > 0
                ? chatter.Message.IndexOf(" ")
                : chatter.Message.Length;

            return(chatter.Message.Substring(0, spaceIndex).ToLower());
        }
Esempio n. 22
0
        /// <summary>
        /// Get the requested username from the chatter's message
        /// </summary>
        /// <param name="chatter"></param>
        /// <returns></returns>
        protected string ParseChatterMessageUsername(TwitchChatter chatter)
        {
            if (chatter.Message.IndexOf("@") > 0)
            {
                return(chatter.Message.Substring(chatter.Message.IndexOf("@") + 1));
            }

            return(chatter.Message.Substring(chatter.Message.IndexOf(" ") + 1));
        }
Esempio n. 23
0
        /// <summary>
        /// Bot-specific timeout on a user for a set amount of time
        /// </summary>
        /// <param name="chatter"></param>
        public async Task CmdAddTimeout(TwitchChatter chatter)
        {
            try
            {
                if (chatter.Message.StartsWith("!addtimeout @"))
                {
                    _irc.SendPublicChatMessage("I cannot make a user not talk to me without this format '!addtimeout [seconds] @[username]'");
                }
                else if (chatter.Message.ToLower().Contains(_botConfig.Broadcaster.ToLower()))
                {
                    _irc.SendPublicChatMessage($"I cannot betray @{_botConfig.Broadcaster} by not allowing him to communicate with me @{chatter.Username}");
                }
                else if (chatter.Message.ToLower().Contains(_botConfig.BotName.ToLower()))
                {
                    _irc.SendPublicChatMessage($"You can't time me out @{chatter.Username} PowerUpL Jebaited PowerUpR");
                }
                else
                {
                    int    indexAction    = chatter.Message.IndexOf(" ");
                    string recipient      = chatter.Message.Substring(chatter.Message.IndexOf("@") + 1).ToLower();
                    double seconds        = -1;
                    bool   isValidTimeout = double.TryParse(chatter.Message.Substring(indexAction, chatter.Message.IndexOf("@") - indexAction - 1), out seconds);

                    if (!isValidTimeout || seconds < 0.00)
                    {
                        _irc.SendPublicChatMessage("The timeout amount wasn't accepted. Please try again with positive seconds only");
                    }
                    else if (seconds < 15.00)
                    {
                        _irc.SendPublicChatMessage("The duration needs to be at least 15 seconds long. Please try again");
                    }
                    else
                    {
                        DateTime timeoutExpiration = await _timeout.AddTimeout(recipient, _broadcasterId, seconds, _botConfig.TwitchBotApiLink);

                        string response = $"I'm told not to talk to you until {timeoutExpiration.ToLocalTime()} ";

                        if (timeoutExpiration.ToLocalTime().IsDaylightSavingTime())
                        {
                            response += $"({TimeZone.CurrentTimeZone.DaylightName})";
                        }
                        else
                        {
                            response += $"({TimeZone.CurrentTimeZone.StandardName})";
                        }

                        _irc.SendPublicChatMessage($"{response} @{recipient}");
                    }
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "CmdMod", "CmdAddTimeout(TwitchChatter)", false, "!addtimeout");
            }
        }
Esempio n. 24
0
        /// <summary>
        /// Updates the game being played on the Twitch channel
        /// </summary>
        /// <param name="chatter"></param>
        /// <param name="hasTwitterInfo">Check for Twitter credentials</param>
        public async Task CmdUpdateGame(TwitchChatter chatter, bool hasTwitterInfo)
        {
            try
            {
                // Get game from command parameter
                string game = chatter.Message.Substring(chatter.Message.IndexOf(" ") + 1);

                // Send HTTP method PUT to base URI in order to change the game
                RestClient  client  = new RestClient("https://api.twitch.tv/kraken/channels/" + _broadcasterInstance.TwitchId);
                RestRequest request = new RestRequest(Method.PUT);
                request.AddHeader("Cache-Control", "no-cache");
                request.AddHeader("Content-Type", "application/json");
                request.AddHeader("Authorization", "OAuth " + _botConfig.TwitchAccessToken);
                request.AddHeader("Accept", "application/vnd.twitchtv.v5+json");
                request.AddHeader("Client-ID", _botConfig.TwitchClientId);
                request.AddParameter("application/json", "{\"channel\":{\"game\":\"" + game + "\"}}",
                                     ParameterType.RequestBody);

                IRestResponse response = null;
                try
                {
                    response = await client.ExecuteTaskAsync <Task>(request);

                    string statResponse = response.StatusCode.ToString();
                    if (statResponse.Contains("OK"))
                    {
                        _irc.SendPublicChatMessage($"Twitch channel game status updated to \"{game}\"");
                        if (_botConfig.EnableTweets && hasTwitterInfo)
                        {
                            Console.WriteLine(_twitter.SendTweet($"Just switched to \"{game}\" on "
                                                                 + $"twitch.tv/{_broadcasterInstance.Username}"));
                        }

                        await Threads.ChatReminder.RefreshReminders();
                    }
                    else
                    {
                        Console.WriteLine(response.Content);
                    }
                }
                catch (WebException ex)
                {
                    if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.BadRequest)
                    {
                        Console.WriteLine("Error 400 detected!!");
                    }
                    response = (IRestResponse)ex.Response;
                    Console.WriteLine("Error: " + response);
                }
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "CmdMod", "CmdUpdateGame(TwitchChatter, bool)", false, "!updategame");
            }
        }
Esempio n. 25
0
 /// <summary>
 /// Tell the stream the specified moderator will be AFK
 /// </summary>
 /// <param name="chatter"></param>
 public async void CmdModAfk(TwitchChatter chatter)
 {
     try
     {
         _irc.SendPublicChatMessage($"@{chatter.DisplayName} is going AFK @{_botConfig.Broadcaster}! SwiftRage");
     }
     catch (Exception ex)
     {
         await _errHndlrInstance.LogError(ex, "CmdMod", "CmdModAfk(string)", false, "!modafk");
     }
 }
Esempio n. 26
0
 /// <summary>
 /// Tell the stream the specified moderator is back
 /// </summary>
 /// <param name="chatter"></param>
 public async void CmdModBack(TwitchChatter chatter)
 {
     try
     {
         _irc.SendPublicChatMessage($"@{chatter.DisplayName} is back @{_botConfig.Broadcaster}! BlessRNG");
     }
     catch (Exception ex)
     {
         await _errHndlrInstance.LogError(ex, "CmdMod", "CmdModBack(string)", false, "!modback");
     }
 }
Esempio n. 27
0
 public string PopJoin(TwitchChatter chatter)
 {
     if (_joinStreamerList.Count == 0)
     {
         return($"Queue is empty @{chatter.DisplayName}");
     }
     else
     {
         string poppedUser = _joinStreamerList.Dequeue();
         return($"{poppedUser} has been removed from the queue @{chatter.DisplayName}");
     }
 }
Esempio n. 28
0
 public async void ClearMessage(TwitchChatter chatter)
 {
     try
     {
         SendIrcMessage(":" + username + "!" + username + "@" + username +
                        ".tmi.twitch.tv PRIVMSG #" + channel + " :/delete " + chatter.MessageId);
     }
     catch (Exception ex)
     {
         await _errHndlrInstance.LogError(ex, "IrcClient", "ClearMessage(TwitchChatter)", false);
     }
 }
Esempio n. 29
0
        /// <summary>
        /// Display the current game/category for the Twitch channel
        /// </summary>
        /// <param name="chatter"></param>
        /// <returns></returns>
        private async Task <DateTime> ShowCurrentTwitchGameAsync(TwitchChatter chatter)
        {
            try
            {
                _irc.SendPublicChatMessage($"We're currently playing \"{TwitchStreamStatus.CurrentCategory}\" @{chatter.DisplayName}");
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "TwitchChannelFeature", "ShowCurrentTwitchGame(TwitchChatter)", false, "!game");
            }

            return(DateTime.Now);
        }
Esempio n. 30
0
        private async Task <DateTime> PopJoinAsync(TwitchChatter chatter)
        {
            try
            {
                _joinStreamerInstance.PopJoin(chatter);
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "JoinStreamerFeature", "PopJoin(TwitchChatter)", false, "!popjoin");
            }

            return(DateTime.Now);
        }