public static void Handle(TwitchBot twitchBot, ChatMessage chatMessage, string alias)
 {
     if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel), @"\s\w+")))
     {
         twitchBot.SendLastMessage(chatMessage, chatMessage.GetLowerSplit()[1]);
     }
 }
Example #2
0
    private void HandleAfkCommand(TwitchChatMessage chatMessage)
    {
        foreach (AfkCommandType type in AfkCommandTypes)
        {
            // ReSharper disable once ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator
            foreach (string alias in AppSettings.CommandList[type].Alias)
            {
                Regex pattern = PatternCreator.Create(alias, chatMessage.Channel.Prefix, @"(\s|$)");

                // ReSharper disable once InvertIf
                if (pattern.IsMatch(chatMessage.Message))
                {
                    if (CooldownController.IsOnAfkCooldown(chatMessage.UserId))
                    {
                        return;
                    }

                    AfkCommandHandler.Handle(chatMessage, type);
                    CooldownController.AddAfkCooldown(chatMessage.UserId);
                    TwitchBot.CommandCount++;
                    return;
                }
            }
        }
    }
 public static void Handle(TwitchBot twitchBot, ChatMessage chatMessage, string alias)
 {
     if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel), @"\s.+")))
     {
         twitchBot.SendCompilerResult(chatMessage);
     }
 }
Example #4
0
    public override void Handle()
    {
        Regex pattern = PatternCreator.Create(Alias, ChatMessage.Channel.Prefix, @"\s.+");

        if (pattern.IsMatch(ChatMessage.Message))
        {
            Response = $"{ChatMessage.Username}, {HttpRequest.GetGoLangOnlineCompilerResult(ChatMessage.Message[(ChatMessage.Split[0].Length + 1)..])}";
Example #5
0
 public static void Handle(TwitchBot twitchBot, ChatMessage chatMessage, string alias)
 {
     if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel), @"\s\S+\s" + Pattern.TimeSplitPattern + @"\s" + Pattern.TimeSplitPattern + @"(\s|$)")))
     {
         twitchBot.SendCreatedNuke(chatMessage, chatMessage.GetLowerSplit()[1], TimeHelper.ConvertStringToSeconds(new() { chatMessage.GetLowerSplit()[2] }), TimeHelper.ConvertStringToMilliseconds(new() { chatMessage.GetLowerSplit()[3] }));
     }
 }
Example #6
0
    public override void Handle()
    {
        Regex pattern = PatternCreator.Create(Alias, ChatMessage.Channel.Prefix);

        if (pattern.IsMatch(ChatMessage.Message))
        {
            string       channel      = ChatMessage.LowerSplit.Length > 1 ? ChatMessage.LowerSplit[1] : ChatMessage.Channel.Name;
            DottedNumber chatterCount = HttpRequest.GetChatterCount(channel);
            Response = $"{ChatMessage.Username}, ";

            switch (chatterCount)
            {
            case > 1:
                Response += $"there are {chatterCount} chatters in the channel of {channel}";
                break;

            case > 0:
                Response += $"there is {chatterCount} chatter in the channel of {channel}";
                break;

            default:
                Response += $"there are no chatters in the channel of {channel}";
                break;
            }
            return;
        }
    }
Example #7
0
 public static void Handle(TwitchBot twitchBot, ChatMessage chatMessage, string alias)
 {
     if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel), @"\s\w+(\s\S+)?")))
     {
         twitchBot.SendFuck(chatMessage);
     }
 }
Example #8
0
    public override void Handle()
    {
        Regex  channelPattern = PatternCreator.Create(Alias, ChatMessage.Channel.Prefix, @"\s\w+");
        Stream?stream;

        Response = $"{ChatMessage.Username}, ";

        if (channelPattern.IsMatch(ChatMessage.Message))
        {
            stream = TwitchApi.GetStream(ChatMessage.Split[1]);
        }
        else
        {
            stream = TwitchApi.GetStream(ChatMessage.ChannelId);
        }

        if (stream is null)
        {
            Response += "this channel is currently not streaming";
            return;
        }
        Response += $"{stream.UserName} is currently streaming {stream.GameName} with {stream.ViewerCount} viewer{(stream.ViewerCount > 1 ? 's' : string.Empty)} for ";
        TimeSpan streamSpan   = stream.StartedAt.Subtract(DateTime.Now);
        long     milliseconds = streamSpan.TotalMilliseconds.ToLong() + TimeHelper.Now();

        if (!DateTime.Now.IsDaylightSavingTime())
        {
            milliseconds += new Hour().Milliseconds;
        }
        string streamTime = TimeHelper.GetUnixDifference(milliseconds).ToString();

        Response += streamTime;
        return;
    }
Example #9
0
    public override void Handle()
    {
        Regex pattern = PatternCreator.Create(Alias, ChatMessage.Channel.Prefix, @"\s\S{3,}");

        if (pattern.IsMatch(ChatMessage.Message))
        {
            DbController.AddSugestion(ChatMessage, ChatMessage.Message[ChatMessage.LowerSplit[0].Length..]);
Example #10
0
    public override void Handle()
    {
        Regex pattern = PatternCreator.Create(Alias, ChatMessage.Channel.Prefix, @"\s\S+$");
        if (pattern.IsMatch(ChatMessage.Message))
        {
            Response = $"{ChatMessage.Username}, {SpotifyRequest.AddToQueue(ChatMessage.Channel.Name, ChatMessage.Split[1]).Result}";
            return;
        }

        pattern = PatternCreator.Create(Alias, ChatMessage.Channel.Prefix, "\s\w+\s\w+");
        if(pattern.IsMatch(ChatMessage.Message))
        {
            if (DbController.DoesSpotifyUserExist(ChatMessage.Split[2]))
            {
                Response = $"{ChatMessage.Username}, {SpotifyRequest.AddToQueue(ChatMessage.LowerSplit[1], SpotifyRequest.GetCurrentlyPlayingTrack(ChatMessage.Split[2]), false).Result};
            }
        }

        pattern = PatternCreator.Create(Alias, ChatMessage.Channel.Prefix, @"\s\w+\s\S+");
        if (pattern.IsMatch(ChatMessage.Message))
        {
            Response = $"{ChatMessage.Username}, {SpotifyRequest.AddToQueue(ChatMessage.LowerSplit[1], ChatMessage.Split[2], false).Result}";
        }
    }
}
 public static void Handle(TwitchBot twitchBot, ChatMessage chatMessage, string alias)
 {
     if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel), @"\s\S{3,}")))
     {
         twitchBot.SendSuggestionNoted(chatMessage);
     }
 }
Example #12
0
    public override void Handle()
    {
        Regex afkPattern = PatternCreator.Create(Alias, ChatMessage.Channel.Prefix, @"\safk\s\w+");

        if (afkPattern.IsMatch(ChatMessage.Message))
        {
            Response = $"{ChatMessage.Username}, ";
            string username = ChatMessage.LowerSplit[2];
            int?   userId   = TwitchApi.GetUserId(username);
            if (userId is null)
            {
                Response += PredefinedMessages.UserNotFoundMessage;
                return;
            }

            UserNew?user = DbController.GetUser(userId.Value, username);
            if (user is null)
            {
                Response += PredefinedMessages.UserNotFoundMessage;
                return;
            }

            if (user.IsAfk == true)
            {
                Response += new AfkMessage(userId.Value).GoingAway !;
                string message = user.AfkMessage.Decode();
                if (!string.IsNullOrEmpty(message))
                {
                    Response += $": {message}";
                }
                Response += $" ({TimeHelper.GetUnixDifference(user.AfkTime)} ago)";
            }
            else
            {
                Response += $"{username} is not afk";
            }
            return;
        }

        Regex reminderPattern = PatternCreator.Create(Alias, ChatMessage.Channel.Prefix, @"\sreminder\s\d+");

        if (reminderPattern.IsMatch(ChatMessage.Message))
        {
            Response = $"{ChatMessage.Username}, ";
            int      id       = ChatMessage.Split[2].ToInt();
            Reminder?reminder = DbController.GetReminder(id);
            if (reminder is null)
            {
                Response += PredefinedMessages.ReminderNotFoundMessage;
                return;
            }

            Response += $"From: {reminder.GetAuthor()} || To: {reminder.GetTarget()} || ";
            Response += $"Set: {TimeHelper.GetUnixDifference(reminder.Time)} ago || ";
            Response += reminder.ToTime > 0 ? $"Fires in: {TimeHelper.GetUnixDifference(reminder.ToTime)} || " : string.Empty;
            Response += $"Message: {reminder.Message.Decode()}";
            return;
        }
    }
Example #13
0
    public override void Handle()
    {
        Regex pattern = PatternCreator.Create(Alias, ChatMessage.Channel.Prefix, @"\s\S+");

        if (pattern.IsMatch(ChatMessage.Message))
        {
            List <string> messageParts = new();
            string[]      split        = ChatMessage.Split[1..];
Example #14
0
 public static void Handle(TwitchBot twitchBot, ChatMessage chatMessage, string alias)
 {
     if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel), @"\s#?\w+")))
     {
         if (chatMessage.Username == Resources.Owner)
         {
             twitchBot.JoinChannel(chatMessage.GetLowerSplit()[1]);
         }
     }
 }
Example #15
0
    public override void Handle()
    {
        Regex prefixPattern = PatternCreator.Create(Alias, ChatMessage.Channel.Prefix, @"\sprefix\s\S+");

        if (prefixPattern.IsMatch(ChatMessage.Message))
        {
            Response = $"{ChatMessage.Username}, ";
            if (ChatMessage.IsModerator || ChatMessage.IsBroadcaster)
            {
                string prefix = ChatMessage.LowerSplit[2][..(ChatMessage.LowerSplit[2].Length > AppSettings.MaxPrefixLength
Example #16
0
    public override void Handle()
    {
        Regex pattern = PatternCreator.Create(Alias, ChatMessage.Channel.Prefix, @"\s\w+(\s\S+)?");

        if (!pattern.IsMatch(ChatMessage.Message))
        {
            string target = ChatMessage.LowerSplit[1];
            string emote  = ChatMessage.LowerSplit.Length > 2 ? ChatMessage.Split[2] : string.Empty;
            Response = $"{Emoji.PointRight} {Emoji.Bed} {ChatMessage.Username} tucked {target} to bed {emote}".Trim();
        }
    }
Example #17
0
    public override void Handle()
    {
        Regex prefixPattern = PatternCreator.Create(Alias, ChatMessage.Channel.Prefix, @"\sprefix");

        if (prefixPattern.IsMatch(ChatMessage.Message))
        {
            Response = $"{ChatMessage.Username}, ";
            if (ChatMessage.IsModerator || ChatMessage.IsBroadcaster)
            {
                ChatMessage.Channel.Prefix = null;
                Response += "the prefix has been unset";
            }
            else
            {
                Response += PredefinedMessages.NoModOrBroadcasterMessage;
            }
            return;
        }

        Regex reminderPattern = PatternCreator.Create(Alias, ChatMessage.Channel.Prefix, @"\sreminder\s\d+");

        if (reminderPattern.IsMatch(ChatMessage.Message))
        {
            Response = $"{ChatMessage.Username}, ";
            int  reminderId = ChatMessage.Split[2].ToInt();
            bool removed    = DbController.RemoveReminder(ChatMessage, reminderId);
            if (removed)
            {
                Response += "the reminder has been unset";
            }
            else
            {
                Response += "the reminder couldn't be unset";
            }
            return;
        }

        Regex emotePattern = PatternCreator.Create(Alias, ChatMessage.Channel.Prefix, @"\semote");

        if (emotePattern.IsMatch(ChatMessage.Message))
        {
            Response = $"{ChatMessage.Username}, ";
            if (ChatMessage.IsModerator || ChatMessage.IsBroadcaster)
            {
                ChatMessage.Channel.Emote = AppSettings.DefaultEmote;
                Response += "unset emote";
            }
            else
            {
                Response += PredefinedMessages.NoModOrBroadcasterMessage;
            }
            return;
        }
    }
 public static void Handle(TwitchBot twitchBot, ChatMessage chatMessage, string alias)
 {
     if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel), @"\s\w+")))
     {
         twitchBot.Send(chatMessage.Channel, $"{Emoji.PointRight} {chatMessage.GetLowerSplit()[1]}, here you can find a list of commands and the repository: {Resources.GitHubRepoLink}");
     }
     else if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel))))
     {
         twitchBot.Send(chatMessage.Channel, $"{Emoji.PointRight} {chatMessage.Username}, here you can find a list of commands and the repository: {Resources.GitHubRepoLink}");
     }
 }
 public static void Handle(TwitchBot twitchBot, ChatMessage chatMessage, string alias)
 {
     if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel), @"\s\w+")))
     {
         twitchBot.SendSpotifyCurrentlyPlaying(chatMessage);
     }
     else if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel))))
     {
         twitchBot.SendSpotifyCurrentlyPlaying(chatMessage);
     }
 }
Example #20
0
    public override void Handle()
    {
        Regex pattern = PatternCreator.Create(Alias, ChatMessage.Channel.Prefix, @"\s\w+");

        if (pattern.IsMatch(ChatMessage.Message))
        {
            string response = Task.Run(async() => await SpotifyRequest.ListenTo(ChatMessage.Username, ChatMessage.LowerSplit[1])).Result;
            Response = $"{ChatMessage.Username}, {response}";
            return;
        }
    }
Example #21
0
 public static void Handle(TwitchBot twitchBot, ChatMessage chatMessage, string alias)
 {
     _chatMessage = chatMessage;
     if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel), Pattern.ReminderInTimePattern)))
     {
         twitchBot.SendSetTimedReminder(chatMessage, GetTimedRemindMessage(), GetToTime());
     }
     else if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel), @"\s\w+(\s\S+)*")))
     {
         twitchBot.SendSetReminder(chatMessage, GetRemindMessage());
     }
 }
Example #22
0
    public override void Handle()
    {
        Regex pattern = PatternCreator.Create(Alias, ChatMessage.Channel.Prefix, @"\s\w+(\s\S+)?");

        if (pattern.IsMatch(ChatMessage.Message))
        {
            Response = $"{Emoji.PointRight} {Emoji.OkHand} {ChatMessage.Username} f****d {ChatMessage.Split[1]}";
            if (ChatMessage.Split.Length > 2)
            {
                Response += $" {ChatMessage.Split[2]}";
            }
            return;
        }
    }
 public static void Handle(TwitchBot twitchBot, ChatMessage chatMessage, string alias)
 {
     if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel), @"\s\w+\s#?\w+")))
     {
         twitchBot.SendRandomMessage(chatMessage, chatMessage.GetLowerSplit()[1], chatMessage.GetLowerSplit()[2].ReplaceHashtag());
     }
     else if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel), @"\s\w+")))
     {
         twitchBot.SendRandomMessage(chatMessage, chatMessage.GetLowerSplit()[1]);
     }
     else if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel))))
     {
         twitchBot.SendRandomMessage(chatMessage);
     }
 }
 public static void Handle(TwitchBot twitchBot, ChatMessage chatMessage, string alias)
 {
     if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel), @"\s\w+\s\S+")))
     {
         twitchBot.Send(chatMessage.Channel, GenerateMessage(chatMessage.Username, chatMessage.GetLowerSplit()[1], chatMessage.GetSplit()[2]));
     }
     else if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel), @"\s\w+")))
     {
         twitchBot.Send(chatMessage.Channel, GenerateMessage(chatMessage.Username, chatMessage.GetLowerSplit()[1]));
     }
     else
     {
         twitchBot.Send(chatMessage.Channel, $"{chatMessage.Username}, who do you want to tuck?");
     }
 }
Example #25
0
 public static void Handle(TwitchBot twitchBot, ChatMessage chatMessage, string alias)
 {
     if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel), @"\sprefix")))
     {
         twitchBot.SendUnsetPrefix(chatMessage);
     }
     else if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel), @"\sreminder\s\d+")))
     {
         twitchBot.SendUnsetReminder(chatMessage);
     }
     else if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel), @"\semote")))
     {
         twitchBot.SendUnsetEmoteInFront(chatMessage);
     }
 }
Example #26
0
 public static void Handle(TwitchBot twitchBot, ChatMessage chatMessage, string alias)
 {
     if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel), @"\sffz(\s((\d+)|(\w+(\s\d+)?)))?")))
     {
         twitchBot.SendFFZEmotes(chatMessage);
     }
     else if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel), @"\sbttv(\s((\d+)|(\w+(\s\d+)?)))?")))
     {
         twitchBot.SendBTTVEmotes(chatMessage);
     }
     else if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel), @"\s7tv(\s((\d+)|(\w+(\s\d+)?)))?")))
     {
         twitchBot.Send7TVEmotes(chatMessage);
     }
 }
Example #27
0
    public override void Handle()
    {
        Response = $"{ChatMessage.Username}, ";
        Regex pattern = PatternCreator.Create(Alias, ChatMessage.Channel.Prefix, @"\s\w+");

        if (pattern.IsMatch(ChatMessage.Message))
        {
            string username = ChatMessage.LowerSplit[1];
            string?userId   = TwitchApi.GetUserId(username)?.ToString();
            Response += userId ?? PredefinedMessages.TwitchUserDoesntExistMessage;
        }
        else
        {
            Response += ChatMessage.UserId.ToString();
        }
    }
Example #28
0
    public override void Handle()
    {
        Regex pattern = PatternCreator.Create(Alias, ChatMessage.Channel.Prefix, @"\s\S+");

        if (pattern.IsMatch(ChatMessage.Message))
        {
            JCommand?command = AppSettings.CommandList.FindCommand(ChatMessage.LowerSplit[1]);
            if (command is null)
            {
                Response = $"{ChatMessage.Username}, no matching command found";
                return;
            }

            Response = $"{ChatMessage.Username}, https://github.com/Sterbehilfe/OkayegTeaTimeCSharp/blob/master/OkayegTeaTime/Twitch/Commands/CommandClasses/{command.Name}Command.cs";
        }
    }
Example #29
0
 public static void Handle(TwitchBot twitchBot, ChatMessage chatMessage)
 {
     if (MessageHelper.IsCommand(chatMessage))
     {
         ((CommandType[])Enum.GetValues(typeof(CommandType))).ToList().ForEach(type =>
         {
             if (chatMessage.MatchesAnyAlias(type))
             {
                 if (!BotActions.IsOnCooldown(chatMessage.Username, type))
                 {
                     CommandHelper.GetCommand(type).Alias.ForEach(alias =>
                     {
                         if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel), @"(\s|$)")))
                         {
                             BotActions.AddUserToCooldownDictionary(chatMessage.Username, type);
                             Type.GetType(CommandHelper.GetCommandClassName(type)).GetMethod(_handleName).Invoke(null, new object[] { twitchBot, chatMessage, alias });
                             BotActions.AddCooldown(chatMessage.Username, type);
                         }
                     });
                 }
             }
         });
         twitchBot.CommandCount++;
     }
     else if (MessageHelper.IsAfkCommand(chatMessage))
     {
         ((AfkCommandType[])Enum.GetValues(typeof(AfkCommandType))).ToList().ForEach(type =>
         {
             if (chatMessage.MatchesAnyAlias(type))
             {
                 if (!BotActions.IsOnAfkCooldown(chatMessage.Username))
                 {
                     CommandHelper.GetAfkCommand(type).Alias.ForEach(alias =>
                     {
                         if (chatMessage.GetMessage().IsMatch(PatternCreator.Create(alias, PrefixHelper.GetPrefix(chatMessage.Channel), @"(\s|$)")))
                         {
                             BotActions.AddUserToAfkCooldownDictionary(chatMessage.Username);
                             AfkCommandHandler.Handle(twitchBot, chatMessage, type);
                             BotActions.AddAfkCooldown(chatMessage.Username);
                         }
                     });
                 }
             }
         });
         twitchBot.CommandCount++;
     }
 }
Example #30
0
    public override void Handle()
    {
        Regex pattern = PatternCreator.Create(Alias, ChatMessage.Channel.Prefix);

        if (pattern.IsMatch(ChatMessage.Message))
        {
            Response = $"{ChatMessage.Username}, ";
            if (ChatMessage.IsModerator || ChatMessage.IsBroadcaster)
            {
                Response += SpotifyRequest.SkipToNextSong(ChatMessage.Channel.Name).Result;
            }
            else
            {
                Response += "you have to be a mod or the broadcaster to skip the song";
            }
        }
    }