Пример #1
0
        public MyBot()
        {
            /* init */
            client = new DiscordClient(x =>
            {
                x.LogLevel   = LogSeverity.Info;
                x.LogHandler = Log;
            });

            client.UsingCommands(input =>
            {
                input.PrefixChar         = '!';
                input.AllowMentionPrefix = true;
            });
            commands = client.GetService <CommandService>();
            /* init */

            /*
             *  Default info
             */
            commands.CreateCommand("hello").Do(async(e) =>
            {
                await e.Channel.SendMessage("こんにちは " + e.User.NicknameMention);
            });

            commands.CreateCommand("千川ちひろ").Alias("help").Do(async(e) =>
            {
                await help(e);
                //await e.Channel.SendMessage("rockon590が大好き^_^");
            });


            commands.CreateCommand("admin").Parameter("message", ParameterType.Multiple).Do(async(e) =>
            {
                string jsonstr = "";
                try { jsonstr = File.ReadAllText("../../../Certificate.json"); }
                catch
                {
                    Console.WriteLine("ERROR: 沒有找到" + "Certificate.json");
                    Console.ReadKey();
                }

                /* discordBot Token */
                JObject jsonobj = JObject.Parse(jsonstr);
                string owner    = jsonobj.GetValue("owner").ToString();
                if (owner != null && owner.Equals(e.User.NicknameMention))
                {
                    if (e.Args.Length == 1)
                    {
                        if (e.Args[0].Equals("晚安"))
                        {
                            var eu_channel   = client.GetServer(293706623652724736).GetChannel(299934136448057365); // eu testlab
                            var nmw_channel  = client.GetServer(257033414576701442).GetChannel(295057576020934656); // nmw gambling
                            var lika_channel = client.GetServer(308898984200765450).GetChannel(308908235413389314); // lika gambling
                            await eu_channel.SendMessage("みなさん、おやすみなさい");
                            await nmw_channel.SendMessage("みなさん、おやすみなさい");
                            await lika_channel.SendMessage("みなさん、おやすみなさい");
                            Console.WriteLine("SUCCESS!");
                            Environment.Exit(0);
                        }
                    }
                }
            });



            /*
             *  End Default info
             */

            /*
             * Add feature
             */
            UserInfo();
            Draw.DrawCardCommand();
            Instrucions.SetInstrucions();
            Lots.DrawLotsCommand();
            DrawRank.DrawCardRankCommand();
            ;
            ;
            ;
            ;

            /*
             * End feature
             */


            /*
             * Discord bot login.
             * Need to put last line.
             */
            client.ExecuteAndWait(async() =>
            {
                // Get discordBot Token from json
                string jsonstr = "";
                try { jsonstr = File.ReadAllText("../../../Certificate.json"); }
                catch
                {
                    Console.WriteLine("ERROR: 沒有找到" + "Certificate.json");
                    Console.ReadLine();
                    return;
                }

                /* discordBot Token */
                JObject jsonobj        = JObject.Parse(jsonstr);
                string discordbotToken = jsonobj.GetValue("token").ToString();
                if (discordbotToken == "")
                {
                    Console.WriteLine("Please check your token from \"Certificate.json\" file");
                    Console.WriteLine("URL : https://discordapp.com/developers/applications/me");
                    Console.ReadLine();                     //Pause
                    return;
                }

                await client.Connect(discordbotToken, TokenType.Bot);
                client.SetGame(new Game(jsonobj.GetValue("game").ToString()));
            });
        }