Ejemplo n.º 1
0
        public void Initialize()
        {
            using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp))
            {
                socket.Bind(new IPEndPoint(IPAddress.Any, 19132));

                var startInfo = new ProcessStartInfo(@"C:\Development\Other\bedrock-server-1.14.1.4\bedrock_server.exe");
                startInfo.CreateNoWindow  = false;
                startInfo.WindowStyle     = ProcessWindowStyle.Normal;
                startInfo.UseShellExecute = false;

                _bedrock = Process.Start(startInfo);
                _client  = new MiNetClient(new IPEndPoint(IPAddress.Parse("192.168.0.4"), 19162), "TheGrey", new DedicatedThreadPool(new DedicatedThreadPoolSettings(Environment.ProcessorCount)));
                _client.MessageHandler = new ChunkGeneratorHandler(_client);
                _client.StartClient();

                if (_client.ServerEndPoint != null)
                {
                    while (!_client.FoundServer)
                    {
                        _client.SendUnconnectedPing();
                        Thread.Sleep(100);
                    }
                }
            }

            Log.Info("Found server, waiting for spawn");


            Task.Run(BotHelpers.DoWaitForSpawn(_client)).Wait();
            Log.Info("Spawned on bedrock server");
        }
Ejemplo n.º 2
0
        public async Task RemoveRank(params string[] rank)
        {
            // Check to make sure user is not in blacklist, and if we are using the blacklist
            if (BotInfo.Permissions.IsUserInBlackList(Context.User.ToString()) && BotInfo.UseblackListCaughtUsers)
            {
                await Log("Blacklist user attempted to use a powerful command", LogSeverity.Critical);

                return;
            }

            // Check to make sure a bot is not calling this command
            if (Context.User.IsBot)
            {
                await Log("A BOT ATTEMPTED TO REMOVE A RANK", LogSeverity.Critical);

                if (BotInfo.UseblackListCaughtUsers)
                {
                    BotInfo.Permissions.AddUserToBlacklist(Context.User.ToString());
                }

                return;
            }

            if (BotInfo.UsewhiteList && !BotInfo.Permissions.IsUserInWhiteList(Context.User.ToString()))
            {
                if (BotInfo.UseblackListCaughtUsers && !BotInfo.Permissions.IsUserInBlackList(Context.User.ToString()))
                {
                    await Log("The user " + Context.User.ToString() + " attempted to use the command AnnoyDeath", LogSeverity.Critical);

                    BotInfo.Permissions.AddUserToBlacklist(Context.User.ToString());
                    return;
                }
            }

            SocketUser user = Context.User;

            string _rank = BotHelpers.CondenseStringArray(rank);

            bool doubleCheck = false;

            foreach (SocketRole role in Context.Guild.Roles)
            {
                if (role.Name == _rank)
                {
                    doubleCheck = true;
                    break;
                }
            }
            if (doubleCheck == true)
            {
                var role = Context.Guild.Roles.FirstOrDefault(x => x.Name == _rank);
                await(user as IGuildUser).RemoveRoleAsync(role);
                await(ReplyAsync("Rank removed!"));
            }
            else
            {
                await(ReplyAsync("Couldn't complete request!"));
            }
        }
Ejemplo n.º 3
0
 public FunctionCall playsound(string arg_txt)
 {
     return(delegate()
     {
         BotHelpers.PlaySound(arg_txt);
         return FunctionResult.Continue;
     });
 }
Ejemplo n.º 4
0
 public FunctionCall process_stop(string arg_txt)
 {
     return(delegate()
     {
         BotHelpers.EndProcess(arg_txt);
         return FunctionResult.Continue;
     });
 }
Ejemplo n.º 5
0
        public FunctionCall wait(string arg_txt)
        {
            NumberGenerator rn = NumberGenerator.Parse(arg_txt);

            return(delegate()
            {
                BotHelpers.Wait(rn.GetInt());
                return FunctionResult.Continue;
            });
        }
Ejemplo n.º 6
0
        public void Initialize(IWorldProvider worldProvider)
        {
            Process blocker;

            {
                // Block port!
                var startInfo = new ProcessStartInfo("MiNET.Console.exe", "listener");
                startInfo.CreateNoWindow  = false;
                startInfo.WindowStyle     = ProcessWindowStyle.Normal;
                startInfo.UseShellExecute = false;
                blocker = Process.Start(startInfo);
            }
            {
                var startInfo = new ProcessStartInfo(Path.Combine(Config.GetProperty("BDSPath", null), Config.GetProperty("BDSExe", null)));
                startInfo.WorkingDirectory      = Config.GetProperty("BDSPath", null);
                startInfo.CreateNoWindow        = false;
                startInfo.WindowStyle           = ProcessWindowStyle.Normal;
                startInfo.UseShellExecute       = false;
                startInfo.RedirectStandardInput = true;

                _bedrock = Process.Start(startInfo);

                _client = new MiNetClient(new IPEndPoint(IPAddress.Parse("192.168.10.178"), 19162), "TheGrey", new DedicatedThreadPool(new DedicatedThreadPoolSettings(Environment.ProcessorCount)));
                _client.MessageHandler = new ChunkGeneratorHandler(_client, worldProvider);
                //_client.UseBlobCache = true;
                _client.StartClient();

                if (_client.ServerEndPoint != null)
                {
                    while (!_client.FoundServer)
                    {
                        _client.SendUnconnectedPing();
                        Thread.Sleep(100);
                    }
                }
            }

            Log.Info("Found server, waiting for spawn");


            Task.Run(BotHelpers.DoWaitForSpawn(_client)).Wait();
            Log.Info("Spawned on bedrock server");

            blocker?.Kill();             // no need to block further once we have spawned our bot.

            // Shutdown hook. Must use to flush in memory log of LevelDB.
            AppDomain.CurrentDomain.ProcessExit += (sender, args) =>
            {
                Log.Warn("Closing bedrock dedicated server (BDS)");
                _bedrock.StandardInput.WriteLine("stop");
                _bedrock.WaitForExit(1000);
                _bedrock.Kill();
            };
        }
Ejemplo n.º 7
0
        public async Task CreateRankAsync(
            params string[] name)
        {
            // Check to make sure user is not in blacklist, and if we are using the blacklist
            if (BotInfo.Permissions.IsUserInBlackList(Context.User.ToString()) && BotInfo.UseblackListCaughtUsers)
            {
                await Log("Blacklist user attempted to use a powerful command", LogSeverity.Critical);

                return;
            }

            // Check to make sure a bot is not calling this command
            if (Context.User.IsBot)
            {
                await Log("A BOT ATTEMPTED TO MESSAGE PEOPLE", LogSeverity.Critical);

                if (BotInfo.UseblackListCaughtUsers)
                {
                    BotInfo.Permissions.AddUserToBlacklist(Context.User.ToString());
                }

                return;
            }

            if (BotInfo.UsewhiteList && !BotInfo.Permissions.IsUserInWhiteList(Context.User.ToString()))
            {
                if (BotInfo.UseblackListCaughtUsers && !BotInfo.Permissions.IsUserInBlackList(Context.User.ToString()))
                {
                    await Log("The user " + Context.User.ToString() + " attempted to use the command AnnoyDeath", LogSeverity.Critical);

                    BotInfo.Permissions.AddUserToBlacklist(Context.User.ToString());
                    return;
                }
            }

            string _name = BotHelpers.CondenseStringArray(name);

            foreach (SocketRole role in Context.Guild.Roles)
            {
                if (role.Name == _name)
                {
                    await Context.Channel.SendMessageAsync("Rank already exists!");
                    await Log(Context.User.ToString() + "tried making the rank " + _name + " but it already exists!", LogSeverity.Error);

                    return;
                }
            }

            await Context.Guild.CreateRoleAsync(_name, null, null, false, null).ContinueWith(x => Context.Channel.SendMessageAsync("Rank made!"));

            await Log(Context.User.ToString() + " created the rank " + _name, LogSeverity.Info);
        }
        public async Task IntentGreeting(IDialogContext context, IAwaitable <IMessageActivity> item, LuisResult result)
        {
            await context.PostAsync("Olá. Tudo bem? Posso ajudar com informações sobre ações, o que você deseja saber?");

            IMessageActivity replyActivity = context.MakeMessage();

            replyActivity.AttachmentLayout = AttachmentLayoutTypes.Carousel;
            replyActivity.Attachments      = BotHelpers.GetMainMenuCarousel();

            await context.PostAsync(replyActivity);

            context.Wait(MessageReceived);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Executes a series of <see cref="FunctionCall"/>s
 /// </summary>
 /// <param name="calls"></param>
 /// <returns>True if script all lines in the script were executed.
 /// False if the script terminated.</returns>
 bool ExecuteScript(IEnumerable <FunctionCall> calls)
 {
     foreach (FunctionCall call in calls)
     {
         FunctionResult result = call();
         BotHelpers.Wait(StandardWait.GetInt());
         if (result == FunctionResult.Break)
         {
             // don't continue with script
             return(false);
         }
     }
     return(true); // script completed
 }
Ejemplo n.º 10
0
        public static void Start()
        {
            var botHelper         = new BotHelpers();
            var commandDictionary = botHelper.BuildSoundFiles();
            var introDictionary   = botHelper.BuildSoundIntros();
            var commandList       = botHelper.BuildCommandList();

            var _client = botHelper.Client;

            _client.UsingAudio(x =>
            {
                x.Mode = AudioMode.Outgoing;
            });

            _client.MessageReceived += async(s, e) =>
            {
                var soundFile = FetchSoundFile(e.Message.Text, commandDictionary);

                if (!string.IsNullOrEmpty(soundFile))
                {
                    await botHelper.ProcessAudioAsync("sounds", e.Message.Text, soundFile, e.User.VoiceChannel);
                }

                if (e.Message.Text.Equals("!breadme"))
                {
                    await e.Message.Channel.SendMessage(commandList);
                }
            };

            _client.UserUpdated += async(s, e) =>
            {
                var soundFile = FetchSoundFile(e.After.Name, introDictionary);

                if (!string.IsNullOrEmpty(soundFile))
                {
                    await botHelper.ProcessAudioAsync("intros", e.After.Name, soundFile, e.After.VoiceChannel);
                }
            };

            _client.ExecuteAndWait(async() => {
                await _client.Connect(Settings.DiscordConfig.AppToken, TokenType.Bot);
            });
        }
Ejemplo n.º 11
0
        public async Task AnnoyDeath(string username, int numTimes, params string[] message)
        {
            if (BotInfo.UsewhiteList && !BotInfo.Permissions.IsUserInWhiteList(Context.User.ToString()))
            {
                if (BotInfo.UseblackListCaughtUsers && !BotInfo.Permissions.IsUserInBlackList(Context.User.ToString()))
                {
                    await Log("The user " + Context.User.ToString() + " attempted to use the command AnnoyDeath", LogSeverity.Critical);
                    await ReplyAsync("You need to be on the whitelist!");

                    BotInfo.Permissions.AddUserToBlacklist(Context.User.ToString());
                    return;
                }
            }

            if (numTimes > 50)
            {
                numTimes = 50;
            }

            await Log($"Sending {numTimes} messages to " + username);

            var users = Context.Guild.Users;

            foreach (var user in users)
            {
                if (user.ToString() != username)
                {
                    continue;
                }

                for (int i = 0; i < numTimes; i++)
                {
                    await user.SendMessageAsync(BotHelpers.CondenseStringArray(message));

                    await Task.Delay(500);
                }
            }

            await ReplyAsync("☢️ The nukes have been launched towards " + username + ", god help us all. ☢️");

            return;
        }
Ejemplo n.º 12
0
        public async Task DescribeAbility(params string[] name)
        {
            string _name = BotHelpers.CondenseStringArray(name);

            if (!Program.abilityLibrary.LibraryHasAbility(_name))
            {
                await Log(Context.User.ToString() + " asked for the invalid ability name " + _name, LogSeverity.Error);
                await ReplyAsync(_name + " is not a valid ability!");

                return;
            }
            else
            {
                Ability      ab           = Program.abilityLibrary.GetAbility(_name);
                EmbedBuilder embedBuilder = new EmbedBuilder();
                embedBuilder.AddField("Name", ab.Name);
                embedBuilder.AddField("Rank", ab.GetRankAsString());
                embedBuilder.AddField("Description", ab.Description);

                await ReplyAsync("Here is what I found . . . \n", false, embedBuilder.Build()).ContinueWith(x =>
                                                                                                            Log("Descibed the ability " + _name + " in the channel " + Context.Channel.ToString()));
            }
        }
Ejemplo n.º 13
0
        public async Task MessagePlayersOfRank(string _rank, params string[] message)
        {
            // Check to make sure user is not in blacklist, and if we are using the blacklist
            if (BotInfo.Permissions.IsUserInBlackList(Context.User.ToString()) && BotInfo.UseblackListCaughtUsers)
            {
                await Log("Blacklist user attempted to use a powerful command");

                return;
            }

            // Check to make sure a bot is not calling this command
            if (Context.User.IsBot)
            {
                await Log("A BOT ATTEMPTED TO MESSAGE PEOPLE");

                if (BotInfo.UseblackListCaughtUsers)
                {
                    BotInfo.Permissions.AddUserToBlacklist(Context.User.ToString());
                }

                return;
            }

            if (BotInfo.UsewhiteList && !BotInfo.Permissions.IsUserInWhiteList(Context.User.ToString()))
            {
                if (BotInfo.UseblackListCaughtUsers && !BotInfo.Permissions.IsUserInBlackList(Context.User.ToString()))
                {
                    await Log("The user " + Context.User.ToString() + " attempted to use the command AnnoyDeath", LogSeverity.Critical);

                    BotInfo.Permissions.AddUserToBlacklist(Context.User.ToString());
                    return;
                }
            }

            var users         = Context.Guild.Users;
            int numValidUsers = 0;

            foreach (var user in users)
            {
                bool hasRole = false;
                foreach (var role in user.Roles)
                {
                    if (role.ToString() == _rank)
                    {
                        hasRole = true;
                        break;
                    }
                }

                if (hasRole)
                {
                    string _message = BotHelpers.CondenseStringArray(message);

                    if (_message == "test" || _message == "")
                    {
                        _message = "Hello there! This is either a test, or the guy who made me do this didn't give me a message to give you.";
                    }

                    await user.SendMessageAsync(_message);
                    await Log("Sent message to " + user.ToString());

                    numValidUsers++;
                }
            }
            await ReplyAsync($"Sent {numValidUsers} messages");
        }