예제 #1
0
 private async Task LogUserAsync(StreamWriter writer, ChatReply reply, string replyTo, IServiceProvider services)
 {
     if (reply.Message.Contains(".seen"))
     {
         return;
     }
     try
     {
         string   username = reply.User.Substring(1).Split("!")[0];
         string[] input    = { username, reply.Message, DateTime.Now.ToString() };
         SeenUser seenUser = SeenUser.CreateSeen(input, replyTo);
         using var scope = services.CreateScope();
         SeenUserRepository repository = scope.ServiceProvider.GetRequiredService <SeenUserRepository>();
         await repository.UpsertSeenUser(seenUser);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
예제 #2
0
        public async Task ResolveCommand(StreamWriter writer, ChatReply reply, IServiceProvider services, string botNick)
        {
            string replyTo = GetReplyTo(reply, botNick);

            await LogUserAsync(writer, reply, replyTo, services);

            string[] msg = reply.Message.Split(" ");

            if (IsLike(msg))
            {
                await SendLike(writer, msg, replyTo, services);
            }
            else
            {
                switch (msg[0])
                {
                case ":.test":
                    writer.WriteLine("PRIVMSG " + replyTo + " :asbestos in obstetrics");
                    writer.Flush();
                    break;

                case ":.help":
                    string help;
                    string helpMsg = GetRestOfMessage(msg);
                    if (String.IsNullOrWhiteSpace(helpMsg))
                    {
                        help = CommandRepository.GetCommands();
                    }
                    else
                    {
                        help = CommandRepository.GetCommandString(helpMsg);
                    }

                    writer.WriteLine("PRIVMSG " + replyTo + " " + help);
                    writer.Flush();
                    break;

                case ":.quayle":
                    string quote = DQFactory.GetRandomQuote();
                    writer.WriteLine("PRIVMSG " + replyTo + " " + quote);
                    writer.Flush();
                    break;

                case ":.fight":
                    string fightMsg = GetFirstWordOfMessage(msg);
                    if (!String.IsNullOrWhiteSpace(fightMsg))
                    {
                        string fight = FightFactory.GetFight(fightMsg);
                        writer.WriteLine("PRIVMSG " + replyTo + " " + fight);
                        writer.Flush();
                    }
                    break;

                case ":.hi5":
                    string hi5Msg = GetFirstWordOfMessage(msg);
                    if (!String.IsNullOrWhiteSpace(hi5Msg))
                    {
                        string sender = reply.User.Substring(1).Split("!")[0];
                        string hi5    = HighFiveFactory.GetHighFive(sender, hi5Msg);
                        writer.WriteLine("PRIVMSG " + replyTo + " " + hi5);
                        writer.Flush();
                    }
                    break;

                case ":.we":
                    string msg2 = GetRestOfMessage(msg);
                    using (var scope = services.CreateScope())
                    {
                        WeatherService _s = scope.ServiceProvider.GetRequiredService <WeatherService>();
                        string         r  = await _s.Get(msg2, replyTo);

                        writer.WriteLine(r);
                        writer.Flush();
                    }
                    break;

                case ":.fc":
                    string fcMsg = GetRestOfMessage(msg);
                    using (var scope = services.CreateScope())
                    {
                        ForecastService _s = scope.ServiceProvider.GetRequiredService <ForecastService>();
                        string          r  = await _s.Get(fcMsg, replyTo);

                        writer.WriteLine(r);
                        writer.Flush();
                    }
                    break;

                case ":.yt":
                    string ytMsg = GetRestOfMessage(msg);
                    using (var scope = services.CreateScope())
                    {
                        YouTubeService _s = scope.ServiceProvider.GetRequiredService <YouTubeService>();
                        string         r  = await _s.Get(ytMsg, replyTo);

                        writer.WriteLine(r);
                        writer.Flush();
                    }
                    break;

                case ":.likes":
                    string phrase = GetRestOfMessage(msg).Trim();
                    if (phrase.Length > 0)
                    {
                        using var scope = services.CreateScope();
                        LikeRepository repository = scope.ServiceProvider.GetRequiredService <LikeRepository>();
                        Like           like       = await repository.GeyByKeyAndChannel(phrase, replyTo);

                        string reponse = like?.GetSendMessage() ?? Like.GetNotFoundMessage(replyTo, phrase);
                        writer.WriteLine(reponse);
                        writer.Flush();
                    }
                    break;

                case ":.seen":
                    string seenMsg = GetRestOfMessage(msg);
                    using (var scope = services.CreateScope())
                    {
                        SeenUserRepository repository = scope.ServiceProvider.GetRequiredService <SeenUserRepository>();
                        SeenUser           user       = await repository.GetByKeyAndChannel(seenMsg, replyTo);

                        string response = user?.GetSendMessage() ?? SeenUser.GetNotFoundMessage(replyTo, seenMsg);
                        writer.WriteLine(response);
                        writer.Flush();
                    }
                    break;

                case ":.8ball":
                    string eballQ = GetRestOfMessage(msg).Trim();
                    string eballReply;
                    if (!eballQ.EndsWith("?"))
                    {
                        eballReply = "I can only answer a question";
                    }
                    else
                    {
                        eballReply = EightBallFactory.GetRandomReply();
                    }
                    writer.WriteLine("PRIVMSG " + replyTo + " " + eballReply);
                    writer.Flush();
                    break;

                case ":.remind":
                    string reminderMessage = GetRestOfMessage(msg).Trim();
                    await WriteReminder(writer, reminderMessage, reply, replyTo, services);

                    break;

                default:
                    break;
                }
            }
        }