Exemple #1
0
        public static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);


            bot = new botmain();
            bot.Init();//봇 생성과 초기화


            unsafe
            {
                fixed(bool *fixedtgl = &tgl_crawl)
                bot.ch.tgl = fixedtgl;
            }


            form = new Form1();
            wf   = new Winform();
            DB   = new data();

            form.GetDB(DB);

            wf.WinformLog("@이니셜라이징끝");
            bot.ch.wf = wf;
            bot.ch.db = DB;

            discordclient          = bot.ch.getdiscord();
            botthread              = new Thread(new ThreadStart(working));
            botthread.IsBackground = true;
            botthread.Start();



            dbload();

            tgl_crawl = false;
            loading   = 0;

            //worker = new Thread(new ThreadStart(crawling));
            worker = new Thread(new ThreadStart(crawler3));
            worker.Start();

            wf.WinformLog("@여기까지");


            Application.Run(form);
        }
Exemple #2
0
        public data()
        {
            form = Program.form;
            wf   = Program.wf;

            fileload();
            wf.WinformLog("@" + "DB 로드");
        }
Exemple #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
                }
            }
        }
        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
            {
            }
        }
        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");
            });
        }
Exemple #6
0
        public void fileload()
        {
            list.Clear();
            user.Clear();
            server.Clear();
            wf.WinformPerclear();
            string[] dataValue;
            string[] titleValue;
            string[] userValue;
            string[] serverValue;
            string[] permValue;

            string[] listValue;


            DirectoryInfo di = new DirectoryInfo(direction);

            if (!di.Exists)
            {
                di.Create();
            }

            try
            {
                dataValue  = File.ReadAllLines(direction + @"\data.txt");
                old_title  = dataValue[0];
                old_domain = dataValue[1];
            }
            catch (FileNotFoundException) {
                dataValue  = new string[0];
                old_title  = null;
                old_domain = null;
            }

            try { listValue = File.ReadAllLines(direction + @"\datalist.txt"); }
            catch (FileNotFoundException) { listValue = new string[0]; }

            try{ titleValue = File.ReadAllLines(direction + @"\title.txt"); }
            catch (FileNotFoundException) { titleValue = new string[0]; }

            try{ userValue = File.ReadAllLines(direction + @"\user.txt"); }
            catch (FileNotFoundException) { userValue = new string[0]; }

            try{ serverValue = File.ReadAllLines(direction + @"\server.txt"); }
            catch (FileNotFoundException) { serverValue = new string[0]; }

            try{ permValue = File.ReadAllLines(direction + @"\perm.txt"); }
            catch (FileNotFoundException) { permValue = new string[0]; }



            wf.Removelistall();
            for (int i = 0; i < titleValue.Length; i++)
            {
                listadd(titleValue[i], userValue[i], serverValue[i]);
            }
            for (int i = 0; i < permValue.Length; i++)
            {
                wf.WinformPermadd(permValue[i]);
            }
            for (int i = 0; i < listValue.Length; i++)
            {
                oldlist.Add(listValue[i]);
            }


            wf.WinformLog("@리스트 로드");
            filesave();
        }