public void WinformProg(data DataBase)
        {
            if (form.InvokeRequired)
            {
                if (form.Pgb.Value < 100)
                {
                    form.BeginInvoke(new Action(() => form.Pgb.PerformStep()));
                }
                else
                {
                    form.BeginInvoke(new Action(() => form.Pgb.Value = 0));
                    form.BeginInvoke(new Action(() => form.Log.Clear()));
                    DataBase.filesave();
                }
            }
            else
            {
                if (form.Pgb.Value < 100)
                {
                    form.Pgb.PerformStep();
                }
                else
                {
                    form.Pgb.Value = 0;
                    form.Log.Clear();
                    DataBase.filesave();

                    //DataBase.backup();
                }
            }
        }
Beispiel #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     Database.filesave();
 }
Beispiel #3
0
        static void crawler3()
        {
            while (true)
            {
                progress();
                Thread.Sleep(10000);

                if (tgl_crawl)
                {
                    #region crawler2

                    List <string> old_list = DB.getoldlist();

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

                    try
                    {
                        //crawl.maru_crawl(old_list);

                        if (form.cb.Checked)
                        {
                            crawl.direct_crwal(old_list, form);
                        }
                        else
                        {
                            crawl.maru_crawl(old_list);
                        }
                    }
                    catch
                    {
                        wf.WinformLog("@크롤링 실패");
                        continue;
                    }


                    List <maru> maru = crawl.getlist();

                    if (!(maru.Count > 0))
                    {
                        wf.WinformOld(old_title, old_domain);

                        try
                        {
                            discordclient.SetGameAsync(old_title);
                        }
                        catch
                        {
                            wf.WinformLog("@타이틀 배치 실패");
                        }

                        continue;
                    }


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


                    ulong tmp_server;
                    ulong tmp_user;

                    try
                    {
                        discordclient.SetGameAsync(new_title);
                    }
                    catch
                    {
                        wf.WinformLog("@타이틀 배치 실패");
                    }



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

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

                        for (int j = 0; j < list.Count(); j++)
                        {
                            if (new_title.Contains(list[j]))
                            {
                                tmp_server = Convert.ToUInt64(server[j]);
                                tmp_user   = Convert.ToUInt64(user[j]);



                                if (discordclient.GetChannel(tmp_server) != null &&
                                    discordclient.GetChannel(tmp_server).GetUser(tmp_user) != null)
                                {
                                    int fail = 0;//성공
                                    do
                                    {
                                        try
                                        {
                                            SendDM(discordclient
                                                   .GetChannel(tmp_server)
                                                   .GetUser(tmp_user),
                                                   new_title, Properties.Settings.Default.URL + new_domain);


                                            wf.WinformLog("@" + discordclient.GetUser(tmp_user) + "가 " + new_title + "를 받음\n");
                                        }
                                        catch
                                        {
                                            wf.WinformLog("@메세지 전송 실패\n");
                                            fail++;
                                        }
                                        finally
                                        {
                                            fail = 0;
                                        }
                                    } while (0 < fail && fail < 10);//1~최대10회 실패동안 반복

                                    Thread.Sleep(1000);
                                }
                            }
                        }
                    }
                    ////////////크롤종료후

                    wf.WinformOld(new_title, Properties.Settings.Default.URL + new_domain);
                    DB.setold(new_title, new_domain);
                    DB.setoldlist(crawl.getalllist());
                    DB.filesave();

                    #endregion
                }
            }
        }
Beispiel #4
0
        public Robot(string Token, Form1 form)
        {
            this.token = Token;
            this.form  = form;
            wf         = form.getWF();
            worker     = new Thread(new ThreadStart(crawling));
            worker.Start();

            DataBase = form.getDB();
            dbload();
            wf.WinformOld(DataBase.getold()[0], DataBase.getold()[1]);


            discord = new DiscordClient(x =>
            {
                x.LogLevel   = LogSeverity.Info;
                x.LogHandler = Log;
            });

            discord.UsingCommands(x =>
            {
                x.PrefixChar         = '!';
                x.AllowMentionPrefix = true;
            });
            var commands = discord.GetService <CommandService>();

            ////////////////////////////////////////////////////////////////////

            /*
             * commands.CreateCommand("여기").Do(async (e) =>
             * {
             *  DataBase.setchan(e.Channel.Id,e.User.Id.ToString());
             *  string imsi = File.ReadAllText(DataBase.getdirection() + @"\" + e.User.Id.ToString() + ".txt");
             *  Channel here = discord.GetChannel(Convert.ToUInt64(imsi));
             *  await here.SendMessage(
             *      here.ToString() + "여기 있으면 됨?");
             * });
             */

            commands.CreateCommand("크롤").Do(async(e) =>
            {
                if (wf.checkPerm(e.User.Id.ToString()))
                {
                    if (tgl_crawl)
                    {
                        //Console.WriteLine("@크롤" + crawlonline);
                        tgl_crawl = false;
                        wf.WinformLog("@크롤" + tgl_crawl);
                        discord.SetGame(null);
                        await e.Channel.SendMessage("크롤 종료");
                    }
                    else
                    {
                        //Console.WriteLine("@크롤"+crawlonline);
                        tgl_crawl = true;
                        wf.WinformLog("@크롤" + tgl_crawl);
                        await e.Channel.SendMessage("크롤 시작");
                    }
                }
                else
                {
                    await e.Channel.SendMessage("s");
                }
            });

            commands.CreateCommand("짭비님")
            .Alias(new string[] { "짭비", "님아" })
            .Do(async(e) =>
            {
                //Console.WriteLine("@짭비님");
                wf.WinformLog("@짭비님");

                await e.Channel.SendMessage($"{e.User.Name}님 왜요");
                await e.Channel.SendMessage($"{e.User.Mention}");
                await e.Channel.SendMessage("");
            });

            commands.CreateCommand("뭐함")
            .Alias(new string[] { "뭐해", "뭐해요", "뭐해여", "머해", "머해요", "머해여", "머함" })
            .Do(async(e) =>
            {
                await e.Channel.SendMessage($"{discord.CurrentGame.Name} 이거 봄");
            });

            commands.CreateCommand("추가")
            .Parameter("this", ParameterType.Unparsed)
            .Do(async(e) =>
            {
                string msg = e.GetArg("this");
                if (msg != null)
                {
                    await e.Channel.SendMessage("검색어 추가요?");
                    string[] tmp = msg.Split('\"');
                    string tmp2  = "";
                    for (int i = 0; i < tmp.Length; i++)
                    {
                        if (tmp[i] != "\r\n" && tmp[i] != "\n" && tmp[i] != "" && tmp[i].Length < 25)
                        {
                            if (!tmp[i].Contains("<@"))
                            {
                                DataBase.listadd(tmp[i], e.User.Id.ToString(), e.Server.Id.ToString());
                                tmp2 += tmp[i] + "\r\n";
                            }
                        }
                    }
                    await e.Channel.SendMessage("============" + "\r\n" + tmp2 + "============" + "\r\n" + "됨");
                    dbload();
                }
                else
                {
                    await e.Channel.SendMessage("뭐요");
                }
            });
            commands.CreateCommand("제거")
            .Alias(new string[] { "삭제" })
            .Parameter("this", ParameterType.Unparsed)
            .Do(async(e) =>
            {
                string msg = e.GetArg("this");
                if (msg != null)
                {
                    await e.Channel.SendMessage(msg + "요?");
                    if (DataBase.listfind(msg) || msg == "전체")
                    {
                        if (DataBase.listdel(msg, e.User.Id.ToString(), e.Server.Id.ToString()))
                        {
                            await e.Channel.SendMessage(msg + "지움");
                            dbload();
                        }
                        else
                        {
                            await e.Channel.SendMessage("님한테 그런거 없음;");
                        }
                    }
                    else
                    {
                        await e.Channel.SendMessage("그런거 없음;");
                    }
                }
                else
                {
                    await e.Channel.SendMessage("뭐요");
                }
            });
            commands.CreateCommand("저장")
            .Alias(new string[] { "세이브" })
            .Do(async(e) =>
            {
                if (wf.checkPerm(e.User.Id.ToString()))
                {
                    await e.Channel.SendMessage("db 저장하면됨?" + "\n" + "알씀");
                    DataBase.filesave();
                }
                else
                {
                    await e.Channel.SendMessage("싫음");
                }
            });
            commands.CreateCommand("백업")
            .Do(async(e) =>
            {
                if (wf.checkPerm(e.User.Id.ToString()))
                {
                    await e.Channel.SendMessage("db 백업하면됨?" + "\n" + "알씀");
                    DataBase.backup();
                }
                else
                {
                    await e.Channel.SendMessage("귀찮음");
                }
            });
            commands.CreateCommand("불러오기")
            .Alias(new string[] { "로드" })
            .Do(async(e) =>
            {
                if (wf.checkPerm(e.User.Id.ToString()))
                {
                    await e.Channel.SendMessage("db 불러오면됨?" + "\n" + "알씀");
                    DataBase.fileload();
                    dbload();
                    await e.Channel.SendMessage("됐다");
                }
                else
                {
                    await e.Channel.SendMessage("ㄴ");
                }
            });
            commands.CreateCommand("리스트")
            .Alias(new string[] { "목록", "검색어" })
            .Do(async(e) =>
            {
                await e.Channel
                .SendMessage("검색어요?"
                             + "\n" + "알씀");


                await e.Channel.SendMessage(makelist(e.User.Id.ToString()));
                await e.Channel.SendMessage("됐다");
            });
            commands.CreateCommand("퍼미션")
            .Alias(new string[] { "목록", "검색어" })
            .Do(async(e) =>
            {
                await e.Channel
                .SendMessage("퍼미션요?"
                             + "\n" + "알씀");
                List <string> perm = wf.getpermlist();
                string imsi        = "";

                int size = perm.Count();
                for (int i = 0; i < size; i++)
                {
                    imsi += "\"" + perm[i] + "\"" + "\r\n";
                }
                imsi = "============"
                       + "\r\n" + imsi
                       + "============";
                await e.Channel.SendMessage(imsi);
                await e.Channel.SendMessage("됐다");
            });
            commands.CreateCommand("퍼미션추가")
            .Parameter("this", ParameterType.Unparsed)
            .Do(async(e) =>
            {
                string msg = e.GetArg("this");
                if (wf.checkPerm(e.User.Id.ToString()))
                {
                    wf.WinformPermadd(msg);
                    await e.Channel.SendMessage(msg + " 추가함");
                }
                else
                {
                    await e.Channel.SendMessage("ㅈㅅ");
                }
            });
            commands.CreateCommand("퍼미션제거")
            .Parameter("this", ParameterType.Unparsed)
            .Do(async(e) =>
            {
                string msg = e.GetArg("this");
                if (wf.checkPerm(e.User.Id.ToString()))
                {
                    if (wf.WinformPermfind(msg) != -1)
                    {
                        wf.WinformPermremove(msg);
                        await e.Channel.SendMessage(msg + " 제거");
                    }
                    else
                    {
                        await e.Channel.SendMessage("그런거없음;");
                    }
                }
                else
                {
                    await e.Channel.SendMessage("ㅈㅅ");
                }
            });
            commands.CreateCommand("유저제거")
            .Parameter("this", ParameterType.Unparsed)
            .Do(async(e) =>
            {
                string msg = e.GetArg("this");

                if (msg != null)
                {
                    await e.Channel.SendMessage(
                        e.Channel.GetUser(Convert.ToUInt64(msg)) + "거요?");
                    if (wf.checkPerm(e.User.Id.ToString()))
                    {
                        if (DataBase.listdel("전체", msg, e.Server.Id.ToString()))
                        {
                            await e.Channel.SendMessage(
                                e.Channel.GetUser(Convert.ToUInt64(msg)) + "거지움");
                            dbload();
                        }
                        else
                        {
                            await e.Channel.SendMessage("ㄴㄴㄴ");
                        }
                    }
                    else
                    {
                        await e.Channel.SendMessage("안됨;");
                    }
                }
                else
                {
                    await e.Channel.SendMessage("뭐요");
                }
            });
            commands.CreateCommand("서버제거")
            .Parameter("this", ParameterType.Unparsed)
            .Do(async(e) =>
            {
                string msg = e.GetArg("this");

                if (msg != null)
                {
                    await e.Channel.SendMessage(
                        discord.GetServer(Convert.ToUInt64(msg)) + "여기요?");
                    if (wf.checkPerm(e.User.Id.ToString()))
                    {
                        if (DataBase.listdel("전체", "전체", msg))
                        {
                            await e.Channel.SendMessage(
                                discord.GetServer(Convert.ToUInt64(msg)) + "여기지움");
                            dbload();
                        }
                        else
                        {
                            await e.Channel.SendMessage("ㄴㄴㄴ");
                        }
                    }
                    else
                    {
                        await e.Channel.SendMessage("안됨;");
                    }
                }
                else
                {
                    await e.Channel.SendMessage("뭐요");
                }
            });
            commands.CreateCommand("엿보기")
            .Parameter("this", ParameterType.Unparsed)
            .Do(async(e) =>
            {
                string msg = e.GetArg("this");
                IEnumerable <User> UserList = e.Channel.FindUsers(msg);

                if (UserList.Count() == 0)
                {
                    await e.Channel
                    .SendMessage(e.Channel.GetUser(Convert.ToUInt64(msg)).Name + "님 검색어요?");
                    await e.Channel.SendMessage(makelist(msg));
                }
                else
                {
                    await e.Channel
                    .SendMessage(UserList.First().Name + "님 검색어요?");
                    await e.Channel.SendMessage(makelist(UserList.First().Id.ToString()));
                }

                await e.Channel.SendMessage("됐다");
            });

            commands.CreateCommand("서버목록")
            .Do(async(e) =>
            {
                IEnumerator <Server> enumer = discord.Servers.GetEnumerator();
                string tmp = "============\r\n";
                while (enumer.MoveNext())
                {
                    tmp += "\"[" + enumer.Current + "|" + enumer.Current.Id + "]\"" + "\r\n";
                }
                await e.Channel.SendMessage(tmp + "============");
            });


            /*
             * commands.CreateCommand("일어나")
             *  .Do(async (e) =>
             *  {
             *      if (wf.checkPerm(e.User.Id.ToString()))
             *      {
             *          await discord.Disconnect();
             *          await discord.Connect(token, TokenType.Bot);
             *      }
             *
             *  });
             */

            ///////////////////////////////////////////////////////////////////

            /////인사하기

            /*
             * discord.UserUpdated += async (s, e) => {
             *  Channel channel = e.Server.FindChannels("lounge", ChannelType.Text).SingleOrDefault();
             *  if (e.Before.Status == UserStatus.Offline)
             *      if (e.After.Status == UserStatus.Online)
             *          await channel.SendMessage(e.After.Name + "님 ㅎㅇ");
             *  if (e.Before.Status == UserStatus.Idle)
             *      if (e.After.Status == UserStatus.Online)
             *          await channel.SendMessage(e.After.Name + "님 ㅎㅇ");
             * };*/

            discord.ExecuteAndWait(async() =>
            {
                await discord.Connect(
                    Token, TokenType.Bot);
                wf.WinformLog("@bot online");
            });
        }
        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;
                }
            }
        }