コード例 #1
0
ファイル: SetKeyCommand.cs プロジェクト: someone243/CupCake
 private void Run(IInvokeSource source, ParsedCommand message)
 {
     this.RequireOwner();
     string key = message.GetTrail(0);
     this.RoomService.ChangeKey(key);
     source.Reply("Set key to {0}.", key);
 }
コード例 #2
0
 public CommandExceptionEvent(IInvokeSource source, ParsedRequest request, CommandException exception)
 {
     this.Exception = exception;
     this.Source    = source;
     this.Request   = request;
     this.Handled   = exception.Ignored;
 }
コード例 #3
0
ファイル: GodModeCommand.cs プロジェクト: someone243/CupCake
        private void Run(IInvokeSource source, ParsedCommand message)
        {
            this.RequireEdit();

            bool enabled;

            if (message.Count >= 1)
            {
                try
                {
                    enabled = Boolean.Parse(message.Args[0]);
                }
                catch (Exception ex)
                {
                    throw new CommandException("Unable to parse parameter: enabled", ex);
                }
            }
            else
            {
                enabled = !this.PlayerService.OwnPlayer.IsGod;
            }

            this.ActionService.GodMode(enabled);

            source.Reply("God mode was set to {0}.", enabled);
        }
コード例 #4
0
 private void RequireModerator(IInvokeSource source)
 {
     if (requireModerator)
     {
         Group.Moderator.RequireFor(source);
     }
 }
コード例 #5
0
ファイル: CommandService.cs プロジェクト: someone243/CupCake
        public void Invoke(IInvokeSource source, ParsedCommand message)
        {
            var e = new InvokeEvent(source, message);
            this.Events.Raise(e);

            if (!e.Handled && source.Group >= this.ResponseMinGroup)
                source.Reply(UnknownCommandStr);
        }
コード例 #6
0
ファイル: NameCommand.cs プロジェクト: KylerM/CupCake
        protected override void Run(IInvokeSource source, ParsedCommand message)
        {
            this.RequireOwner();

            var name = message.GetTrail(0);
            this.RoomService.SetName(name);
            source.Reply("Name changed to: {0}", name);
        }
コード例 #7
0
ファイル: UnmuteCommand.cs プロジェクト: someone243/CupCake
        private void Run(IInvokeSource source, ParsedCommand message)
        {
            Player player = this.PlayerService.MatchPlayer(message.Args[0]);

            this.Chatter.Unmute(player.Username);

            source.Reply("Unmuted {0}.", player.ChatName);
        }
コード例 #8
0
        private void Run(IInvokeSource source, ParsedCommand message)
        {
            Player player = this.PlayerService.MatchPlayer(message.Args[0]);

            this.Chatter.ReportAbuse(player.Username, message.GetTrail(1));

            source.Reply("Reported {0}.", player.ChatName);
        }
コード例 #9
0
 public static void RequireFor(this PlayerInvokeOrigin origin, IInvokeSource source,
     string errorMessage = "Command is not available here.")
 {
     var playerSource = source as PlayerInvokeSource;
     if (playerSource != null)
     {
         if (playerSource.Origin != origin) throw new InvalidInvokeOriginCommandException(errorMessage);
     }
 }
コード例 #10
0
ファイル: KickCommand.cs プロジェクト: someone243/CupCake
        private void Run(IInvokeSource source, ParsedCommand message)
        {
            this.RequireOwner();
            Player player = this.GetPlayerOrSelf(source, message);
            this.RequireSameRank(source, player);

            this.Chatter.ChatService.Kick(source.Name, player.Username,
                (message.Count > 1 ? message.GetTrail(1) : "Tsk tsk tsk"));
        }
コード例 #11
0
ファイル: SaveCommand.cs プロジェクト: someone243/CupCake
        private void Run(IInvokeSource source, ParsedCommand message)
        {
            this.RequireOwner();
            if (message.Count == 0 || message.Args[0] != "SAVE")
                throw new CommandException("To use save, type !save SAVE");

            this.RoomService.Save();
            source.Reply("Saved.");
        }
コード例 #12
0
ファイル: ClearCommand.cs プロジェクト: someone243/CupCake
        private void Run(IInvokeSource source, ParsedCommand message)
        {
            this.RequireOwner();

            if (message.Count == 0 || message.Args[0] != "CLEAR")
                throw new CommandException("To use clear, type !clear CLEAR");

            this.RoomService.Clear();
            source.Reply("Cleared level.");
        }
コード例 #13
0
ファイル: GiveEditCommand.cs プロジェクト: someone243/CupCake
        private void Run(IInvokeSource source, ParsedCommand message)
        {
            this.RequireOwner();
            Player player = this.GetPlayerOrSelf(source, message);
            this.RequireSameRank(source, player);

            this.Chatter.GiveEdit(player.Username);

            source.Reply("Gave edit to {0}.", player.ChatName);
        }
コード例 #14
0
 public static Group GetGroup(this IInvokeSource source)
 {
     try
     {
         return(source.ToPermissionInvokeSource().Group);
     }
     catch (InvalidInvokeSourceCommandException)
     {
         return(Group.External);
     }
 }
コード例 #15
0
ファイル: BanCommand.cs プロジェクト: someone243/CupCake
 private void Run(IInvokeSource source, ParsedCommand message)
 {
     if (message.Count >= 2)
     {
         this.Ban(source, message.Args[0], message.GetTrail(1));
     }
     else
     {
         this.Ban(source, message.Args[0]);
     }
 }
コード例 #16
0
ファイル: AccessCommand.cs プロジェクト: KylerM/CupCake
        protected override void Run(IInvokeSource source, ParsedCommand message)
        {
            string key = String.Empty;

            if (message.Count >= 1)
                key = message.GetTrail(0);

            this.RoomService.Access(key);

            source.Reply("Access sent.");
        }
コード例 #17
0
        public static ConsoleInvokeSource ToConsoleInvokeSource(this IInvokeSource source,
                                                                string errorMessage = "This command is not available in game.")
        {
            var consoleSource = source as ConsoleInvokeSource;

            if (consoleSource == null)
            {
                throw new InvalidInvokeSourceCommandException(errorMessage);
            }

            return(consoleSource);
        }
コード例 #18
0
        public static PlayerInvokeSource ToPlayerInvokeSource(this IInvokeSource source,
                                                              string errorMessage = "You must call this command as a player.")
        {
            var playerSource = source as PlayerInvokeSource;

            if (playerSource == null)
            {
                throw new InvalidInvokeSourceCommandException(errorMessage);
            }

            return(playerSource);
        }
コード例 #19
0
        public static void RequireFor(this PlayerInvokeOrigin origin, IInvokeSource source,
                                      string errorMessage = "Command is not available here.")
        {
            var playerSource = source as PlayerInvokeSource;

            if (playerSource != null)
            {
                if (playerSource.Origin != origin)
                {
                    throw new InvalidInvokeOriginCommandException(errorMessage);
                }
            }
        }
コード例 #20
0
        private void OffCommand(IInvokeSource source, ParsedRequest request)
        {
            RequireModerator(source);

            if (!roundsManager.Enabled)
            {
                source.Reply("Bot is already disabled.");
            }
            else
            {
                source.Reply("Disabling bot...");
                roundsManager.Enabled = false;
            }
        }
コード例 #21
0
        private void StopCommand(IInvokeSource source, ParsedRequest request)
        {
            RequireModerator(source);

            if (!roundsManager.Enabled)
            {
                source.Reply("Bot is not enabled!");
            }
            else
            {
                source.Reply("Stopping round...");
                roundsManager.ForceStop();
            }
        }
コード例 #22
0
ファイル: VisibleCommand.cs プロジェクト: someone243/CupCake
        private void Run(IInvokeSource source, ParsedCommand message)
        {
            this.RequireOwner();

            bool isVisible;
            try
            {
                isVisible = Boolean.Parse(message.Args[0]);
            }
            catch (Exception ex)
            {
                throw new CommandException("Unable to parse parameter: isVisible", ex);
            }
            this.Chatter.ChangeVisibility(isVisible);
            source.Reply("Changed visibility to {0}.", isVisible);
        }
コード例 #23
0
        private void Run(IInvokeSource source, ParsedCommand message)
        {
            Smiley smiley;
            try
            {
                smiley = (Smiley)Enum.Parse(typeof(Smiley), message.Args[0], true);
            }
            catch (Exception ex)
            {
                throw new CommandException("Unable to parse parameter: smiley", ex);
            }

            this.ActionService.ChangeFace(smiley);

            source.Reply("Smiley set to {0}.", smiley);
        }
コード例 #24
0
ファイル: EnablePotsCommand.cs プロジェクト: KylerM/CupCake
        protected override void Run(IInvokeSource source, ParsedCommand message)
        {
            this.RequireOwner();

            bool isAllowed;
            try
            {
                isAllowed = Boolean.Parse(message.Args[0]);
            }
            catch (Exception ex)
            {
                throw new CommandException("Unable to parse parameter: isAllowed", ex);
            }
            this.RoomService.SetAllowPotions(isAllowed);
            source.Reply("Potions enabled: {0}.", isAllowed);
        }
コード例 #25
0
ファイル: TeleportCommand.cs プロジェクト: KylerM/CupCake
        protected override void Run(IInvokeSource source, ParsedCommand message)
        {
            this.RequireOwner();
            Player player = this.PlayerService.MatchPlayer(message.Args[0]);
            this.RequireSameRank(source, player);

            if (message.Count >= 3)
            {
                int x = message.GetInt(1);
                int y = message.GetInt(2);

                this.Chatter.Teleport(player.Username, x, y);
            }
            else if (message.Count == 2)
            {
                try
                {
                    Player target = this.PlayerService.MatchPlayer(message.Args[1]);
                    this.Chatter.Teleport(player.Username, target.BlockX, target.BlockY);
                }
                catch (CommandException ex)
                {
                    throw new CommandException(ex.Message + " Parameter: target", ex);
                }
            }
            else
            {
                var playerSource = source as PlayerInvokeSource;
                if (playerSource != null)
                {
                    int x = playerSource.Player.BlockX;
                    int y = playerSource.Player.BlockX;

                    this.Chatter.Teleport(player.Username, x, y);
                }
                else
                {
                    this.Chatter.Teleport(player.Username);
                }
            }

            source.Reply("Teleported {0}.", player.ChatName);
        }
コード例 #26
0
        public static IPermissionInvokeSource ToPermissionInvokeSource(this IInvokeSource source)
        {
            var permissionSource = source as IPermissionInvokeSource;

            if (permissionSource != null)
            {
                return(permissionSource);
            }

            var pSource = source as PlayerInvokeSource;

            if (pSource != null)
            {
                return(new PlayerPermissionInvokeSourceAdapter(pSource));
            }

            throw new InvalidInvokeSourceCommandException(
                      "Unable to retrieve your permissions. Command could not be run.");
        }
コード例 #27
0
ファイル: GetRankCommand.cs プロジェクト: KylerM/CupCake
 protected override void Run(IInvokeSource source, ParsedCommand message)
 {
     if (message.Count >= 1)
     {
         string user = message.Args[0];
         this.PlayerService.MatchPlayer(user,
             player =>
                 source.Reply("{0}'s rank is {1}", player.ChatName, player.GetGroup()),
             username =>
                 source.Reply("{0} is now {1}.", PlayerUtils.GetChatName(username),
                     this.Host.GetPermission(PlayerUtils.GetStorageName(username))));
     }
     var playerSource = source as PlayerInvokeSource;
     if (playerSource != null)
     {
         source.Reply("{0}'s rank is {1}", playerSource.Player.ChatName, playerSource.Player.GetGroup());
     }
     else
     {
         throw new UnknownPlayerCommandException("No player was specified!");
     }
 }
コード例 #28
0
ファイル: TempBanCommand.cs プロジェクト: someone243/CupCake
        private void Run(IInvokeSource source, ParsedCommand message)
        {
            DateTime timeout;
            try
            {
                TimeSpan duration = TimeSpan.Parse(message.Args[1]);
                timeout = DateTime.UtcNow.Add(duration);
            }
            catch (Exception ex)
            {
                throw new CommandException("Unable to parse parameter: duration", ex);
            }

            if (message.Count >= 3)
            {
                this.Ban(source, message.Args[0], timeout, message.GetTrail(2));
            }
            else
            {
                this.Ban(source, message.Args[0], timeout);
            }
        }
コード例 #29
0
ファイル: UsePotionCommand.cs プロジェクト: KylerM/CupCake
        protected override void Run(IInvokeSource source, ParsedCommand message)
        {
            Potion pot;
            try
            {
                pot = (Potion)Enum.Parse(typeof(Potion), message.Args[0], true);
            }
            catch (Exception ex)
            {
                throw new CommandException("Unable to parse parameter: potion", ex);
            }

            try
            {
                this.PotionService.UsePotion(pot);
            }
            catch (InvalidOperationException ex)
            {
                throw new CommandException("Unable to use potion: " + ex.Message, ex);
            }

            source.Reply("Potion {0} used.", pot);
        }
コード例 #30
0
ファイル: GuardianModeCommand.cs プロジェクト: KylerM/CupCake
        protected override void Run(IInvokeSource source, ParsedCommand message)
        {
            bool enabled;

            if (message.Count >= 1)
            {
                try
                {
                    enabled = Boolean.Parse(message.Args[0]);
                }
                catch (Exception ex)
                {
                    throw new CommandException("Unable to parse parameter: enabled", ex);
                }
            }
            else
            {
                enabled = !this.PlayerService.OwnPlayer.IsGuardian;
            }

            this.ActionService.GuardianMode(enabled);

            source.Reply("Guardian mode was set to {0}.", enabled);
        }
コード例 #31
0
ファイル: ResetCommand.cs プロジェクト: KylerM/CupCake
 protected override void Run(IInvokeSource source, ParsedCommand message)
 {
     this.RequireOwner();
     this.Chatter.Reset();
     source.Reply("Level reset.");
 }
コード例 #32
0
 public static void Reply(this IInvokeSource invokeSource, string message, params object[] args)
 {
     // ReSharper disable once RedundantStringFormatCall
     invokeSource.Reply(string.Format(message, args));
 }
コード例 #33
0
ファイル: ModCommand.cs プロジェクト: someone243/CupCake
 private void Run(IInvokeSource source, ParsedCommand message)
 {
     this.RunPermissionCommand(source, message, Group.Moderator);
 }
コード例 #34
0
ファイル: GetCrownCommand.cs プロジェクト: someone243/CupCake
 private void Run(IInvokeSource source, ParsedCommand message)
 {
     this.ActionService.GetCrown();
     source.Reply("Got crown.");
 }
コード例 #35
0
ファイル: RestartCommand.cs プロジェクト: someone243/CupCake
        private void Run(IInvokeSource source, ParsedCommand message)
        {
            source.Reply("Restarting...");

            this.HostService.Restart();
        }
コード例 #36
0
ファイル: BlueCommand.cs プロジェクト: someone243/CupCake
 private void Run(IInvokeSource source, ParsedCommand message)
 {
     this.KeyService.PressKey(Key.Blue);
     source.Reply("Pressed blue key.");
 }
コード例 #37
0
ファイル: MyBot.cs プロジェクト: Yonom/BotCake
 void HiCommand(IInvokeSource source, ParsedRequest request)
 {
     source.Reply("Hello");
 }
コード例 #38
0
ファイル: Program.cs プロジェクト: Yonom/BotBits.Commands
        private static void HiCommand(IInvokeSource source, ParsedRequest request)
        {
            var player = source.ToPlayerInvokeSource().Player;

            source.Reply("Hello world {0}!", player.Username);
        }
コード例 #39
0
 protected override void Run(IInvokeSource source, ParsedCommand message)
 {
     this.RunPermissionCommand(source, message, Group.Operator);
 }
コード例 #40
0
 public CommandEvent(IInvokeSource source, ParsedRequest request)
 {
     this.Source  = source;
     this.Request = request;
 }
コード例 #41
0
 private void Run(IInvokeSource source, ParsedCommand message)
 {
     if (this.PlayerService.OwnPlayer.HasSilverCrown)
         throw new CommandException("Bot already has crown!");
     this.ActionService.CompleteLevel();
 }
コード例 #42
0
 protected override void Run(IInvokeSource source, ParsedCommand message)
 {
     this.KeyService.PressKey(Key.Green);
     source.Reply("Pressed green key.");
 }
コード例 #43
0
ファイル: MyBot.cs プロジェクト: Yonom/BotCake
 void HiCommand(IInvokeSource source, ParsedRequest request)
 {
     source.Reply("Hello");
 }