コード例 #1
0
    void Start()
    {
        gManager = GameObject.Find("Game_manager").GetComponent <GridManager>();
        sChecker = GameObject.Find("Game_manager").GetComponent <StateChecker>();

        dragDist = Screen.height * 5 / 100;
    }
コード例 #2
0
        public async Task ShowChannelRolesAsync()
        {
            if (!StateChecker.IsGuildAdmin(Context))
            {
                await Context.Channel.SendMessageAsync(":x: You are not guild admin!");

                return;
            }

            if (StateChecker.IsPrivateMessage(Context))
            {
                await Context.Channel.SendMessageAsync(
                    ":x: Please use this command in the guild you wish to see the roles for");
            }

            var roleHandler          = new RoleHandler(Factory.GetDatabase());
            var allGuildTextChannels = Context.Guild.TextChannels;
            var botUserId            = Context.Client.CurrentUser.Id;

            foreach (var guildChannel in allGuildTextChannels)
            {
                var users = guildChannel.Users;
                foreach (var user in users)
                {
                    if (user.Id == botUserId)
                    {
                        var role = roleHandler.GetRoleForChannel(guildChannel.Id);
                        await Context.Channel.SendMessageAsync($"{guildChannel.Name} : {role}");
                    }
                }
            }
        }
コード例 #3
0
ファイル: Help.cs プロジェクト: flint276/LongJohnSilver
        public async Task HelpAsync()
        {
            if (!StateChecker.IsKnockoutChannel(Context))
            {
                await Context.Channel.SendMessageAsync(
                    "**!createknockout** - Creates a new knockout, instructions follow in a private message.\n" +
                    "(please don't forget to type **!quit** if you change your mind or the bot will remain locked in creation mode!\n" +
                    "**!vote** *<Up>*/*<Down>* - Vote for the contenders you wish to raise and decrease.\n" +
                    "**!showknockout** - Refresh and show the current knockout at the bottom of the screen.\n" +
                    "**!epitaph** *<eulogy for the fallen* - Use this to type a silly little message to honor the contender you last eliminated.\n" +
                    "**!snap** - Halve the current scores, can only be used by the knockout creator.\n" +
                    "**!newday** - Reset the counters for the hour, can only be used by channel ops.\n" +
                    "**!rebuild** - Completely delete the current or in progress knockout. Only for channel ops! Use with caution!\n" +
                    "Have fun! If I break, please let RedFlint know!"
                    );

                return;
            }

            if (!StateChecker.IsGeneralChannel(Context))
            {
                await Context.Channel.SendMessageAsync(
                    "**!ver** - Show the latest version of the bot.\n" +
                    "**!weather** *<Location>* - Show a simple weather report for that location.\n" +
                    "Have fun! If I break, please let RedFlint know!"
                    );

                return;
            }
        }
コード例 #4
0
 private void Awake()
 {
     //  StartCoroutine(MoveTowardsThis(0));
     sChecker  = GameObject.Find("Game_manager").GetComponent <StateChecker>();
     locHol    = gameObject.GetComponent <LocationHolder>();
     gridManag = GameObject.Find("Game_manager").GetComponent <GridManager>();
 }
コード例 #5
0
ファイル: NewDay.cs プロジェクト: flint276/LongJohnSilver
        public async Task NewDayAsync()
        {
            if (!StateChecker.IsKnockoutChannel(Context) || StateChecker.IsPrivateMessage(Context))
            {
                return;
            }

            if (!(StateChecker.IsChannelOp(Context)))
            {
                await Context.Channel.SendMessageAsync(":x: You are not a bot moderator!");

                return;
            }

            if (Context.IsPrivate)
            {
                await Context.Channel.SendMessageAsync("Please use this command in the knockout channel!");

                return;
            }

            var knockouts = new KnockOutHandler(Context.Channel.Id, Factory.GetDatabase());

            knockouts.NewDay();
            await Context.Channel.SendMessageAsync("It is a glorious new day. Everyone's turns are reset!");

            return;
        }
コード例 #6
0
        public async Task SetChannelRoleAsync([Remainder] string input = "")
        {
            if (!StateChecker.IsGuildAdmin(Context))
            {
                await Context.Channel.SendMessageAsync(":x: You are not guild admin!");

                return;
            }

            if (StateChecker.IsPrivateMessage(Context))
            {
                await Context.Channel.SendMessageAsync(
                    ":x: Please use this command in the channel you wish to set the role for");
            }

            var roleHandler = new RoleHandler(Factory.GetDatabase());

            if (!roleHandler.IsValidRole(input))
            {
                await Context.Channel.SendMessageAsync($":x: *{input}* is not a valid channel role");

                return;
            }

            roleHandler.SetRoleForChannel(Context.Channel.Id, input);
            await Context.Channel.SendMessageAsync(
                $"This channel has now been set to the *{input.ToLower()}* role!");
        }
コード例 #7
0
        public async Task AbortKnockoutAsync()
        {
            if (!StateChecker.IsPrivateMessage(Context))
            {
                return;
            }

            var channelId = KnockOutHandler.ChannelForUser(Context.User.Id, Factory.GetDatabase());

            if (channelId == 0)
            {
                await Context.Channel.SendMessageAsync(":x: You are not making a knockout at the moment!");

                return;
            }

            var knockouts = new KnockOutHandler(channelId, Factory.GetDatabase());

            if (knockouts.KnockoutCreatorUlong != Context.User.Id)
            {
                await Context.Channel.SendMessageAsync(":x: You are not making a knockout at the moment!");

                return;
            }

            switch (knockouts.KnockoutStatus)
            {
            case 1:
                await Context.Channel.SendMessageAsync(":x: You are not making a knockout at the moment!");

                return;

            case 2:
                await Context.Channel.SendMessageAsync(":x: You are not making a knockout at the moment!");

                return;

            case 3:
                await Context.Channel.SendMessageAsync(":x: You are not making a knockout at the moment!");

                return;

            case 4:
                break;

            default:
                await Context.Channel.SendMessageAsync(":x: Right. This shouldn't have happened. Someone call RedFlint.");

                return;
            }

            var chnl = Context.Client.GetChannel(knockouts.KnockoutChannelUlong) as Discord.IMessageChannel;

            knockouts.EmptyDatabase();

            await Context.Channel.SendMessageAsync("Database cleared!");

            await chnl.SendMessageAsync("Knockout Creation Aborted By Creator. You are free to create a new knockout.");
        }
コード例 #8
0
        public void CheckStateTest_ShouldReturn1()
        {
            var lineList = new List <LineStructure>
            {
                new LineStructure()
                {
                    X1 = 0, Y1 = 0, X2 = 10, Y2 = 0, StrokeColor = _red
                },
                new LineStructure()
                {
                    X1 = 10, Y1 = 0, X2 = 20, Y2 = 0, StrokeColor = _blue
                },
                new LineStructure()
                {
                    X1 = 0, Y1 = 10, X2 = 10, Y2 = 10, StrokeColor = _red
                },
                new LineStructure()
                {
                    X1 = 10, Y1 = 10, X2 = 20, Y2 = 10, StrokeColor = _blue
                },
                new LineStructure()
                {
                    X1 = 0, Y1 = 20, X2 = 10, Y2 = 20, StrokeColor = _red
                },

                new LineStructure()
                {
                    X1 = 0, Y1 = 0, X2 = 0, Y2 = 10, StrokeColor = _white
                },
                new LineStructure()
                {
                    X1 = 10, Y1 = 0, X2 = 10, Y2 = 10, StrokeColor = _white
                },
                new LineStructure()
                {
                    X1 = 20, Y1 = 0, X2 = 20, Y2 = 10, StrokeColor = _blue
                },
                new LineStructure()
                {
                    X1 = 10, Y1 = 10, X2 = 10, Y2 = 20, StrokeColor = _blue
                }
            };

            var refLine = new LineStructure()
            {
                X1 = 0, Y1 = 10, X2 = 0, Y2 = 20, StrokeColor = _white
            };
            var stateChecker = new StateChecker()
            {
                GameHeight = 10,
                GameWidth  = 10
            };

            int actual   = stateChecker.CheckState(refLine, lineList).Item2;
            int expected = 1;

            Assert.IsTrue(actual == expected);
        }
コード例 #9
0
        public void Should_check_for_new_checkers()
        {
            var checker = new StateChecker();

            checker.IsAvailable(new Feature()
            {
                State = true
            }).ShouldBe(true);
        }
コード例 #10
0
ファイル: Epitaph.cs プロジェクト: flint276/LongJohnSilver
        public async Task EpitaphAsync([Remainder] string input = "")
        {
            if (!StateChecker.IsKnockoutChannel(Context) || StateChecker.IsPrivateMessage(Context))
            {
                return;
            }

            if (input == "")
            {
                await Context.Channel.SendMessageAsync(":x: Please enter a valid epitaph.");

                return;
            }

            if (input.Count() > 199)
            {
                await Context.Channel.SendMessageAsync(":x: Epitaph too long!");
            }

            var knockouts = new KnockOutHandler(Context.Channel.Id, Factory.GetDatabase());

            switch (knockouts.KnockoutStatus)
            {
            case 1:
                await Context.Channel.SendMessageAsync(":x: No Knockout ongoing. Feel free to start a new one!");

                return;

            case 2:
                break;

            case 3:
                await Context.Channel.SendMessageAsync(":x: This knockout is finished.");

                return;

            case 4:
                await Context.Channel.SendMessageAsync(":x: This knockout is still under construction! Patience!");

                return;

            default:
                await Context.Channel.SendMessageAsync(":x: Right. This shouldn't have happened. Someone call RedFlint.");

                return;
            }

            if (!knockouts.CanWriteAnEpitaph(Context.User.Id))
            {
                await Context.Channel.SendMessageAsync(":x: You are not eligible to write an epitaph for a contender.");

                return;
            }

            knockouts.WriteEpitaphFromUser(Context.User.Id, input);
            await Context.Channel.SendMessageAsync(":skull: Engraved!");
        }
コード例 #11
0
        public async Task PreviewKnockoutAsync()
        {
            if (!StateChecker.IsPrivateMessage(Context))
            {
                return;
            }

            var channelId = KnockOutHandler.ChannelForUser(Context.User.Id, Factory.GetDatabase());

            if (channelId == 0)
            {
                await Context.Channel.SendMessageAsync(":x: You are not making a knockout at the moment!");

                return;
            }

            var knockouts = new KnockOutHandler(channelId, Factory.GetDatabase());

            if (knockouts.KnockoutCreatorUlong != Context.User.Id)
            {
                await Context.Channel.SendMessageAsync(":x: You are not making a knockout at the moment!");

                return;
            }

            switch (knockouts.KnockoutStatus)
            {
            case 1:
                await Context.Channel.SendMessageAsync(":x: No Knockout is being created at the moment!");

                return;

            case 2:
                await Context.Channel.SendMessageAsync(":x: This knockout has already started! Preview in main channel.");

                return;

            case 3:
                await Context.Channel.SendMessageAsync(":x: This knockout is finished, see the results in the main channel.");

                return;

            case 4:
                break;

            default:
                await Context.Channel.SendMessageAsync(":x: Right. This shouldn't have happened. Someone call RedFlint.");

                return;
            }

            await BotEmbeds.ShowKnockout(Context, knockouts);
        }
コード例 #12
0
ファイル: Player.cs プロジェクト: daima4657/uguisu
    // Update is called once per frame
    void Update()
    {
        StateChecker StateChecker = GetComponent <StateChecker>(); //statecheckerコンポーネントにアクセス

        state = StateChecker.state;                                //自前の変数にステートの状態を代入しておく

        //vector3を呼び出して移動の制御や向きの反転を行う
        Vector3 v     = this.transform.position;
        Vector3 scale = transform.localScale;

        //animatorにアクセスして、ステートの状態によって変数をスイッチしている
        idle     = (PlayerAnimation.GetCurrentAnimatorStateInfo(0).IsName("idle") == true) ? true : false;
        walk     = (PlayerAnimation.GetCurrentAnimatorStateInfo(0).IsName("walk") == true) ? true : false;
        jumpUp   = (PlayerAnimation.GetCurrentAnimatorStateInfo(0).IsName("jump_up") == true) ? true : false;
        jumpDown = (PlayerAnimation.GetCurrentAnimatorStateInfo(0).IsName("jump_down") == true) ? true : false;
        land     = (PlayerAnimation.GetCurrentAnimatorStateInfo(0).IsName("land") == true) ? true : false;
        damege   = (PlayerAnimation.GetCurrentAnimatorStateInfo(0).IsName("damege") == true) ? true : false;

        //左への歩き
        if (Input.GetKey(KeyCode.LeftArrow) && CanControl)
        {
            v.x    -= 0.05f;
            v.z     = 0;        //z軸を固定。根本的対処の必要あり
            scale.x = -1;
        }
        //右への歩き
        if (Input.GetKey(KeyCode.RightArrow) && CanControl)
        {
            v.x    += 0.05f;
            v.z     = 0;
            scale.x = 1;
        }

        //上昇中でも下降中でもなければジャンプ判定をオフにする
        if (state == "idle" || state == "walk" || state == "land")
        {
            NowJump = false;
        }

        //特定のステートでキー操作による移動を無効化する
        if (state == "land" || state == "damege")
        {
            CanControl = false;
        }
        else
        {
            CanControl = true;
        }

        this.transform.position = v;
        transform.localScale    = scale;
    }
コード例 #13
0
        public IIdentity Logon(string username, string password, IScope context = null)
        {
            if (null == UserService)
            {
                if (Logg.IsForDebug())
                {
                    Logg.Debug("No user service");
                }
                return(null);
            }
            var user = UserService.GetUser(username);

            if (null == user && Logg.IsForDebug())
            {
                Logg.Debug("user is null");
            }
            if (!StateChecker.IsPasswordLogable(user))
            {
                Logg.Debug("user not logable");
                return(null);
            }
            var result = new Identity {
                Name = username,
                AuthenticationType = "hash"
            };
            var state = StateChecker.GetActivityState(user);

            if (state != UserActivityState.Ok)
            {
                Logg.Debug("user is in invalid state " + state);
                result.State   = state;
                result.IsError = true;
                result.Error   = new SecurityException(state.ToStr());
            }
            else
            {
                if (PasswordManager.MatchPassword(user, password))
                {
                    Logg.Debug("pass matched");
                    result.IsAuthenticated = true;
                    result.IsAdmin         = user.IsAdmin;
                    result.User            = user;
                }
                else
                {
                    Logg.Debug("pass not matched");
                    result.IsError = true;
                    result.Error   = new SecurityException("invalid hash");
                }
            }
            return(result);
        }
コード例 #14
0
        public void Should_be_able_to_add_checkers_onto_features()
        {
            var checker           = new StateChecker();
            var featureDictionary = new Dictionary <string, bool>();

            featureDictionary.Add("feature", true);

            var provider = new InMemorySwitchProvider(featureDictionary);

            provider.AddChecker(checker);

            provider.ReadConfiguration();
            provider.IsAvailable("feature").ShouldBe(true);
        }
コード例 #15
0
        public async Task AddKnockoutAsync()
        {
            if (!StateChecker.IsKnockoutChannel(Context) || StateChecker.IsPrivateMessage(Context))
            {
                return;
            }

            var knockouts = new KnockOutHandler(Context.Channel.Id, Factory.GetDatabase());

            switch (knockouts.KnockoutStatus)
            {
            case 1:
                break;

            case 2:
                await Context.Channel.SendMessageAsync(":x: A knockout is already in progress!");

                return;

            case 3:
                break;

            case 4:
                await Context.Channel.SendMessageAsync(":x: A knockout is already being built by someone, sorry!");

                return;

            default:
                await Context.Channel.SendMessageAsync(":x: Right. This shouldn't have happened. Someone call RedFlint.");

                break;
            }

            await Discord.UserExtensions.SendMessageAsync(Context.User,
                                                          "Commands to create your own Knockout (all commands in this window please):\n\n" +
                                                          "**!name** _The Name Of Your Knockout_\n" +
                                                          "**!add** _The Name of Your Knockout Contender to add (no slashes please! I'm afraid Face/Off is not allowed for now!)_\n" +
                                                          "**!remove** _The Name of a Knockout Contender to delete (case sensitive)_\n" +
                                                          "**!preview** _Preview your Knockout_\n" +
                                                          "**!begin** _Start your Knockout, NO CHANGES CAN BE MADE BEYOND THIS POINT_\n" +
                                                          "**!quit** _Abandon and Delete your Knockout_\n"
                                                          );

            knockouts.CreateNewKnockout(Context.User.Id);

            await BotEmbeds.DraftBeingCreated(Context, knockouts);

            return;
        }
コード例 #16
0
        public string GetSalt(string username, IScope context = null)
        {
            if (null == UserService)
            {
                return(null);
            }
            var user = UserService.GetUser(username);

            if (!StateChecker.IsSecureLogable(user))
            {
                return(null);
            }

            return(SecureLogonService.GetSalt(user, context));
        }
コード例 #17
0
        public void checker_should_call_internal_checker()
        {
            var checker    = new StateChecker();
            var newChecker = Substitute.For <IChecker>();

            checker.AddChecker(newChecker);

            var feature = new Feature()
            {
                State = true
            };

            checker.IsAvailable(feature);

            newChecker.Received(1).IsAvailable(feature);
        }
コード例 #18
0
        public async Task ClearChannelRoleAsync()
        {
            if (!StateChecker.IsGuildAdmin(Context))
            {
                await Context.Channel.SendMessageAsync(":x: You are not guild admin!");

                return;
            }

            if (StateChecker.IsPrivateMessage(Context))
            {
                await Context.Channel.SendMessageAsync(
                    ":x: Please use this command in the channel you wish to clear the role for");
            }

            var roleHandler = new RoleHandler(Factory.GetDatabase());

            roleHandler.ClearRoleForChannel(Context.Channel.Id);
        }
コード例 #19
0
        public async Task EmbedKnockoutAsync()
        {
            if (!StateChecker.IsKnockoutChannel(Context) || StateChecker.IsPrivateMessage(Context))
            {
                return;
            }

            var knockouts = new KnockOutHandler(Context.Channel.Id, Factory.GetDatabase());

            switch (knockouts.KnockoutStatus)
            {
            case 1:
                await Context.Channel.SendMessageAsync(":x: No Knockout has been created or is being created. Go for it! Type !createknockout to begin.");

                return;

            case 2:
                await BotEmbeds.ShowKnockout(Context, knockouts);

                return;

            case 3:
                await BotEmbeds.KnockoutIsOver(Context, knockouts);

                break;

            case 4:
                var userId   = knockouts.KnockoutCreatorUlong;
                var username = Context.Client.GetUser(userId).Username;
                await Context.Channel.SendMessageAsync($"This Knockout is currently under construction by **{username}**! Feel free to advise!");

                await BotEmbeds.ShowKnockout(Context, knockouts);

                return;

            default:
                await Context.Channel.SendMessageAsync(":x: Right. This shouldn't have happened. Someone call RedFlint.");

                return;
            }
        }
コード例 #20
0
        public async Task RebuildDatabasesAsync()
        {
            if (!StateChecker.IsKnockoutChannel(Context) || StateChecker.IsPrivateMessage(Context))
            {
                return;
            }

            if (!StateChecker.IsChannelOp(Context))
            {
                await Context.Channel.SendMessageAsync(":x: You are not a channel op!");

                return;
            }

            await Context.Channel.SendMessageAsync("!!! All databases are being rebuilt and purged !!!");

            var knockouts = new KnockOutHandler(Context.Channel.Id, Factory.GetDatabase());

            knockouts.RebuildDataBase();

            await Context.Channel.SendMessageAsync("!!! Done !!!");
        }
コード例 #21
0
        public IIdentity Logon(string username, SecureLogonInfo info, IScope context = null)
        {
            if (null == UserService)
            {
                return(null);
            }
            var user = UserService.GetUser(username);

            if (!StateChecker.IsSecureLogable(user))
            {
                return(null);
            }
            var result = new Identity {
                Name = username,
                AuthenticationType = "secure"
            };
            var state = StateChecker.GetActivityState(user);

            if (state != UserActivityState.Ok)
            {
                result.IsError = true;
                result.Error   = new SecurityException(state.ToStr());
            }
            else
            {
                try {
                    SecureLogonService.CheckSecureInfo(info, user, context);
                    result.IsAuthenticated = true;
                    result.User            = user;
                    result.IsAdmin         = user.IsAdmin;
                }
                catch (Exception e) {
                    result.IsError = true;
                    result.Error   = e;
                }
            }

            return(result);
        }
コード例 #22
0
 public SignalRHub(StateChecker stateChecker)
 {
     _stateChecker = stateChecker;
 }
コード例 #23
0
        public async Task RemoveContenderAsync([Remainder] string input = "")
        {
            if (!StateChecker.IsPrivateMessage(Context))
            {
                return;
            }

            if (input == "")
            {
                await Context.Channel.SendMessageAsync(":x: No Value Entered!");

                return;
            }

            var channelId = KnockOutHandler.ChannelForUser(Context.User.Id, Factory.GetDatabase());

            if (channelId == 0)
            {
                await Context.Channel.SendMessageAsync(":x: You are not making a knockout at the moment!");

                return;
            }

            var knockouts = new KnockOutHandler(channelId, Factory.GetDatabase());

            if (knockouts.KnockoutCreatorUlong != Context.User.Id)
            {
                await Context.Channel.SendMessageAsync(":x: You are not making a knockout at the moment!");

                return;
            }

            switch (knockouts.KnockoutStatus)
            {
            case 1:
                await Context.Channel.SendMessageAsync(":x: No Knockout is being created at the moment!");

                return;

            case 2:
                await Context.Channel.SendMessageAsync(":x: This knockout has already started! No more changes!");

                return;

            case 3:
                await Context.Channel.SendMessageAsync(":x: This knockout is finished, please feel free to create a new one!");

                return;

            case 4:
                break;

            default:
                await Context.Channel.SendMessageAsync(":x: Right. This shouldn't have happened. Someone call RedFlint.");

                return;
            }

            if (!knockouts.DeleteContender(input))
            {
                await Context.Channel.SendMessageAsync($":x: No Exact Match Found for **{input}**. Please Try Again");

                return;
            }

            await Context.Channel.SendMessageAsync($"You have removed the contender **{input}**");
        }
コード例 #24
0
 public void SetUp()
 {
     _stateChecker = new StateChecker();
 }
コード例 #25
0
        public async Task AddKnockoutAsync([Remainder] string input = "")
        {
            if (!StateChecker.IsPrivateMessage(Context))
            {
                return;
            }

            if (input == "")
            {
                await Context.Channel.SendMessageAsync(":x: No Value Entered!");

                return;
            }

            if (input.Contains("/"))
            {
                await Context.Channel.SendMessageAsync(":x: I told you that you couldn't choose Face/Off! (or whatever other film you've found with a / in it. V/H/S maybe...)");

                return;
            }

            var channelId = KnockOutHandler.ChannelForUser(Context.User.Id, Factory.GetDatabase());

            if (channelId == 0)
            {
                await Context.Channel.SendMessageAsync(":x: You are not making a knockout at the moment!");

                return;
            }

            var knockouts = new KnockOutHandler(channelId, Factory.GetDatabase());

            if (knockouts.KnockoutCreatorUlong != Context.User.Id)
            {
                await Context.Channel.SendMessageAsync(":x: You are not making a knockout at the moment!");

                return;
            }

            switch (knockouts.KnockoutStatus)
            {
            case 1:
                await Context.Channel.SendMessageAsync(":x: No Knockout is being created at the moment!");

                return;

            case 2:
                await Context.Channel.SendMessageAsync(":x: This knockout has already started! No more changes!");

                return;

            case 3:
                await Context.Channel.SendMessageAsync(":x: This knockout is finished, please feel free to create a new one!");

                return;

            case 4:
                break;

            default:
                await Context.Channel.SendMessageAsync(":x: Right. This shouldn't have happened. Someone call RedFlint.");

                return;
            }

            knockouts.AddNewContender(input);

            await Context.Channel.SendMessageAsync($"You have added the contender **{input}**");
        }
コード例 #26
0
        public async Task PlayAsync([Remainder] string input = "")
        {
            if (!StateChecker.IsKnockoutChannel(Context) || StateChecker.IsPrivateMessage(Context))
            {
                return;
            }

            if (input == "")
            {
                await Context.Channel.SendMessageAsync(":x: Please enter your options in this format: *!vote choice to add/choice to delete*");

                return;
            }

            if (!input.Contains("/") || input.Count(c => c == '/') > 1)
            {
                await Context.Channel.SendMessageAsync(":x: Please enter your options in this format: *!vote choice to add/choice to delete*");

                return;
            }

            var choices = input.Split('/');

            var choiceToAdd = choices.First();
            var choiceToSub = choices.Last();

            var knockouts = new KnockOutHandler(Context.Channel.Id, Factory.GetDatabase());

            switch (knockouts.KnockoutStatus)
            {
            case 1:
                await Context.Channel.SendMessageAsync(":x: No Knockout ongoing. Feel free to start a new one!");

                return;

            case 2:
                break;

            case 3:
                await Context.Channel.SendMessageAsync(":x: This knockout is finished. Feel free to start a new one!");

                return;

            case 4:
                await Context.Channel.SendMessageAsync(":x: This knockout is still under construction! Patience!");

                return;

            default:
                await Context.Channel.SendMessageAsync(":x: Right. This shouldn't have happened. Someone call RedFlint.");

                return;
            }

            if (knockouts.PlayerWentLastTime(Context.User.Id))
            {
                await Context.Channel.SendMessageAsync(":x: You just went! Give a few other people a chance!");

                return;
            }

            if (knockouts.TurnsLeftForPlayer(Context.User.Id) <= 0)
            {
                await Context.Channel.SendMessageAsync(":x: You are out of turns, please wait until the turns are reset");

                return;
            }

            var original = choiceToAdd;

            choiceToAdd = knockouts.FindNearestMatch(choiceToAdd);
            if (choiceToAdd == "ERROR")
            {
                await Context.Channel.SendMessageAsync($":x: I'm sorry, I could not find a close match for **{original}**, please try again");

                return;
            }

            original    = choiceToSub;
            choiceToSub = knockouts.FindNearestMatch(choiceToSub);
            if (choiceToSub == "ERROR")
            {
                await Context.Channel.SendMessageAsync($":x: I'm sorry, I could not find a close match for **{original}**, please try again");

                return;
            }

            if (choiceToAdd == choiceToSub)
            {
                await Context.Channel.SendMessageAsync(":x: Choices are the same, try again.");

                return;
            }

            knockouts.ApplyVoteChanges(choiceToAdd, choiceToSub, Context.User.Id);

            if (knockouts.LivingContendersCount <= 3)
            {
                knockouts.EndKnockout();

                await BotEmbeds.KnockoutIsOver(Context, knockouts);
            }
            else
            {
                var userName  = Context.User.Username;
                var avatarUrl = Context.User.GetAvatarUrl();

                await Context.Channel.SendMessageAsync("", false, BotEmbeds.PlayerVotingReportEmbed(userName, avatarUrl, choiceToAdd, choiceToSub));

                var recentKiller = knockouts.PlayerHasJustKilled();

                if (recentKiller != 0)
                {
                    var killer = Context.Client.GetUser(recentKiller);

                    if (killer != null)
                    {
                        await killer.SendMessageAsync("You have killed a contender, type !epitaph _<message>_ in the main channel to leave a mark on their grave!");

                        await killer.SendMessageAsync("(please note, if you eliminate another contender, you will lose the opportunity to engrave an epitaph for this one)");
                    }

                    knockouts.GetContendersFromDb();
                }

                await BotEmbeds.ShowKnockout(Context, knockouts);
            }
        }
コード例 #27
0
        public async Task BeginKnockoutAsync()
        {
            if (!StateChecker.IsPrivateMessage(Context))
            {
                return;
            }

            var channelId = KnockOutHandler.ChannelForUser(Context.User.Id, Factory.GetDatabase());

            if (channelId == 0)
            {
                await Context.Channel.SendMessageAsync(":x: You are not making a knockout at the moment!");

                return;
            }

            var knockouts = new KnockOutHandler(channelId, Factory.GetDatabase());

            if (knockouts.KnockoutCreatorUlong != Context.User.Id)
            {
                await Context.Channel.SendMessageAsync(":x: You are not making a knockout at the moment!");

                return;
            }

            switch (knockouts.KnockoutStatus)
            {
            case 1:
                await Context.Channel.SendMessageAsync(":x: No Knockout is being created at the moment!");

                return;

            case 2:
                await Context.Channel.SendMessageAsync(":x: This knockout has already started! No more changes!");

                return;

            case 3:
                await Context.Channel.SendMessageAsync(":x: This knockout is finished, please feel free to create a new one!");

                return;

            case 4:
                break;

            default:
                await Context.Channel.SendMessageAsync(":x: Right. This shouldn't have happened. Someone call RedFlint.");

                return;
            }

            if (knockouts.ContendersCount < 4)
            {
                await Context.Channel.SendMessageAsync(":x: Knockouts are over when it reaches the Top 3. Please add more Contenders.");

                return;
            }

            if (knockouts.KnockoutTitle == "" || knockouts.KnockoutTitle == "No Knockout In Progress" || knockouts.KnockoutTitle == "Knockout Under Construction")
            {
                await Context.Channel.SendMessageAsync(":x: Please Name your Knockout");

                return;
            }

            knockouts.SetKnockoutToActive();

            await Context.Channel.SendMessageAsync("You're done! Please check in main channel for the knockout!");

            var chnl = Context.Client.GetChannel(knockouts.KnockoutChannelUlong) as Discord.IMessageChannel;
            await chnl.SendMessageAsync("A New Knockout Has Been Created!");

            await BotEmbeds.ShowKnockout(Context, chnl, knockouts);
        }