コード例 #1
0
        public static async Task HandleReaction(Cacheable <IUserMessage, ulong> cache, SocketReaction reaction)
        {
            if (!G2048Provider.UserIsPlaying(reaction.UserId))
            {
                return;
            }

            var msg = await cache.GetOrDownloadAsync();

            // Immediatly remove reaction so user is able to use it as input
            // Check permissions first
            if (reaction.UserId != msg.Author.Id)
            {
                var user = reaction.User.GetValueOrDefault(null) ?? Global.Client.GetUser(reaction.UserId);
                try
                {
                    await msg.RemoveReactionAsync(reaction.Emote, user);
                }
                catch (Exception e)

                {
                    await Logger.Log(new LogMessage(LogSeverity.Warning, $"Discord | Missing Permissions to remove reaction in {msg.Channel}", e.Message, e.InnerException));
                }
            }

            if (reaction.Emote.Name == "⬆")
            {
                G2048Provider.MakeMove(reaction.UserId, Game2048.MoveDirection.Up);
            }
            else if (reaction.Emote.Name == "⬇")
            {
                G2048Provider.MakeMove(reaction.UserId, Game2048.MoveDirection.Down);
            }
            else if (reaction.Emote.Name == "⬅")
            {
                G2048Provider.MakeMove(reaction.UserId, Game2048.MoveDirection.Left);
            }
            else if (reaction.Emote.Name == "➡")
            {
                G2048Provider.MakeMove(reaction.UserId, Game2048.MoveDirection.Right);
            }
            else if (reaction.Emote.Name == "❌")
            {
                G2048Provider.EndGame(reaction.UserId);
                return;
            }


            /*
             *("⬆"));
             * await msg.AddReactionAsync(new Emoji("⬇"));
             * await msg.AddReactionAsync(new Emoji("⬅"));
             * await msg.AddReactionAsync(new Emoji("➡"));
             *
             */
        }
コード例 #2
0
ファイル: G1024Commands.cs プロジェクト: Phytal/Wsashi
        public async Task Start2048Game()
        {
            if (G2048Provider.UserIsPlaying(Context.User.Id))
            {
                await ReplyAsync("You are already playing.\nYou must end the game first.");

                return;
            }

            var msg = await Context.Channel.SendMessageAsync("**YOUR GAME IS BEING PREPARED**\nPlease wait until all 4 emojis are added and the board changes.");

            await msg.AddReactionAsync(new Emoji("⬆"));

            await msg.AddReactionAsync(new Emoji("⬇"));

            await msg.AddReactionAsync(new Emoji("⬅"));

            await msg.AddReactionAsync(new Emoji("➡"));

            await msg.AddReactionAsync(new Emoji("❌"));

            G2048Provider.CreateNewGame(Context.User.Id, msg);
        }
コード例 #3
0
ファイル: G1024Commands.cs プロジェクト: Phytal/Wsashi
 public async Task End2048Gmae()
 {
     G2048Provider.EndGame(Context.User.Id);
     await Task.CompletedTask;
 }