示例#1
0
        public static async Task Run(SocketSlashCommand command, DiscordSocketClient client, Dictionary <string, SocketSlashCommandDataOption> options, ISocketMessageChannel recruitingChannel, List <IMessage> messages, List <Team> teams)
        {
            var guildUser   = (SocketGuildUser)options["username"].Value;
            var discordUser = guildUser.Nickname ?? guildUser.Username;

            // Player not exist? -> respond with error
            (var oldTeam, var player) = Team.FindPlayer(teams, discordUser);
            if (player == null)
            {
                await command.RespondAsync($"User {discordUser} does not exist in the recruiting table", ephemeral : true);

                return;
            }

            // If player was captain of old team remove that teams captain
            if (oldTeam.Captain?.DiscordUser == player.DiscordUser)
            {
                oldTeam.Captain = null;
            }

            // Move Player
            oldTeam.Players.Remove(player);

            // Update old team message
            if (oldTeam.Players.Count > 0)
            {
                await recruitingChannel.ModifyMessageAsync(oldTeam.MsgId, (message) => message.Content = oldTeam.ToMessage());
            }
            else
            {
                await recruitingChannel.DeleteMessageAsync(oldTeam.MsgId);
            }

            await command.RespondAsync($"You have removed user {discordUser} from {oldTeam.Name}", ephemeral : true);
        }
示例#2
0
        public static async Task Run(SocketSlashCommand command, DiscordSocketClient client, StorageClient storageClient, Dictionary <string, SocketSlashCommandDataOption> options, Guild guild, ISocketMessageChannel recruitingChannel, List <Team> teams)
        {
            var guildUser   = (SocketGuildUser)options["username"].Value;
            var discordUser = guildUser.Nickname ?? guildUser.Username;

            // Player not exist? -> respond with error
            (var oldTeam, var player) = Team.FindPlayer(teams, discordUser);
            if (player == null)
            {
                await command.FollowupAsync($"User {discordUser} does not exist in the recruiting table", ephemeral : true);

                return;
            }

            oldTeam.RemovePlayer(player);

            // Update old team message
            if (oldTeam.Players.Count > 0)
            {
                await recruitingChannel.ModifyMessageAsync(oldTeam.MsgId, (message) => message.Content = oldTeam.ToMessage());

                await storageClient.SaveTableRow(Team.TableName, oldTeam.Name, guild.RowKey, oldTeam);
            }
            else
            {
                await recruitingChannel.DeleteMessageAsync(oldTeam.MsgId);

                await storageClient.DeleteTableRow(Team.TableName, oldTeam.Name, guild.RowKey);
            }

            await command.FollowupAsync($"You have removed user {discordUser} from {oldTeam.Name}", ephemeral : true);
        }
示例#3
0
        public static async Task Run(SocketSlashCommand command, DiscordSocketClient client, StorageClient storageClient, Dictionary <string, SocketSlashCommandDataOption> options, Guild guild, ISocketMessageChannel recruitingChannel, List <Team> teams)
        {
            var guildUser = (SocketGuildUser)options["username"].Value;
            var teamName  = String.Empty;

            if (options.TryGetValue("team", out SocketSlashCommandDataOption teamOption))
            {
                teamName = teamOption.Value.ToString();
            }

            // Construct new player from parameters
            var newPlayer = new Player();

            newPlayer.DiscordUser = guildUser.Nickname ?? guildUser.Username;
            newPlayer.Platform    = (Platform)Enum.Parse(typeof(Platform), options["platform"].Value.ToString());
            newPlayer.PlatformId  = options["id"].Value.ToString();

            if (newPlayer.Platform == Platform.Tracker && !Player.ValidateTrackerLink(newPlayer.PlatformId))
            {
                await command.FollowupAsync($"Your RL tracker link is invalid", ephemeral : true);

                return;
            }

            // Is player just updating tracker link? -> Update link
            (var team, var existingPlayer) = Team.FindPlayer(teams, newPlayer.DiscordUser);

            if (existingPlayer != null && !string.Equals(team.Name, teamName, StringComparison.InvariantCultureIgnoreCase))
            {
                await command.FollowupAsync($"Invalid use of add command. Please use the move command to change a user between teams", ephemeral : true);

                return;
            }

            if (team == null)
            {
                teamName = string.IsNullOrEmpty(teamName) ? "Free_Agents" : teamName;
                team     = Team.AddPlayer(teams, teamName, newPlayer);
            }
            else
            {
                existingPlayer.Platform   = newPlayer.Platform;
                existingPlayer.PlatformId = newPlayer.PlatformId;
            }

            // Have we added this team message yet? -> Write team message and move to next team
            if (team.MsgId == 0)
            {
                team.MsgId = (await recruitingChannel.SendMessageAsync(team.ToMessage())).Id;
            }
            else
            {
                // This is an existing team -> Modify old team message
                await recruitingChannel.ModifyMessageAsync(team.MsgId, (message) => message.Content = team.ToMessage());
            }

            await storageClient.SaveTableRow(Team.TableName, team.Name, guild.RowKey, team);

            await command.FollowupAsync($"{newPlayer.DiscordUser}'s RL tracker has been added to the recruiting board in channel <#{recruitingChannel.Id}>", ephemeral : true);
        }
示例#4
0
        public static async Task Run(SocketSlashCommand command, DiscordSocketClient client, StorageClient storageClient, Dictionary <string, SocketSlashCommandDataOption> options, Guild guild, ISocketMessageChannel recruitingChannel, List <Team> teams)
        {
            var user = command.User as SocketGuildUser;

            // Construct new player from parameters
            var newPlayer = new Player();

            newPlayer.DiscordUser = user.Nickname ?? user.Username;
            newPlayer.Platform    = (Platform)Enum.Parse(typeof(Platform), options["platform"].Value.ToString());
            newPlayer.PlatformId  = options["id"].Value.ToString();

            if (newPlayer.Platform == Platform.Tracker && !Player.ValidateTrackerLink(newPlayer.PlatformId))
            {
                await command.FollowupAsync($"Your RL tracker link is invalid", ephemeral : true);

                return;
            }

            // Is player just updating tracker link? -> Update link
            (var team, var existingPlayer) = Team.FindPlayer(teams, newPlayer.DiscordUser);

            // Is player not on a team? -> Add to FreeAgents
            if (team == null)
            {
                team = Team.AddPlayer(teams, "Free_Agents", newPlayer);
            }
            else
            {
                existingPlayer.Platform   = newPlayer.Platform;
                existingPlayer.PlatformId = newPlayer.PlatformId;
            }

            // Have we added this team message yet? -> Write team message and move to next team
            if (team.MsgId == 0)
            {
                team.MsgId = (await recruitingChannel.SendMessageAsync(team.ToMessage())).Id;
            }
            else
            {
                // This is an existing team -> Modify old team message
                await recruitingChannel.ModifyMessageAsync(team.MsgId, (message) => message.Content = team.ToMessage());
            }

            await storageClient.SaveTableRow(Team.TableName, team.Name, guild.RowKey, team);

            await command.FollowupAsync($"Your RL tracker has been added to the recruiting board in channel <#{recruitingChannel.Id}>", ephemeral : true);
        }
示例#5
0
        public static async Task Run(SocketSlashCommand command, DiscordSocketClient client, StorageClient storageClient, Dictionary <string, SocketSlashCommandDataOption> options, Guild guild, ISocketMessageChannel recruitingChannel, List <Team> teams)
        {
            var teamName          = options["team"].Value.ToString();
            var lookingForPlayers = (bool)options["looking"].Value;

            // Player not exist? -> respond with error
            var team = Team.FindTeam(teams, teamName);

            if (team == null)
            {
                await command.FollowupAsync($"Team {teamName} does not exist in the recruiting table", ephemeral : true);

                return;
            }

            team.LookingForPlayers = lookingForPlayers;

            await recruitingChannel.ModifyMessageAsync(team.MsgId, (message) => message.Content = team.ToMessage());

            await storageClient.SaveTableRow(Team.TableName, teamName, guild.RowKey, team);

            await command.FollowupAsync($"You marked team {team.Name} as looking for players {lookingForPlayers}", ephemeral : true);
        }
示例#6
0
        public static async Task Run(SocketSlashCommand command, DiscordSocketClient client, StorageClient storageClient, Dictionary <string, SocketSlashCommandDataOption> options, Guild guild, ISocketMessageChannel recruitingChannel, List <Team> teams)
        {
            var guildUser   = (SocketGuildUser)options["username"].Value;
            var discordUser = guildUser.Nickname ?? guildUser.Username;
            var teamName    = options["team"].Value.ToString();
            var captain     = options.ContainsKey("captain") && (bool)options["captain"].Value;

            // Player not exist? -> respond with error
            (var oldTeam, var player) = Team.FindPlayer(teams, discordUser);
            if (player == null)
            {
                await command.FollowupAsync($"User {discordUser} does not exist in the recruiting table", ephemeral : true);

                return;
            }

            oldTeam.RemovePlayer(player);
            var  newTeam   = Team.AddPlayer(teams, teamName, player, captain);
            bool isNewTeam = newTeam.MsgId == 0;

            // Update old team message
            if (oldTeam.Players.Count > 0)
            {
                await recruitingChannel.ModifyMessageAsync(oldTeam.MsgId, (message) => message.Content = oldTeam.ToMessage());
            }
            else
            {
                await recruitingChannel.DeleteMessageAsync(oldTeam.MsgId);
            }

            // Update new team message
            if (newTeam.MsgId == 0)
            {
                newTeam.MsgId = (await recruitingChannel.SendMessageAsync(newTeam.ToMessage())).Id;
            }
            else
            {
                await recruitingChannel.ModifyMessageAsync(newTeam.MsgId, (message) => message.Content = newTeam.ToMessage());
            }

            var transactions = new List <(string, TableTransactionActionType, Team, ETag)>();

            if (oldTeam.Players.Count > 0)
            {
                transactions.Add((oldTeam.Name, TableTransactionActionType.UpdateMerge, oldTeam, oldTeam.etag));
            }
            else
            {
                transactions.Add((oldTeam.Name, TableTransactionActionType.Delete, null, oldTeam.etag));
            }

            if (!string.Equals(newTeam.Name, oldTeam.Name, StringComparison.OrdinalIgnoreCase))
            {
                transactions.Add((newTeam.Name, isNewTeam ? TableTransactionActionType.UpsertMerge : TableTransactionActionType.UpdateMerge, newTeam, newTeam.etag));
            }

            // if the transaction fails it should retry, and then the message will be updated to reflect the actual value in storage.
            await storageClient.ExecuteTransaction(Team.TableName, transactions, guild.RowKey);

            await command.FollowupAsync($"You have moved user {discordUser} from {oldTeam.Name} -> {newTeam.Name}", ephemeral : true);
        }
示例#7
0
        public static async Task Run(SocketSlashCommand command, DiscordSocketClient client, Dictionary <string, SocketSlashCommandDataOption> options, ISocketMessageChannel recruitingChannel, List <IMessage> messages, List <Team> teams)
        {
            var guildUser = (SocketGuildUser)options["username"].Value;

            // Construct new player from parameters
            var newPlayer = new Player();

            newPlayer.DiscordUser = guildUser.Nickname ?? guildUser.Username;
            newPlayer.Platform    = (Platform)Enum.Parse(typeof(Platform), options["platform"].Value.ToString());
            newPlayer.PlatformId  = options["id"].Value.ToString();

            // Is player just updating tracker link? -> Update link
            bool updated = false;

            foreach (var team in teams)
            {
                var exists = team.Players.Where((p) => p.DiscordUser == newPlayer.DiscordUser);
                if (exists.Any())
                {
                    // Player exists on team so just update
                    var existingPlayer = exists.First();
                    existingPlayer.Platform   = newPlayer.Platform;
                    existingPlayer.PlatformId = newPlayer.PlatformId;
                    updated = true;
                    break;
                }
            }

            // Is player not on a team? -> Add to FreeAgents
            if (!updated)
            {
                var freeAgents = Team.FindTeam(teams, "Free_Agents");

                // Not found? -> Add Free Agent team
                if (freeAgents == null)
                {
                    freeAgents = new Team()
                    {
                        Name    = "Free_Agents",
                        Players = new List <Player>()
                    };
                    teams.Add(freeAgents);
                }

                freeAgents.Players.Add(newPlayer);
            }

            foreach (var team in teams)
            {
                // Have we added this team message yet? -> Write team message and move to next team
                if (team.MsgId == 0)
                {
                    await recruitingChannel.SendMessageAsync(team.ToMessage());

                    continue;
                }

                // This is an existing team -> Modify old team message
                await recruitingChannel.ModifyMessageAsync(team.MsgId, (message) => message.Content = team.ToMessage());
            }

            await command.RespondAsync($"{newPlayer.DiscordUser}'s RL tracker has been added to the recruiting board in channel <#{recruitingChannel.Id}>", ephemeral : true);
        }
示例#8
0
        public static async Task Run(SocketSlashCommand command, DiscordSocketClient client, Dictionary <string, SocketSlashCommandDataOption> options, ISocketMessageChannel recruitingChannel, List <IMessage> messages, List <Team> teams)
        {
            var guildUser   = (SocketGuildUser)options["username"].Value;
            var discordUser = guildUser.Nickname ?? guildUser.Username;

            // Player not exist? -> respond with error
            (var oldTeam, var player) = Team.FindPlayer(teams, discordUser);
            if (player == null)
            {
                await command.RespondAsync($"User {discordUser} does not exist in the recruiting table", ephemeral : true);

                return;
            }

            // If player was captain of old team remove that teams captain
            if (oldTeam.Captain?.DiscordUser == player.DiscordUser)
            {
                oldTeam.Captain = null;
            }

            // Move Player
            oldTeam.Players.Remove(player);
            // Update old team message
            await recruitingChannel.ModifyMessageAsync(oldTeam.MsgId, (message) => message.Content = oldTeam.ToMessage());

            var teamName = options["team"].Value.ToString();

            var newTeam = Team.FindTeam(teams, teamName);

            if (newTeam == null)
            {
                newTeam = new Team()
                {
                    Name    = teamName,
                    Players = new List <Player>()
                };
            }

            newTeam.Players.Add(player);

            // If this is a captain make new team captain = player
            if (options.ContainsKey("captain") && (bool)options["captain"].Value)
            {
                newTeam.Captain = player;
            }

            // Update old team message
            if (oldTeam.Players.Count > 0)
            {
                await recruitingChannel.ModifyMessageAsync(oldTeam.MsgId, (message) => message.Content = oldTeam.ToMessage());
            }
            else
            {
                await recruitingChannel.DeleteMessageAsync(oldTeam.MsgId);
            }

            // Update new team message
            if (newTeam.MsgId == 0)
            {
                await recruitingChannel.SendMessageAsync(newTeam.ToMessage());
            }
            else
            {
                await recruitingChannel.ModifyMessageAsync(newTeam.MsgId, (message) => message.Content = newTeam.ToMessage());
            }

            await command.RespondAsync($"You have moved user {discordUser} from {oldTeam.Name} -> {newTeam.Name}", ephemeral : true);
        }