Ejemplo n.º 1
0
    public async static Task HandleRemoveCommand(SocketMessage message, CommunityRepository repository)
    {
        string originalMessage = message.Content;

        string[] splitMessage = originalMessage.Split(new char[] { ' ' }, 2);
        string   stageName    = splitMessage[1];

        Stage stage = new Stage()
        {
            Name   = stageName.ToLower(),
            Author = String.Format("{0}#{1}", message.Author.Username.ToLower(), message.Author.Discriminator.ToLower())
        };

        if (!repository.StageExists(stage))
        {
            string reply = String.Format(@"Failed to remove the stage ""{0}"" from the community repository because it does not exist", stageName);
            await message.Channel.SendMessageAsync(reply);

            return;
        }

        Stage repositoryStage = repository.GetStage(stage.Name);

        if (repositoryStage.Author.ToLower() != stage.Author.ToLower())
        {
            string reply = String.Format(@"Failed to remove the stage ""{0}"" from the community repository because you are not the author for that stage.", stageName);
            await message.Channel.SendMessageAsync(reply);

            return;
        }

        await message.Channel.SendMessageAsync("Removing your stage from the community repository now...");

        repository.RemoveStage(stage);
        string commitMessage = String.Format("Removed the stage {0} from the community repository", repositoryStage.Name);

        MainClass.UpdateGitHub(commitMessage);
        string response = String.Format(@"Successfully removed the stage ""{0}"" from the community repository!", stageName);
        await message.Channel.SendMessageAsync(response);
    }