Ejemplo n.º 1
0
        private void crawler2()
        {
            Crawl_HAP     crawl    = new Crawl_HAP();
            List <string> old_list = DataBase.getoldlist();

            try
            {
                crawl.maru_crawl(old_list);
            }
            catch
            {
                wf.WinformLog("@크롤실패");
                return;
            }
            List <maru> maru = crawl.getlist();

            if (!(maru.Count > 0))
            {
                return;
            }
            wf.WinformLog("@크롤");


            string new_title  = maru[0].gettitle();
            string new_domain = maru[0].getdomain();

            string old_title  = DataBase.getold()[0];
            string old_domain = DataBase.getold()[1];



            ulong tmp_server;
            ulong tmp_user;

            for (int i = 0; i < maru.Count; i++)
            {
                if (maru[i].gettitle() == old_title)
                {
                    break;
                }

                for (int j = 0; j < list.Count(); j++)
                {
                    if (maru[i].gettitle().Contains(list[j]))
                    {
                        tmp_server = Convert.ToUInt64(server[j]);
                        tmp_user   = Convert.ToUInt64(user[j]);
                        try
                        {
                            if (discord.GetServer(tmp_server) != null &&
                                discord.GetServer(tmp_server).GetUser(tmp_user) != null)
                            {
                                discord
                                .GetServer(tmp_server)
                                .GetUser(tmp_user)
                                .SendMessage(maru[i].getdomain());
                            }
                        }
                        catch
                        {
                            wf.WinformLog("@메세지 전송 실패");
                            return;
                        }
                    }
                }
            }

            ////////////크롤종료후

            DataBase.setold(new_title, new_domain);

            DataBase.setoldlist(crawl.getalllist());

            wf.WinformOld(new_title, new_domain);
            try
            {
                discord.SetGame(new_title);
            }
            catch
            {
            }
        }
Ejemplo n.º 2
0
        private async Task OnMessageReceivedAsync(SocketMessage s)
        {
            var msg = s as SocketUserMessage;     // Ensure the message is from a user/bot

            if (msg == null)
            {
                return;
            }
            if (msg.Author.Id == _discord.CurrentUser.Id)
            {
                return;                                            // Ignore self when checking commands
            }
            var context = new SocketCommandContext(_discord, msg); // Create the command context

            int argPos = 0;                                        // Check if the message has a valid command prefix

            if (msg.HasStringPrefix("!", ref argPos) ||
                msg.HasMentionPrefix(_discord.CurrentUser, ref argPos))
            {
                var result = msg.Content.ToString();



                var result2 = result.Split(' ');
                var command = result2[0].Substring(1);

                var result3 = "";
                for (int i = 1; i < result2.Length; i++)
                {
                    result3 += result2[i];
                    if (i != result2.Length - 1)
                    {
                        result3 += " ";
                    }
                }
                var innerText = result3;

                var author = msg.Author.Id.ToString();
                var server = msg.Channel.Id.ToString();

                string   list_txt;
                string[] cut_txt;


                switch (command)
                {
                case "님아":
                    await context.Channel.SendMessageAsync("왜요");

                    break;

                case "크롤":
                    #region 크롤
                    await context.Channel.SendMessageAsync("크롤");

                    if (wf.checkPerm(author))
                    {
                        if (gettgl())
                        {
                            await context.Channel.SendMessageAsync(" 종료");

                            settgl(false);
                        }
                        else if (!gettgl())
                        {
                            await context.Channel.SendMessageAsync(" 시작");

                            settgl(true);
                        }
                    }
                    else
                    {
                        await context.Channel.SendMessageAsync("ㄴ");
                    }
                    break;

                    #endregion
                case "추가":
                    #region 추가
                    if (result3 != "" && !result3.Contains("|"))
                    {
                        await context.Channel.SendMessageAsync(
                            "검색어 추가요?\r\n============\r\n");

                        //
                        string[] tmp  = result3.Split('\"');
                        string   tmp2 = "";
                        for (int i = 0; i < tmp.Length; i++)
                        {
                            if (tmp[i] != "\r\n" && tmp[i] != "\n" && tmp[i] != "" && tmp[i].Length < 40)
                            {
                                if (!tmp[i].Contains("<@"))
                                {
                                    db.listadd(tmp[i], author, server);
                                    tmp2 += tmp[i] + "\r\n";
                                }
                            }
                        }
                        await context.Channel.SendMessageAsync(tmp2 +
                                                               "============\r\n됨");

                        db.filesave();
                        await context.Channel.SendMessageAsync("저장함");
                    }
                    #endregion
                    break;

                case "제거":
                    #region 제거
                    if (result3 != "")
                    {
                        string[] tmp  = result3.Split('\"');
                        string   tmp2 = "";
                        for (int i = 0; i < tmp.Length; i++)
                        {
                            if (tmp[i] != "\r\n" && tmp[i] != "\n" && tmp[i] != "" && tmp[i].Length < 40)
                            {
                                if (!tmp[i].Contains("<@"))
                                {
                                    if (db.listfind(tmp[i]) || tmp[i] == "전체")
                                    {
                                        if (db.listdel(tmp[i], author, server))
                                        {
                                            tmp2 += tmp[i] + "\r\n";
                                        }
                                        else
                                        {
                                            tmp2 += tmp[i] + " 이건 님한테 없음\r\n";
                                        }
                                    }
                                    else
                                    {
                                        tmp2 += tmp[i] + "이런거 없음\r\n";
                                    }
                                }
                            }
                        }
                        await context.Channel.SendMessageAsync(
                            "검색어 제거요?\r\n============\r\n"
                            + tmp2 +
                            "============\r\n됨");

                        if (result3 != "전체")
                        {
                            db.filesave();
                            await context.Channel.SendMessageAsync("저장함");
                        }
                        else
                        {
                            await context.Channel.SendMessageAsync("저장은 안했음");
                        }
                    }
                    else
                    {
                        await context.Channel.SendMessageAsync("뭐요");
                    }
                    #endregion
                    break;

                case "강제제거":
                    #region 강제제거

                    if (wf.checkPerm(author))
                    {
                        if (result3 != "")
                        {
                            if (db.listfind(result3) || result3 == "전체")
                            {
                                if (db.listdel(result3, "강제", server))
                                {
                                    await context.Channel.SendMessageAsync(result3 + " 지움");
                                }
                                else
                                {
                                    await context.Channel.SendMessageAsync("이님한테 그런거 없음;");
                                }
                            }
                            else
                            {
                                await context.Channel.SendMessageAsync("그런거 없음;");
                            }
                        }
                        else
                        {
                            await context.Channel.SendMessageAsync("뭐요");
                        }
                    }
                    #endregion
                    break;

                case "리스트":
                    #region 리스트

                    list_txt = makelist(author);
                    cut_txt  = list_txt.Split('|');

                    for (int i = 0; i < cut_txt.Length; i++)
                    {
                        await context.Channel.SendMessageAsync(cut_txt[i]);
                    }
                    #endregion
                    break;

                case "체크":
                    #region 체크

                    if (result3 != "")
                    {
                        await context.Channel.SendMessageAsync("체크요?");

                        var    list = db.list;
                        string sum  = "";
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (db.user[i] == author)
                            {
                                if (result3.Contains(list[i]))
                                {
                                    sum += "\"" + list[i] + "\"" + "\r\n";
                                }
                            }
                        }

                        sum = "============"
                              + "\r\n" + sum
                              + "============" + "\r\n이것들 걸림";

                        await context.Channel.SendMessageAsync(sum);
                    }
                    #endregion
                    break;

                case "검색":
                    #region 검색
                    if (result3 != "")
                    {
                        await context.Channel.SendMessageAsync("검색요?");

                        var    list = db.list;
                        string sum  = "";
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (db.user[i] == author)
                            {
                                if (list[i].Contains(result3))
                                {
                                    sum += "\"" + list[i] + "\"" + "\r\n";
                                }
                            }
                        }

                        sum = "============"
                              + "\r\n" + sum
                              + "============" + "\r\n이렇게 있네요";

                        await context.Channel.SendMessageAsync(sum);
                    }
                    #endregion
                    break;

                case "엿보기":
                    #region 엿보기
                    if (result3 != "")
                    {
                        list_txt = makelist(result3);
                        cut_txt  = list_txt.Split('|');

                        for (int i = 0; i < cut_txt.Length; i++)
                        {
                            await context.Channel.SendMessageAsync(cut_txt[i]);
                        }
                    }
                    #endregion
                    break;

                case "저장":
                    #region 저장
                    if (wf.checkPerm(author))
                    {
                        db.filesave();
                        await context.Channel.SendMessageAsync("저장 완료");
                    }
                    else
                    {
                        await context.Channel.SendMessageAsync("ㄴ");
                    }
                    #endregion
                    break;

                case "뭐봄":
                case "머봄":
                case "뭐함":
                case "머함":
                case "모함":
                case "머해":
                case "뭐해":
                case "모해":
                    #region
                    var domain = Program.form.domainbox.Text;

                    var       dir     = Directory.GetCurrentDirectory() + @"\data";
                    Crawl_HAP crawler = new Crawl_HAP();
                    WebClient client  = new WebClient();

                    //await context.Channel.SendMessageAsync("", false, wf.WinformGetOld());
                    await context.Channel.SendMessageAsync(wf.WinformGetOldString());

                    #endregion
                    break;
                }
            }
        }